Skip to content

Commit

Permalink
Merge pull request #2081 from Koniverse/koni/dev/issue-2079
Browse files Browse the repository at this point in the history
[Issue 2079] fix bug calculating max transferable
  • Loading branch information
saltict authored Oct 25, 2023
2 parents cf710f1 + 85e9852 commit 0e4f35f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/extension-base/src/koni/api/dotsama/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
16 changes: 10 additions & 6 deletions packages/extension-base/src/koni/background/handlers/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } })));
}
};

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -1979,13 +1979,17 @@ export default class KoniExtension {
destinationTokenInfo,
originTokenInfo: tokenInfo,
recipient: recipient,
sendingValue: '0',
sendingValue: '1000000000000000000',
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);
Expand All @@ -2011,7 +2015,7 @@ export default class KoniExtension {
to: address,
tokenInfo,
transferAll: true,
value: '0'
value: '1000000000000000000'
});

const paymentInfo = await mockTx?.paymentInfo(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ const _SendFund = ({ className = '' }: Props): React.ReactElement<Props> => {
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'));
}
Expand Down

1 comment on commit 0e4f35f

@saltict
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.