chore(trading): add close position button back to console (#5407)

This commit is contained in:
m.ray 2023-12-01 18:38:32 +02:00 committed by GitHub
parent 127e784ceb
commit 3dc77b0eff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 55 additions and 49 deletions

View File

@ -28,3 +28,4 @@ NX_REFERRALS=false
NX_TENDERMINT_URL=https://be.vega.community NX_TENDERMINT_URL=https://be.vega.community
NX_TENDERMINT_WEBSOCKET_URL=wss://be.vega.community/websocket NX_TENDERMINT_WEBSOCKET_URL=wss://be.vega.community/websocket
NX_DISABLE_CLOSE_POSITION=true

View File

@ -150,7 +150,7 @@ export const useEnvironment = create<EnvStore>()((set, get) => ({
* Initialize Vega app to dynamically select a node from the * Initialize Vega app to dynamically select a node from the
* VEGA_CONFIG_URL * VEGA_CONFIG_URL
* *
* This can be ommitted if you intend to only use a single node, * This can be omitted if you intend to only use a single node,
* in those cases be sure to set NX_VEGA_URL * in those cases be sure to set NX_VEGA_URL
*/ */
export const useInitializeEnv = () => { export const useInitializeEnv = () => {
@ -415,6 +415,12 @@ function compileFeatureFlags(): FeatureFlags {
REFERRALS: TRUTHY.includes( REFERRALS: TRUTHY.includes(
windowOrDefault('NX_REFERRALS', process.env['NX_REFERRALS']) as string windowOrDefault('NX_REFERRALS', process.env['NX_REFERRALS']) as string
), ),
DISABLE_CLOSE_POSITION: TRUTHY.includes(
windowOrDefault(
'NX_DISABLE_CLOSE_POSITION',
process.env['NX_DISABLE_CLOSE_POSITION']
) as string
),
UPDATE_MARKET_STATE: TRUTHY.includes( UPDATE_MARKET_STATE: TRUTHY.includes(
windowOrDefault( windowOrDefault(
'NX_UPDATE_MARKET_STATE', 'NX_UPDATE_MARKET_STATE',

View File

@ -27,6 +27,7 @@ export type CosmicElevatorFlags = Pick<
| 'UPDATE_MARKET_STATE' | 'UPDATE_MARKET_STATE'
| 'GOVERNANCE_TRANSFERS' | 'GOVERNANCE_TRANSFERS'
| 'VOLUME_DISCOUNTS' | 'VOLUME_DISCOUNTS'
| 'DISABLE_CLOSE_POSITION'
>; >;
export type Configuration = z.infer<typeof tomlConfigSchema>; export type Configuration = z.infer<typeof tomlConfigSchema>;
export const CUSTOM_NODE_KEY = 'custom' as const; export const CUSTOM_NODE_KEY = 'custom' as const;

View File

@ -81,6 +81,7 @@ const COSMIC_ELEVATOR_FLAGS = {
UPDATE_MARKET_STATE: z.optional(z.boolean()), UPDATE_MARKET_STATE: z.optional(z.boolean()),
GOVERNANCE_TRANSFERS: z.optional(z.boolean()), GOVERNANCE_TRANSFERS: z.optional(z.boolean()),
VOLUME_DISCOUNTS: z.optional(z.boolean()), VOLUME_DISCOUNTS: z.optional(z.boolean()),
DISABLE_CLOSE_POSITION: z.optional(z.boolean()),
}; };
const EXPLORER_FLAGS = { const EXPLORER_FLAGS = {

View File

@ -1,6 +1,6 @@
import { memo, forwardRef, useMemo, type ForwardedRef } from 'react'; import { memo, forwardRef, useMemo, type ForwardedRef } from 'react';
import { import {
MAXGOINT64, HALFMAXGOINT64,
addDecimalsFormatNumber, addDecimalsFormatNumber,
getDateTimeFormat, getDateTimeFormat,
isNumeric, isNumeric,
@ -151,7 +151,7 @@ export const OrderListTable = memo<
: ''; : '';
if ( if (
data.size === MAXGOINT64 && data.size >= HALFMAXGOINT64 &&
data.timeInForce === data.timeInForce ===
Schema.OrderTimeInForce.TIME_IN_FORCE_IOC && Schema.OrderTimeInForce.TIME_IN_FORCE_IOC &&
data.reduceOnly data.reduceOnly

View File

@ -3,7 +3,7 @@ import { PositionsManager } from './positions-manager';
import { positionsMarketsProvider } from './positions-data-providers'; import { positionsMarketsProvider } from './positions-data-providers';
import { singleRow } from './positions.mock'; import { singleRow } from './positions.mock';
import { MockedProvider } from '@apollo/client/testing'; import { MockedProvider } from '@apollo/client/testing';
import { MAXGOINT64 } from '@vegaprotocol/utils'; import { HALFMAXGOINT64 } from '@vegaprotocol/utils';
const mockCreate = jest.fn(); const mockCreate = jest.fn();
@ -31,9 +31,7 @@ jest.mock('@vegaprotocol/data-provider', () => ({
})); }));
describe('PositionsManager', () => { describe('PositionsManager', () => {
// TODO: Close position temporarily disabled in https://github.com/vegaprotocol/frontend-monorepo/pull/5350 it('should close position with half of max uint64', async () => {
// 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,
}); });
@ -43,6 +41,6 @@ describe('PositionsManager', () => {
expect( expect(
mockCreate.mock.lastCall[0].batchMarketInstructions.submissions[0].size mockCreate.mock.lastCall[0].batchMarketInstructions.submissions[0].size
).toEqual(MAXGOINT64); ).toEqual(HALFMAXGOINT64);
}); });
}); });

View File

@ -7,13 +7,11 @@ import {
} from './positions-data-providers'; } from './positions-data-providers';
import type { useDataGridEvents } from '@vegaprotocol/datagrid'; import type { useDataGridEvents } from '@vegaprotocol/datagrid';
import { useT } from '../use-t'; import { useT } from '../use-t';
import { useCallback } from 'react';
// TODO: Close position temporarily disabled in https://github.com/vegaprotocol/frontend-monorepo/pull/5350 import * as Schema from '@vegaprotocol/types';
// import { useVegaTransactionStore } from '@vegaprotocol/web3';
// import { useCallback } from 'react'; import { HALFMAXGOINT64 } from '@vegaprotocol/utils';
// import * as Schema from '@vegaprotocol/types'; import { FLAGS } from '@vegaprotocol/environment';
// import { useVegaTransactionStore } from '@vegaprotocol/web3';
// import { MAXGOINT64 } from '@vegaprotocol/utils';
interface PositionsManagerProps { interface PositionsManagerProps {
partyIds: string[]; partyIds: string[];
@ -32,37 +30,35 @@ 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 disableClosePositionsButton = FLAGS.DISABLE_CLOSE_POSITION;
// TODO: Close position temporarily disabled in https://github.com/vegaprotocol/frontend-monorepo/pull/5350 const onClose = useCallback(
// ({ marketId, openVolume }: { marketId: string; openVolume: string }) =>
// const create = useVegaTransactionStore((store) => store.create); create({
// batchMarketInstructions: {
// const onClose = useCallback( cancellations: [
// ({ marketId, openVolume }: { marketId: string; openVolume: string }) => {
// create({ marketId,
// batchMarketInstructions: { orderId: '', // omit order id to cancel all active orders
// cancellations: [ },
// { ],
// marketId, submissions: [
// orderId: '', // omit order id to cancel all active orders {
// }, marketId: marketId,
// ], type: Schema.OrderType.TYPE_MARKET as const,
// submissions: [ timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_IOC as const,
// { side: openVolume.startsWith('-')
// marketId: marketId, ? Schema.Side.SIDE_BUY
// type: Schema.OrderType.TYPE_MARKET as const, : Schema.Side.SIDE_SELL,
// timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_IOC as const, size: HALFMAXGOINT64, // improvement for avoiding leftovers filled in the meantime when close request has been sent
// side: openVolume.startsWith('-') reduceOnly: true,
// ? 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,
@ -81,8 +77,7 @@ export const PositionsManager = ({
pubKeys={pubKeys} pubKeys={pubKeys}
rowData={data} rowData={data}
onMarketClick={onMarketClick} onMarketClick={onMarketClick}
// TODO: temporarily disable close position onClose={disableClosePositionsButton ? undefined : onClose}
// 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')}

View File

@ -1 +1,5 @@
export const MAXGOINT64 = '9223372036854775807'; export const MAXGOINT64 = '9223372036854775807';
// The fix for the close position functionality needs MaxInt64/2 for the size
// Issue: https://github.com/vegaprotocol/vega/issues/10177
// Core PR: https://github.com/vegaprotocol/vega/pull/10178
export const HALFMAXGOINT64 = '4611686018427387903';

View File

@ -41,7 +41,7 @@ import {
toBigNum, toBigNum,
truncateByChars, truncateByChars,
useFormatTrigger, useFormatTrigger,
MAXGOINT64, HALFMAXGOINT64,
} from '@vegaprotocol/utils'; } from '@vegaprotocol/utils';
import { useAssetsMapProvider } from '@vegaprotocol/assets'; import { useAssetsMapProvider } from '@vegaprotocol/assets';
import { useEthWithdrawApprovalsStore } from './use-ethereum-withdraw-approvals-store'; import { useEthWithdrawApprovalsStore } from './use-ethereum-withdraw-approvals-store';
@ -1014,7 +1014,7 @@ export const getVegaTransactionContentIntent = (tx: VegaStoredTxState) => {
tx.order && tx.order &&
tx.order.status === Schema.OrderStatus.STATUS_STOPPED && tx.order.status === Schema.OrderStatus.STATUS_STOPPED &&
tx.order.timeInForce === Schema.OrderTimeInForce.TIME_IN_FORCE_IOC && tx.order.timeInForce === Schema.OrderTimeInForce.TIME_IN_FORCE_IOC &&
tx.order.size === MAXGOINT64 && tx.order.size >= HALFMAXGOINT64 &&
// isClosePositionTransaction(tx) && // isClosePositionTransaction(tx) &&
Intent.Success; Intent.Success;