From 28679089ea8349d4acaa02ba71ff746cfed4fc47 Mon Sep 17 00:00:00 2001 From: Ivanov N Date: Thu, 26 Dec 2024 18:44:53 +0300 Subject: [PATCH] fix: bug kly amount more than n characters --- src/components/SendFundsForm.vue | 9 +++++- src/lib/klayr/klayr-utils.ts | 53 +++++++++++++++++--------------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/components/SendFundsForm.vue b/src/components/SendFundsForm.vue index bd624e61e..32382795b 100644 --- a/src/components/SendFundsForm.vue +++ b/src/components/SendFundsForm.vue @@ -527,7 +527,14 @@ export default { () => isErc20(this.currency) ? this.ethBalance >= this.transferFee || this.$t('transfer.error_not_enough_eth_fee') - : true + : true, + (v) => { + const isKlyTransfer = this.currency === Cryptos.KLY + if (!isKlyTransfer) return true + const MAX_UINT64 = BigInt('18446744073709551615') + const isKlyTransferAllowed = isKlyTransfer && this.transferFee && v < MAX_UINT64 + return isKlyTransferAllowed || this.$t('transfer.error_incorrect_amount') + } ] } }, diff --git a/src/lib/klayr/klayr-utils.ts b/src/lib/klayr/klayr-utils.ts index 8f4a521a9..05f7eccbf 100644 --- a/src/lib/klayr/klayr-utils.ts +++ b/src/lib/klayr/klayr-utils.ts @@ -232,32 +232,37 @@ type EstimateFeeParams = { * @param params Transaction params */ export function estimateFee(params?: EstimateFeeParams) { - const { - amount = '1', - keyPair = KLY_DEMO_ACCOUNT.keyPair, - recipientAddress = KLY_DEMO_ACCOUNT.address, - data = '', - nonce = 0, - isNewAccount - } = params || {} + try { + const { + amount = '1', + keyPair = KLY_DEMO_ACCOUNT.keyPair, + recipientAddress = KLY_DEMO_ACCOUNT.address, + data = '', + nonce = 0, + isNewAccount + } = params || {} - const transaction = createTransaction( - { - publicKey: Buffer.from(keyPair.publicKey, 'hex'), - secretKey: Buffer.from(keyPair.secretKey, 'hex') - }, - recipientAddress, - amount, - 1, - nonce, - data - ) - const transactionBytes = hexToBytes(transaction.hex) + const transaction = createTransaction( + { + publicKey: Buffer.from(keyPair.publicKey, 'hex'), + secretKey: Buffer.from(keyPair.secretKey, 'hex') + }, + recipientAddress, + amount, + 1, + nonce, + data + ) + const transactionBytes = hexToBytes(transaction.hex) - const fee = BigInt(transactionBytes.length) * KLY_MIN_FEE_PER_BYTE - const transferToNewAccountFee = isNewAccount ? KLY_TRANSFER_TO_NEW_ACCOUNT_FEE : BigInt(0) + const fee = BigInt(transactionBytes.length) * KLY_MIN_FEE_PER_BYTE + const transferToNewAccountFee = isNewAccount ? KLY_TRANSFER_TO_NEW_ACCOUNT_FEE : BigInt(0) - const totalFee = fee + transferToNewAccountFee + const totalFee = fee + transferToNewAccountFee - return convertBeddowsTokly(totalFee.toString()) + return convertBeddowsTokly(totalFee.toString()) + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (err) { + return 0 + } }