Skip to content

Commit

Permalink
fix: per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivanov N committed Dec 27, 2024
1 parent fe08d66 commit f4141c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/components/SendFundsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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
Expand Down
53 changes: 24 additions & 29 deletions src/lib/klayr/klayr-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
17 changes: 11 additions & 6 deletions src/store/modules/kly/kly-getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f4141c0

Please sign in to comment.