From a642bf8ce4f79dc1ac0c4067710fc28f1eff9539 Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Wed, 1 Nov 2023 15:57:38 -0700 Subject: [PATCH] chore(trading): misc changes to trades and transfer (#5175) --- .../src/lib/accounts-data-provider.ts | 2 + libs/accounts/src/lib/transfer-container.tsx | 20 +++++---- libs/accounts/src/lib/transfer-form.tsx | 31 ++++++++----- libs/datagrid/src/lib/pagination.tsx | 2 +- libs/trades/src/lib/trades-manager.tsx | 45 ++++--------------- 5 files changed, 44 insertions(+), 56 deletions(-) diff --git a/libs/accounts/src/lib/accounts-data-provider.ts b/libs/accounts/src/lib/accounts-data-provider.ts index 2ccdd3e07..c69eec11c 100644 --- a/libs/accounts/src/lib/accounts-data-provider.ts +++ b/libs/accounts/src/lib/accounts-data-provider.ts @@ -112,6 +112,8 @@ const USE_ACCOUNT_TYPES = [ AccountType.ACCOUNT_TYPE_FEES_LIQUIDITY, AccountType.ACCOUNT_TYPE_FEES_MAKER, AccountType.ACCOUNT_TYPE_PENDING_TRANSFERS, + AccountType.ACCOUNT_TYPE_VESTED_REWARDS, + AccountType.ACCOUNT_TYPE_VESTING_REWARDS, ]; const getAssetIds = (data: Account[]) => diff --git a/libs/accounts/src/lib/transfer-container.tsx b/libs/accounts/src/lib/transfer-container.tsx index fc9af6bec..15cd5063d 100644 --- a/libs/accounts/src/lib/transfer-container.tsx +++ b/libs/accounts/src/lib/transfer-container.tsx @@ -42,15 +42,17 @@ export const TransferContainer = ({ assetId }: { assetId?: string }) => { ? data.filter((account) => ALLOWED_ACCOUNTS.includes(account.type)) : []; - const assets = accounts.map((account) => ({ - id: account.asset.id, - symbol: account.asset.symbol, - name: account.asset.name, - decimals: account.asset.decimals, - balance: addDecimal(account.balance, account.asset.decimals), - })); - - if (data === null) return null; + const assets = accounts + // Theres only one general account for each asset, this will give us a list + // of assets the user has accounts for + .filter((a) => a.type === Schema.AccountType.ACCOUNT_TYPE_GENERAL) + .map((account) => ({ + id: account.asset.id, + symbol: account.asset.symbol, + name: account.asset.name, + decimals: account.asset.decimals, + balance: addDecimal(account.balance, account.asset.decimals), + })); return ( <> diff --git a/libs/accounts/src/lib/transfer-form.tsx b/libs/accounts/src/lib/transfer-form.tsx index 8a6bd542d..ce7ea5dd6 100644 --- a/libs/accounts/src/lib/transfer-form.tsx +++ b/libs/accounts/src/lib/transfer-form.tsx @@ -5,6 +5,7 @@ import { vegaPublicKey, addDecimal, formatNumber, + addDecimalsFormatNumber, } from '@vegaprotocol/utils'; import { t } from '@vegaprotocol/i18n'; import { @@ -47,7 +48,8 @@ interface TransferFormProps { assets: Array; accounts: Array<{ type: AccountType; - asset: { id: string; symbol: string }; + balance: string; + asset: { id: string; symbol: string; decimals: number }; }>; assetId?: string; feeFactor: string | null; @@ -79,6 +81,7 @@ export const TransferForm = ({ const selectedPubKey = watch('toAddress'); const amount = watch('amount'); const assetId = watch('asset'); + const asset = assets.find((a) => a.id === assetId); const [includeFee, setIncludeFee] = useState(false); @@ -100,10 +103,6 @@ export const TransferForm = ({ ); }, [amount, includeFee, transferAmount, feeFactor]); - const asset = useMemo(() => { - return assets.find((a) => a.id === assetId); - }, [assets, assetId]); - const onSubmit = useCallback( (fields: FormFields) => { if (!asset) { @@ -147,6 +146,13 @@ export const TransferForm = ({ } }, [setValue, pubKey]); + // General account for the selected asset + const generalAccount = accounts.find((a) => { + return ( + a.asset.id === assetId && a.type === AccountType.ACCOUNT_TYPE_GENERAL + ); + }); + return (
{ return ( ); })} @@ -289,10 +297,13 @@ export const TransferForm = ({ defaultValue={AccountType.ACCOUNT_TYPE_GENERAL} > diff --git a/libs/datagrid/src/lib/pagination.tsx b/libs/datagrid/src/lib/pagination.tsx index 412f6d0e6..c552a87ef 100644 --- a/libs/datagrid/src/lib/pagination.tsx +++ b/libs/datagrid/src/lib/pagination.tsx @@ -32,7 +32,7 @@ export const Pagination = ({ {false} {showRetentionMessage && t( - 'Depending on data node retention you may not be able see the "full" history' + 'Depending on data node retention you may not be able see the full history' )}
diff --git a/libs/trades/src/lib/trades-manager.tsx b/libs/trades/src/lib/trades-manager.tsx index d7de33d70..73dc7f8cf 100644 --- a/libs/trades/src/lib/trades-manager.tsx +++ b/libs/trades/src/lib/trades-manager.tsx @@ -3,10 +3,7 @@ import { tradesWithMarketProvider } from './trades-data-provider'; import { TradesTable } from './trades-table'; import { useDealTicketFormValues } from '@vegaprotocol/deal-ticket'; import { t } from '@vegaprotocol/i18n'; -import { Pagination } from '@vegaprotocol/datagrid'; import type { useDataGridEvents } from '@vegaprotocol/datagrid'; -import { useCallback, useState } from 'react'; -import type { AgGridReact } from 'ag-grid-react'; interface TradesContainerProps { marketId: string; @@ -19,43 +16,19 @@ export const TradesManager = ({ }: TradesContainerProps) => { const update = useDealTicketFormValues((state) => state.updateAll); - const { data, error, load, pageInfo } = useDataProvider({ + const { data, error } = useDataProvider({ dataProvider: tradesWithMarketProvider, variables: { marketId }, }); - const [hasDisplayedRow, setHasDisplayedRow] = useState( - undefined - ); - const { onFilterChanged, ...props } = gridProps || {}; - const onRowDataUpdated = useCallback( - ({ api }: { api: AgGridReact['api'] }) => { - setHasDisplayedRow(!!api.getDisplayedRowCount()); - }, - [] - ); return ( -
- { - update(marketId, { price }); - }} - onFilterChanged={(event) => { - onRowDataUpdated(event); - onFilterChanged(event); - }} - onRowDataUpdated={onRowDataUpdated} - overlayNoRowsTemplate={error ? error.message : t('No trades')} - {...props} - /> - -
+ { + update(marketId, { price }); + }} + overlayNoRowsTemplate={error ? error.message : t('No trades')} + {...gridProps} + /> ); };