diff --git a/src/components/SendFundsForm.vue b/src/components/SendFundsForm.vue index 141e8a5b4..53ecdbedb 100644 --- a/src/components/SendFundsForm.vue +++ b/src/components/SendFundsForm.vue @@ -229,6 +229,8 @@ import { isStringEqualCI } from '@/lib/textHelpers' import { formatSendTxError } from '@/lib/txVerify' import { AllCryptos } from '@/lib/constants/cryptos' +import { MAX_UINT64 } from '@klayr/validator' + /** * @returns {string | boolean} */ @@ -533,7 +535,6 @@ export default { (v) => { const isKlyTransfer = this.currency === Cryptos.KLY if (!isKlyTransfer) return true - const MAX_UINT64 = BigInt('18446744073709551615') const isKlyTransferAllowed = this.transferFee && transactions.convertklyToBeddows(v.toFixed(KLY_DECIMALS)) < MAX_UINT64 diff --git a/src/lib/klayr/klayr-utils.ts b/src/lib/klayr/klayr-utils.ts index 05f7eccbf..8f4a521a9 100644 --- a/src/lib/klayr/klayr-utils.ts +++ b/src/lib/klayr/klayr-utils.ts @@ -232,37 +232,32 @@ type EstimateFeeParams = { * @param params Transaction params */ export function estimateFee(params?: EstimateFeeParams) { - try { - const { - amount = '1', - keyPair = KLY_DEMO_ACCOUNT.keyPair, - recipientAddress = KLY_DEMO_ACCOUNT.address, - data = '', - nonce = 0, - isNewAccount - } = params || {} + 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()) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - } catch (err) { - return 0 - } + return convertBeddowsTokly(totalFee.toString()) } diff --git a/src/store/modules/kly/kly-getters.js b/src/store/modules/kly/kly-getters.js index 036de8b9e..f0f3da7ff 100644 --- a/src/store/modules/kly/kly-getters.js +++ b/src/store/modules/kly/kly-getters.js @@ -5,12 +5,17 @@ export default { ...baseGetters, fee: (state) => (amount, recipientAddress, data, isNewAccount) => { - return estimateFee({ - amount, - data, - isNewAccount, - nonce: state.nonce - }) + try { + return estimateFee({ + amount, + data, + isNewAccount, + nonce: state.nonce + }) + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (error) { + return 0 + } }, height(state) {