Skip to content

Commit

Permalink
fix: bug kly amount more than n characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivanov N committed Dec 26, 2024
1 parent 4ea7c6f commit 2867908
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
9 changes: 8 additions & 1 deletion src/components/SendFundsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
]
}
},
Expand Down
53 changes: 29 additions & 24 deletions src/lib/klayr/klayr-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 2867908

Please sign in to comment.