Skip to content

Commit

Permalink
OK-34450: Prevent zero amount transfer on SUI (#6375)
Browse files Browse the repository at this point in the history
* fix: prevent zero amount transfer on SUI

* fix: add allCoins length condition

* fix: benfen zero amount transaction

---------

Co-authored-by: 蔡凯升 <[email protected]>
  • Loading branch information
originalix and wabicai authored Dec 19, 2024
1 parent 3b0baa7 commit 80cc134
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 10 additions & 3 deletions packages/kit-bg/src/vaults/impls/bfc/sdkBfc/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { TransactionBlock } from '@benfen/bfc.js/transactions';
import { BFC_TYPE_ARG } from '@benfen/bfc.js/utils';
import BigNumber from 'bignumber.js';

import { OneKeyInternalError } from '@onekeyhq/shared/src/errors';
import { ETranslations } from '@onekeyhq/shared/src/locale';
import timerUtils from '@onekeyhq/shared/src/utils/timerUtils';

import { normalizeBfcCoinType, objectTypeToCoinType } from './utils';
Expand Down Expand Up @@ -94,10 +96,15 @@ async function createTokenTransaction({
new BigNumber(0),
);

if (totalBalance.lt(amount)) {
throw new Error('Insufficient balance');
if (
totalBalance.lt(amount) ||
(totalBalance.isZero() && allCoins.length === 0)
) {
throw new OneKeyInternalError({
key: ETranslations.earn_insufficient_balance,
});
}

// Max send native token
if (maxSendNativeToken && coinType === BFC_TYPE_ARG) {
tx.transferObjects([tx.gas], recipient);
Expand Down
11 changes: 9 additions & 2 deletions packages/kit-bg/src/vaults/impls/sui/sdkSui/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Transaction } from '@mysten/sui/transactions';
import { SUI_TYPE_ARG } from '@mysten/sui/utils';
import BigNumber from 'bignumber.js';

import { OneKeyInternalError } from '@onekeyhq/shared/src/errors';
import { ETranslations } from '@onekeyhq/shared/src/locale';
import timerUtils from '@onekeyhq/shared/src/utils/timerUtils';

import { normalizeSuiCoinType } from './utils';
Expand Down Expand Up @@ -91,8 +93,13 @@ async function createTokenTransaction({
new BigNumber(0),
);

if (totalBalance.lt(amount)) {
throw new Error('Insufficient balance');
if (
totalBalance.lt(amount) ||
(totalBalance.isZero() && allCoins.length === 0)
) {
throw new OneKeyInternalError({
key: ETranslations.earn_insufficient_balance,
});
}

// Max send native token
Expand Down

0 comments on commit 80cc134

Please sign in to comment.