Merge branch 'main' into chore/backmerge-main
This commit is contained in:
commit
de5371435d
4
.gitignore
vendored
4
.gitignore
vendored
@ -52,6 +52,7 @@ cypress.env.json
|
|||||||
/apps/**/cypress/reports/
|
/apps/**/cypress/reports/
|
||||||
/apps/**/cypress/downloads/
|
/apps/**/cypress/downloads/
|
||||||
/apps/**/fixtures/wallet/node**
|
/apps/**/fixtures/wallet/node**
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
# apps/trading/e2e
|
# apps/trading/e2e
|
||||||
__pycache__/
|
__pycache__/
|
||||||
@ -59,5 +60,4 @@ apps/trading/e2e/logs/
|
|||||||
apps/trading/e2e/.pytest_cache/
|
apps/trading/e2e/.pytest_cache/
|
||||||
apps/trading/e2e/traces/
|
apps/trading/e2e/traces/
|
||||||
|
|
||||||
.nx/cache
|
.nx/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { getAsset, getProductType, getQuoteName } from '@vegaprotocol/markets';
|
import { getAsset, getQuoteName } from '@vegaprotocol/markets';
|
||||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||||
|
|
||||||
@ -297,134 +297,120 @@ export const DealTicketMarginDetails = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const quoteName = getQuoteName(market);
|
const quoteName = getQuoteName(market);
|
||||||
const productType = getProductType(market);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col w-full gap-2 pt-2">
|
<div className="flex flex-col w-full gap-2 pt-2">
|
||||||
{/*
|
<Accordion>
|
||||||
TODO: remove this conditional check once the following PRs are deployed
|
<AccordionPanel
|
||||||
and the estimatePosition query is working for perps
|
itemId="margin"
|
||||||
|
trigger={
|
||||||
- https://github.com/vegaprotocol/vega/pull/10119
|
<AccordionPrimitive.Trigger
|
||||||
- https://github.com/vegaprotocol/vega/pull/10122
|
data-testid="accordion-toggle"
|
||||||
*/}
|
className={classNames(
|
||||||
{productType === 'Future' && (
|
'w-full',
|
||||||
<>
|
'flex items-center gap-2 text-xs',
|
||||||
<Accordion>
|
'group'
|
||||||
<AccordionPanel
|
)}
|
||||||
itemId="margin"
|
|
||||||
trigger={
|
|
||||||
<AccordionPrimitive.Trigger
|
|
||||||
data-testid="accordion-toggle"
|
|
||||||
className={classNames(
|
|
||||||
'w-full',
|
|
||||||
'flex items-center gap-2 text-xs',
|
|
||||||
'group'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
data-testid={`deal-ticket-fee-margin-required`}
|
|
||||||
key={'value-dropdown'}
|
|
||||||
className="flex items-center justify-between w-full gap-2"
|
|
||||||
>
|
|
||||||
<div className="flex items-center text-left gap-1">
|
|
||||||
<Tooltip
|
|
||||||
description={t(
|
|
||||||
'MARGIN_DIFF_TOOLTIP_TEXT',
|
|
||||||
MARGIN_DIFF_TOOLTIP_TEXT,
|
|
||||||
{ assetSymbol }
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<span className="text-muted">
|
|
||||||
{t('Margin required')}
|
|
||||||
</span>
|
|
||||||
</Tooltip>
|
|
||||||
|
|
||||||
<AccordionChevron size={10} />
|
|
||||||
</div>
|
|
||||||
<Tooltip
|
|
||||||
description={
|
|
||||||
formatRange(
|
|
||||||
marginRequiredBestCase,
|
|
||||||
marginRequiredWorstCase,
|
|
||||||
assetDecimals
|
|
||||||
) ?? '-'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className="font-mono text-right">
|
|
||||||
{formatValue(
|
|
||||||
marginRequiredWorstCase,
|
|
||||||
assetDecimals,
|
|
||||||
quantum
|
|
||||||
)}{' '}
|
|
||||||
{assetSymbol || ''}
|
|
||||||
</div>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
</AccordionPrimitive.Trigger>
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<div className="flex flex-col w-full gap-2">
|
<div
|
||||||
<KeyValue
|
data-testid={`deal-ticket-fee-margin-required`}
|
||||||
label={t('Total margin available')}
|
key={'value-dropdown'}
|
||||||
indent
|
className="flex items-center justify-between w-full gap-2"
|
||||||
value={formatValue(totalMarginAvailable, assetDecimals)}
|
>
|
||||||
formattedValue={formatValue(
|
<div className="flex items-center text-left gap-1">
|
||||||
totalMarginAvailable,
|
<Tooltip
|
||||||
|
description={t(
|
||||||
|
'MARGIN_DIFF_TOOLTIP_TEXT',
|
||||||
|
MARGIN_DIFF_TOOLTIP_TEXT,
|
||||||
|
{ assetSymbol }
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<span className="text-muted">{t('Margin required')}</span>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<AccordionChevron size={10} />
|
||||||
|
</div>
|
||||||
|
<Tooltip
|
||||||
|
description={
|
||||||
|
formatRange(
|
||||||
|
marginRequiredBestCase,
|
||||||
|
marginRequiredWorstCase,
|
||||||
|
assetDecimals
|
||||||
|
) ?? '-'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="font-mono text-right">
|
||||||
|
{formatValue(
|
||||||
|
marginRequiredWorstCase,
|
||||||
|
assetDecimals,
|
||||||
|
quantum
|
||||||
|
)}{' '}
|
||||||
|
{assetSymbol || ''}
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</AccordionPrimitive.Trigger>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="flex flex-col w-full gap-2">
|
||||||
|
<KeyValue
|
||||||
|
label={t('Total margin available')}
|
||||||
|
indent
|
||||||
|
value={formatValue(totalMarginAvailable, assetDecimals)}
|
||||||
|
formattedValue={formatValue(
|
||||||
|
totalMarginAvailable,
|
||||||
|
assetDecimals,
|
||||||
|
quantum
|
||||||
|
)}
|
||||||
|
symbol={assetSymbol}
|
||||||
|
labelDescription={t(
|
||||||
|
'TOTAL_MARGIN_AVAILABLE',
|
||||||
|
TOTAL_MARGIN_AVAILABLE,
|
||||||
|
{
|
||||||
|
generalAccountBalance: formatValue(
|
||||||
|
generalAccountBalance,
|
||||||
assetDecimals,
|
assetDecimals,
|
||||||
quantum
|
quantum
|
||||||
)}
|
),
|
||||||
symbol={assetSymbol}
|
marginAccountBalance: formatValue(
|
||||||
labelDescription={t(
|
|
||||||
'TOTAL_MARGIN_AVAILABLE',
|
|
||||||
TOTAL_MARGIN_AVAILABLE,
|
|
||||||
{
|
|
||||||
generalAccountBalance: formatValue(
|
|
||||||
generalAccountBalance,
|
|
||||||
assetDecimals,
|
|
||||||
quantum
|
|
||||||
),
|
|
||||||
marginAccountBalance: formatValue(
|
|
||||||
marginAccountBalance,
|
|
||||||
assetDecimals,
|
|
||||||
quantum
|
|
||||||
),
|
|
||||||
marginMaintenance: formatValue(
|
|
||||||
currentMargins?.maintenanceLevel,
|
|
||||||
assetDecimals,
|
|
||||||
quantum
|
|
||||||
),
|
|
||||||
assetSymbol,
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
{deductionFromCollateral}
|
|
||||||
<KeyValue
|
|
||||||
label={t('Current margin allocation')}
|
|
||||||
indent
|
|
||||||
onClick={
|
|
||||||
generalAccountBalance
|
|
||||||
? () => setBreakdownDialog(true)
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
value={formatValue(marginAccountBalance, assetDecimals)}
|
|
||||||
symbol={assetSymbol}
|
|
||||||
labelDescription={t(
|
|
||||||
'MARGIN_ACCOUNT_TOOLTIP_TEXT',
|
|
||||||
MARGIN_ACCOUNT_TOOLTIP_TEXT
|
|
||||||
)}
|
|
||||||
formattedValue={formatValue(
|
|
||||||
marginAccountBalance,
|
marginAccountBalance,
|
||||||
assetDecimals,
|
assetDecimals,
|
||||||
quantum
|
quantum
|
||||||
)}
|
),
|
||||||
/>
|
marginMaintenance: formatValue(
|
||||||
</div>
|
currentMargins?.maintenanceLevel,
|
||||||
</AccordionPanel>
|
assetDecimals,
|
||||||
</Accordion>
|
quantum
|
||||||
{projectedMargin}
|
),
|
||||||
</>
|
assetSymbol,
|
||||||
)}
|
}
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{deductionFromCollateral}
|
||||||
|
<KeyValue
|
||||||
|
label={t('Current margin allocation')}
|
||||||
|
indent
|
||||||
|
onClick={
|
||||||
|
generalAccountBalance
|
||||||
|
? () => setBreakdownDialog(true)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
value={formatValue(marginAccountBalance, assetDecimals)}
|
||||||
|
symbol={assetSymbol}
|
||||||
|
labelDescription={t(
|
||||||
|
'MARGIN_ACCOUNT_TOOLTIP_TEXT',
|
||||||
|
MARGIN_ACCOUNT_TOOLTIP_TEXT
|
||||||
|
)}
|
||||||
|
formattedValue={formatValue(
|
||||||
|
marginAccountBalance,
|
||||||
|
assetDecimals,
|
||||||
|
quantum
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</AccordionPanel>
|
||||||
|
</Accordion>
|
||||||
|
{projectedMargin}
|
||||||
<KeyValue
|
<KeyValue
|
||||||
label={t('Liquidation')}
|
label={t('Liquidation')}
|
||||||
value={liquidationPriceEstimateRange}
|
value={liquidationPriceEstimateRange}
|
||||||
|
@ -6,14 +6,17 @@ import { MockedProvider } from '@apollo/client/testing';
|
|||||||
import { MAXGOINT64 } from '@vegaprotocol/utils';
|
import { MAXGOINT64 } from '@vegaprotocol/utils';
|
||||||
|
|
||||||
const mockCreate = jest.fn();
|
const mockCreate = jest.fn();
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/wallet', () => ({
|
jest.mock('@vegaprotocol/wallet', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/wallet'),
|
...jest.requireActual('@vegaprotocol/wallet'),
|
||||||
useVegaWallet: jest.fn(() => ({ pubKey: 'partyId' })),
|
useVegaWallet: jest.fn(() => ({ pubKey: 'partyId' })),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/web3', () => ({
|
jest.mock('@vegaprotocol/web3', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/web3'),
|
...jest.requireActual('@vegaprotocol/web3'),
|
||||||
useVegaTransactionStore: jest.fn(() => mockCreate),
|
useVegaTransactionStore: jest.fn(() => mockCreate),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const mockUseDataProvider = (args: any) => {
|
const mockUseDataProvider = (args: any) => {
|
||||||
if (args.dataProvider === positionsMarketsProvider) {
|
if (args.dataProvider === positionsMarketsProvider) {
|
||||||
@ -21,17 +24,20 @@ const mockUseDataProvider = (args: any) => {
|
|||||||
}
|
}
|
||||||
return { data: [singleRow] };
|
return { data: [singleRow] };
|
||||||
};
|
};
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/data-provider', () => ({
|
jest.mock('@vegaprotocol/data-provider', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/data-provider'),
|
...jest.requireActual('@vegaprotocol/data-provider'),
|
||||||
useDataProvider: jest.fn((args) => mockUseDataProvider(args)),
|
useDataProvider: jest.fn((args) => mockUseDataProvider(args)),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('PositionsManager', () => {
|
describe('PositionsManager', () => {
|
||||||
it('should close position with max uint64', async () => {
|
// TODO: Close position temporarily disabled in https://github.com/vegaprotocol/frontend-monorepo/pull/5350
|
||||||
|
// eslint-disable-next-line jest/no-disabled-tests
|
||||||
|
it.skip('should close position with max uint64', async () => {
|
||||||
render(<PositionsManager partyIds={['partyId']} isReadOnly={false} />, {
|
render(<PositionsManager partyIds={['partyId']} isReadOnly={false} />, {
|
||||||
wrapper: MockedProvider,
|
wrapper: MockedProvider,
|
||||||
});
|
});
|
||||||
expect(await screen.getByTestId('close-position')).toBeInTheDocument();
|
expect(await screen.findByTestId('close-position')).toBeInTheDocument();
|
||||||
|
|
||||||
fireEvent.click(screen.getByTestId('close-position'));
|
fireEvent.click(screen.getByTestId('close-position'));
|
||||||
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
import { useCallback } from 'react';
|
|
||||||
import { PositionsTable } from './positions-table';
|
import { PositionsTable } from './positions-table';
|
||||||
import * as Schema from '@vegaprotocol/types';
|
|
||||||
import { useVegaTransactionStore } from '@vegaprotocol/web3';
|
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||||
import {
|
import {
|
||||||
@ -9,9 +6,15 @@ import {
|
|||||||
positionsMarketsProvider,
|
positionsMarketsProvider,
|
||||||
} from './positions-data-providers';
|
} from './positions-data-providers';
|
||||||
import type { useDataGridEvents } from '@vegaprotocol/datagrid';
|
import type { useDataGridEvents } from '@vegaprotocol/datagrid';
|
||||||
import { MAXGOINT64 } from '@vegaprotocol/utils';
|
|
||||||
import { useT } from '../use-t';
|
import { useT } from '../use-t';
|
||||||
|
|
||||||
|
// TODO: Close position temporarily disabled in https://github.com/vegaprotocol/frontend-monorepo/pull/5350
|
||||||
|
//
|
||||||
|
// import { useCallback } from 'react';
|
||||||
|
// import * as Schema from '@vegaprotocol/types';
|
||||||
|
// import { useVegaTransactionStore } from '@vegaprotocol/web3';
|
||||||
|
// import { MAXGOINT64 } from '@vegaprotocol/utils';
|
||||||
|
|
||||||
interface PositionsManagerProps {
|
interface PositionsManagerProps {
|
||||||
partyIds: string[];
|
partyIds: string[];
|
||||||
onMarketClick?: (marketId: string) => void;
|
onMarketClick?: (marketId: string) => void;
|
||||||
@ -29,33 +32,37 @@ export const PositionsManager = ({
|
|||||||
}: PositionsManagerProps) => {
|
}: PositionsManagerProps) => {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
const { pubKeys, pubKey } = useVegaWallet();
|
const { pubKeys, pubKey } = useVegaWallet();
|
||||||
const create = useVegaTransactionStore((store) => store.create);
|
|
||||||
const onClose = useCallback(
|
// TODO: Close position temporarily disabled in https://github.com/vegaprotocol/frontend-monorepo/pull/5350
|
||||||
({ marketId, openVolume }: { marketId: string; openVolume: string }) =>
|
//
|
||||||
create({
|
// const create = useVegaTransactionStore((store) => store.create);
|
||||||
batchMarketInstructions: {
|
//
|
||||||
cancellations: [
|
// const onClose = useCallback(
|
||||||
{
|
// ({ marketId, openVolume }: { marketId: string; openVolume: string }) =>
|
||||||
marketId,
|
// create({
|
||||||
orderId: '', // omit order id to cancel all active orders
|
// batchMarketInstructions: {
|
||||||
},
|
// cancellations: [
|
||||||
],
|
// {
|
||||||
submissions: [
|
// marketId,
|
||||||
{
|
// orderId: '', // omit order id to cancel all active orders
|
||||||
marketId: marketId,
|
// },
|
||||||
type: Schema.OrderType.TYPE_MARKET as const,
|
// ],
|
||||||
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_IOC as const,
|
// submissions: [
|
||||||
side: openVolume.startsWith('-')
|
// {
|
||||||
? Schema.Side.SIDE_BUY
|
// marketId: marketId,
|
||||||
: Schema.Side.SIDE_SELL,
|
// type: Schema.OrderType.TYPE_MARKET as const,
|
||||||
size: MAXGOINT64, // improvement for avoiding leftovers filled in the meantime when close request has been sent
|
// timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_IOC as const,
|
||||||
reduceOnly: true,
|
// side: openVolume.startsWith('-')
|
||||||
},
|
// ? Schema.Side.SIDE_BUY
|
||||||
],
|
// : Schema.Side.SIDE_SELL,
|
||||||
},
|
// size: MAXGOINT64, // improvement for avoiding leftovers filled in the meantime when close request has been sent
|
||||||
}),
|
// reduceOnly: true,
|
||||||
[create]
|
// },
|
||||||
);
|
// ],
|
||||||
|
// },
|
||||||
|
// }),
|
||||||
|
// [create]
|
||||||
|
// );
|
||||||
|
|
||||||
const { data: marketIds } = useDataProvider({
|
const { data: marketIds } = useDataProvider({
|
||||||
dataProvider: positionsMarketsProvider,
|
dataProvider: positionsMarketsProvider,
|
||||||
@ -74,7 +81,8 @@ export const PositionsManager = ({
|
|||||||
pubKeys={pubKeys}
|
pubKeys={pubKeys}
|
||||||
rowData={data}
|
rowData={data}
|
||||||
onMarketClick={onMarketClick}
|
onMarketClick={onMarketClick}
|
||||||
onClose={onClose}
|
// TODO: temporarily disable close position
|
||||||
|
// onClose={onClose}
|
||||||
isReadOnly={isReadOnly}
|
isReadOnly={isReadOnly}
|
||||||
multipleKeys={partyIds.length > 1}
|
multipleKeys={partyIds.length > 1}
|
||||||
overlayNoRowsTemplate={error ? error.message : t('No positions')}
|
overlayNoRowsTemplate={error ? error.message : t('No positions')}
|
||||||
|
Loading…
Reference in New Issue
Block a user