diff --git a/libs/accounts/src/lib/transfer-form.tsx b/libs/accounts/src/lib/transfer-form.tsx index 39857b206..285621a12 100644 --- a/libs/accounts/src/lib/transfer-form.tsx +++ b/libs/accounts/src/lib/transfer-form.tsx @@ -27,6 +27,8 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; import { Controller, useForm } from 'react-hook-form'; import { AssetOption, Balance } from '@vegaprotocol/assets'; import { AccountType, AccountTypeMapping } from '@vegaprotocol/types'; +import { useDataProvider } from '@vegaprotocol/data-provider'; +import { accountsDataProvider } from './accounts-data-provider'; interface FormFields { toVegaKey: string; @@ -77,6 +79,8 @@ export const TransferForm = ({ a.type === AccountType.ACCOUNT_TYPE_GENERAL || a.type === AccountType.ACCOUNT_TYPE_VESTED_REWARDS ) + // Sum the general and vested account balances so the value shown in the asset + // dropdown is correct for all transferable accounts .reduce((merged, account) => { const existing = merged.findIndex( (m) => m.asset.id === account.asset.id @@ -105,18 +109,30 @@ export const TransferForm = ({ const asset = assets.find((a) => a.id === assetId); + const { data: toAccounts } = useDataProvider({ + dataProvider: accountsDataProvider, + variables: { + partyId: selectedPubKey, + }, + skip: !selectedPubKey, + }); + const account = accounts.find( (a) => a.asset.id === assetId && a.type === fromAccount ); const accountBalance = account && addDecimal(account.balance, account.asset.decimals); - // General account for the selected asset - const generalAccount = accounts.find((a) => { - return ( - a.asset.id === assetId && a.type === AccountType.ACCOUNT_TYPE_GENERAL - ); - }); + // The general account of the selected pubkey. You can only transfer + // to general accounts, either when redeeming vested rewards or just + // during normal general -> general transfers + const toGeneralAccount = + toAccounts && + toAccounts.find((a) => { + return ( + a.asset.id === assetId && a.type === AccountType.ACCOUNT_TYPE_GENERAL + ); + }); const [includeFee, setIncludeFee] = useState(false); @@ -314,14 +330,16 @@ export const TransferForm = ({ defaultValue={AccountType.ACCOUNT_TYPE_GENERAL} >