diff --git a/libs/accounts/src/lib/transfer-container.tsx b/libs/accounts/src/lib/transfer-container.tsx index 444a01a791..a02f07f949 100644 --- a/libs/accounts/src/lib/transfer-container.tsx +++ b/libs/accounts/src/lib/transfer-container.tsx @@ -23,7 +23,7 @@ export const ALLOWED_ACCOUNTS = [ export const TransferContainer = ({ assetId }: { assetId?: string }) => { const t = useT(); - const { pubKey, pubKeys } = useVegaWallet(); + const { pubKey, pubKeys, isReadOnly } = useVegaWallet(); const { params } = useNetworkParams([ NetworkParams.transfer_fee_factor, NetworkParams.transfer_minTransferQuantumMultiple, @@ -70,6 +70,7 @@ export const TransferContainer = ({ assetId }: { assetId?: string }) => { pk.publicKey) : null} + isReadOnly={isReadOnly} assetId={assetId} feeFactor={params.transfer_fee_factor} minQuantumMultiple={params.transfer_minTransferQuantumMultiple} diff --git a/libs/accounts/src/lib/transfer-form.spec.tsx b/libs/accounts/src/lib/transfer-form.spec.tsx index e7ff670846..d28bb5c08d 100644 --- a/libs/accounts/src/lib/transfer-form.spec.tsx +++ b/libs/accounts/src/lib/transfer-form.spec.tsx @@ -73,6 +73,28 @@ describe('TransferForm', () => { minQuantumMultiple: '1', }; + const propsNoAssets = { + pubKey, + pubKeys: [ + pubKey, + 'a4b6e3de5d7ef4e31ae1b090be49d1a2ef7bcefff60cccf7658a0d4922651cce', + ], + feeFactor: '0.001', + submitTransfer: jest.fn(), + accounts: [], + minQuantumMultiple: '1', + }; + + it('renders no assets', async () => { + renderComponent(propsNoAssets); + expect(screen.getByTestId('no-assets-available')).toBeVisible(); + }); + + it('renders no accounts', async () => { + renderComponent(propsNoAssets); + expect(screen.getByTestId('no-accounts-available')).toBeVisible(); + }); + it.each([ { targetText: 'Include transfer fee', diff --git a/libs/accounts/src/lib/transfer-form.tsx b/libs/accounts/src/lib/transfer-form.tsx index 861364c1ba..d31faabee5 100644 --- a/libs/accounts/src/lib/transfer-form.tsx +++ b/libs/accounts/src/lib/transfer-form.tsx @@ -45,6 +45,7 @@ interface Asset { export interface TransferFormProps { pubKey: string | null; pubKeys: string[] | null; + isReadOnly?: boolean; accounts: Array<{ type: AccountType; balance: string; @@ -59,6 +60,7 @@ export interface TransferFormProps { export const TransferForm = ({ pubKey, pubKeys, + isReadOnly, assetId: initialAssetId, feeFactor, submitTransfer, @@ -201,27 +203,36 @@ export const TransferForm = ({ ( - { - field.onChange(value); - setValue('fromAccount', ''); - }} - placeholder={t('Please select an asset')} - value={field.value} - > - {assets.map((a) => ( - } - /> - ))} - - )} + render={({ field }) => + assets.length > 0 ? ( + { + field.onChange(value); + setValue('fromAccount', ''); + }} + placeholder={t('Please select an asset')} + value={field.value} + > + {assets.map((a) => ( + } + /> + ))} + + ) : ( + + {t('No assets available')} + + ) + } /> {errors.asset?.message && ( @@ -249,48 +260,57 @@ export const TransferForm = ({ }, }, }} - render={({ field }) => ( - { - field.onChange(e); - - const [type] = parseFromAccount(e.target.value); - - // Enforce that if transferring from a vested rewards account it must go to - // the current connected general account - if ( - type === AccountType.ACCOUNT_TYPE_VESTED_REWARDS && - pubKey - ) { - setValue('toVegaKey', pubKey); - setToVegaKeyMode('select'); - setIncludeFee(false); - } - }} - > - - {accounts - .filter((a) => { - if (!selectedAssetId) return true; - return selectedAssetId === a.asset.id; - }) - .map((a) => { - const id = `${a.type}-${a.asset.id}`; - return ( - - ); - })} - - )} + render={({ field }) => + accounts.length > 0 ? ( + { + field.onChange(e); + + const [type] = parseFromAccount(e.target.value); + + // Enforce that if transferring from a vested rewards account it must go to + // the current connected general account + if ( + type === AccountType.ACCOUNT_TYPE_VESTED_REWARDS && + pubKey + ) { + setValue('toVegaKey', pubKey); + setToVegaKeyMode('select'); + setIncludeFee(false); + } + }} + > + + {accounts + .filter((a) => { + if (!selectedAssetId) return true; + return selectedAssetId === a.asset.id; + }) + .map((a) => { + const id = `${a.type}-${a.asset.id}`; + return ( + + ); + })} + + ) : ( + + {t('No accounts available')} + + ) + } /> {errors.fromAccount?.message && ( @@ -454,7 +474,7 @@ export const TransferForm = ({ decimals={asset?.decimals} /> )} - + {t('Confirm transfer')}