From b68dacf35743f286bfad600bbd1a66a1b5f516e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nam=20Ph=E1=BA=A1m?= Date: Wed, 25 Oct 2023 17:12:59 +0700 Subject: [PATCH 1/4] [Issue 2079] fix bug calculating max transferable --- .../src/koni/background/handlers/Extension.ts | 16 +++++++++++++--- .../src/Popup/Transaction/variants/SendFund.tsx | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/extension-base/src/koni/background/handlers/Extension.ts b/packages/extension-base/src/koni/background/handlers/Extension.ts index 9c6a5bb6da..a818c9ec82 100644 --- a/packages/extension-base/src/koni/background/handlers/Extension.ts +++ b/packages/extension-base/src/koni/background/handlers/Extension.ts @@ -1979,13 +1979,18 @@ export default class KoniExtension { destinationTokenInfo, originTokenInfo: tokenInfo, recipient: recipient, + // sendingValue: '1000000000000000000', sendingValue: '0', substrateApi }); - const paymentInfo = await mockTx.paymentInfo(address); + try { + const paymentInfo = await mockTx.paymentInfo(address); - estimatedFee = paymentInfo?.partialFee?.toString() || '0'; + estimatedFee = paymentInfo?.partialFee?.toString() || '0'; + } catch (e) { + estimatedFee = tokenInfo.minAmount || '0'; + } } } else { const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey); @@ -2011,7 +2016,7 @@ export default class KoniExtension { to: address, tokenInfo, transferAll: true, - value: '0' + value: '1000000000000000000' }); const paymentInfo = await mockTx?.paymentInfo(address); @@ -2026,6 +2031,11 @@ export default class KoniExtension { maxTransferable = maxTransferable.sub(new BN(estimatedFee)); + console.log('freeBalance', freeBalance.value); + console.log('estimatedFee', estimatedFee); + console.log('ED', tokenInfo.minAmount); + console.log('maxTransferable', maxTransferable.toString()); + return { ...freeBalance, value: maxTransferable.gt(BN_ZERO) ? (maxTransferable.toString() || '0') : '0' diff --git a/packages/extension-koni-ui/src/Popup/Transaction/variants/SendFund.tsx b/packages/extension-koni-ui/src/Popup/Transaction/variants/SendFund.tsx index 6d6231f46a..755f4088b5 100644 --- a/packages/extension-koni-ui/src/Popup/Transaction/variants/SendFund.tsx +++ b/packages/extension-koni-ui/src/Popup/Transaction/variants/SendFund.tsx @@ -366,6 +366,10 @@ const _SendFund = ({ className = '' }: Props): React.ReactElement => { return Promise.reject(t('Amount is required')); } + if ((new BN(maxTransfer)).lte(BN_ZERO)) { + return Promise.reject(t('You don\'t have enough tokens to proceed')); + } + if ((new BigN(amount)).eq(new BigN(0))) { return Promise.reject(t('Amount must be greater than 0')); } From 150ff4f560ad59ef3780d5f9fb8e4be086156f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nam=20Ph=E1=BA=A1m?= Date: Wed, 25 Oct 2023 17:17:03 +0700 Subject: [PATCH 2/4] [Issue 2079] fix bug calculating max transferable --- .../extension-base/src/koni/background/handlers/Extension.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/extension-base/src/koni/background/handlers/Extension.ts b/packages/extension-base/src/koni/background/handlers/Extension.ts index a818c9ec82..6f881eb928 100644 --- a/packages/extension-base/src/koni/background/handlers/Extension.ts +++ b/packages/extension-base/src/koni/background/handlers/Extension.ts @@ -1979,8 +1979,7 @@ export default class KoniExtension { destinationTokenInfo, originTokenInfo: tokenInfo, recipient: recipient, - // sendingValue: '1000000000000000000', - sendingValue: '0', + sendingValue: '1000000000000000000', substrateApi }); From 5d9b9217a2b427727805425a119b8223f78e19ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nam=20Ph=E1=BA=A1m?= Date: Wed, 25 Oct 2023 17:41:00 +0700 Subject: [PATCH 3/4] [Issue 2042] update transfer function --- packages/extension-base/src/koni/api/dotsama/transfer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/extension-base/src/koni/api/dotsama/transfer.ts b/packages/extension-base/src/koni/api/dotsama/transfer.ts index 4edf093a45..675e620099 100644 --- a/packages/extension-base/src/koni/api/dotsama/transfer.ts +++ b/packages/extension-base/src/koni/api/dotsama/transfer.ts @@ -206,7 +206,7 @@ export const createTransferExtrinsic = async ({ from, networkKey, substrateApi, if (transferAll) { transfer = api.tx.balances.transferAll(to, false); } else if (value) { - transfer = api.tx.balances.transfer(to, new BN(value)); + transfer = api.tx.balances.transferKeepAlive(to, new BN(value)); } } From 85e985248e38aeaa10e0b25111570ed61da0940f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nam=20Ph=E1=BA=A1m?= Date: Wed, 25 Oct 2023 19:10:48 +0700 Subject: [PATCH 4/4] [Issue 2079] remove logs and adjust wording --- .../src/koni/background/handlers/Extension.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/extension-base/src/koni/background/handlers/Extension.ts b/packages/extension-base/src/koni/background/handlers/Extension.ts index 6f881eb928..3937fa8e56 100644 --- a/packages/extension-base/src/koni/background/handlers/Extension.ts +++ b/packages/extension-base/src/koni/background/handlers/Extension.ts @@ -1712,7 +1712,7 @@ export default class KoniExtension { const atLeastStr = formatNumber(atLeast, tokenInfo.decimals || 0, balanceFormatter); - inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}}{{symbol}} to keep the destination account alive', { replace: { amount: atLeastStr, symbol: tokenInfo.symbol } }))); + inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}} {{symbol}} to keep the destination account alive', { replace: { amount: atLeastStr, symbol: tokenInfo.symbol } }))); } }; @@ -1785,7 +1785,7 @@ export default class KoniExtension { if (new BigN(value).lt(atLeast)) { const atLeastStr = formatNumber(atLeast, destinationTokenInfo.decimals || 0, balanceFormatter); - inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}}{{symbol}} to keep the destination account alive', { replace: { amount: atLeastStr, symbol: originTokenInfo.symbol } }))); + inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}} {{symbol}} to keep the destination account alive', { replace: { amount: atLeastStr, symbol: originTokenInfo.symbol } }))); } const srcMinAmount = originTokenInfo.minAmount || '0'; @@ -2030,11 +2030,6 @@ export default class KoniExtension { maxTransferable = maxTransferable.sub(new BN(estimatedFee)); - console.log('freeBalance', freeBalance.value); - console.log('estimatedFee', estimatedFee); - console.log('ED', tokenInfo.minAmount); - console.log('maxTransferable', maxTransferable.toString()); - return { ...freeBalance, value: maxTransferable.gt(BN_ZERO) ? (maxTransferable.toString() || '0') : '0'