Skip to content

Commit cd0a0e6

Browse files
committed
Implement client based nonEVM zero balance check to send flow
1 parent 5dbfbc2 commit cd0a0e6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

ui/pages/confirmations/hooks/send/useAmountValidation.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,25 @@ describe('useAmountValidation', () => {
415415
const error = await result.current.validateNonEvmAmountAsync();
416416
expect(error).toEqual(undefined);
417417
});
418+
419+
it('returns error when non-EVM account has zero balance', async () => {
420+
jest.spyOn(SendContext, 'useSendContext').mockReturnValue({
421+
asset: {
422+
isNative: true,
423+
rawBalance: '0x0',
424+
decimals: 18,
425+
},
426+
chainId: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
427+
from: MOCK_ADDRESS_1,
428+
value: '1',
429+
} as unknown as SendContext.SendContextType);
430+
431+
const { result } = renderHookWithProvider(
432+
() => useAmountValidation(),
433+
mockState,
434+
);
435+
await waitFor(() =>
436+
expect(result.current.amountError).toEqual('Insufficient funds'),
437+
);
438+
});
418439
});

ui/pages/confirmations/hooks/send/useAmountValidation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export const useAmountValidation = () => {
3737
return undefined;
3838
}
3939

40+
if (rawBalanceNumeric.isZero()) {
41+
return t('insufficientFundsSend');
42+
}
43+
4044
try {
4145
const result = (await validateAmountWithSnap(
4246
value || '0',
@@ -49,7 +53,7 @@ export const useAmountValidation = () => {
4953
} catch (error) {
5054
return t('invalidValue');
5155
}
52-
}, [t, value, validateAmountWithSnap, isNonEvmSendType]);
56+
}, [t, value, validateAmountWithSnap, isNonEvmSendType, rawBalanceNumeric]);
5357

5458
const validateAmountAsync = useCallback(async () => {
5559
if (!value) {

0 commit comments

Comments
 (0)