From e15f391638d9cc2486d90140ac9ca6de3d15937e Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Wed, 13 Oct 2021 12:37:35 +0800 Subject: [PATCH] fix decimals for some chains --- src/libs/data/data.js | 15 +++++++++++++++ src/views/OperationDelegateComponent.vue | 4 ++-- src/views/OperationRedelegateComponent.vue | 4 ++-- src/views/OperationTransfer2Component.vue | 4 ++-- src/views/OperationTransferComponent.vue | 4 ++-- src/views/OperationUnbondComponent.vue | 4 ++-- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/libs/data/data.js b/src/libs/data/data.js index 055d6ce9..65513afe 100644 --- a/src/libs/data/data.js +++ b/src/libs/data/data.js @@ -268,12 +268,27 @@ export function formatTokenDenom(tokenDenom) { return '' } +export function getUnitAmount(amount, denom) { + if (denom.startsWith('basecro')) { + return String((Number(amount) * 100000000).toFixed()) + } + if (denom.startsWith('rowan')) { + // eslint-disable-next-line no-undef + return (BigInt(amount) * 1000000000000000000n).toString() + } + return String((Number(amount) * 1000000).toFixed()) +} + export function formatTokenAmount(tokenAmount, fraction = 2, denom = 'uatom') { let amount if (denom.startsWith('rowan')) { // eslint-disable-next-line no-undef amount = Number(BigInt(Number(tokenAmount)) / 1000000000000000000n) // } + } else if (denom.startsWith('basecro')) { + // eslint-disable-next-line no-undef + amount = Number(tokenAmount) / 100000000 + // } } else { amount = Number(tokenAmount) / 1000000 } diff --git a/src/views/OperationDelegateComponent.vue b/src/views/OperationDelegateComponent.vue index f5de40c7..10e1fcf5 100644 --- a/src/views/OperationDelegateComponent.vue +++ b/src/views/OperationDelegateComponent.vue @@ -262,7 +262,7 @@ import { required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, } from '@validations' import { - abbrAddress, formatToken, formatTokenDenom, getLocalAccounts, setLocalTxHistory, sign, timeIn, + abbrAddress, formatToken, formatTokenDenom, getLocalAccounts, getUnitAmount, setLocalTxHistory, sign, timeIn, } from '@/libs/data' import vSelect from 'vue-select' import ToastificationContent from '@core/components/toastification/ToastificationContent.vue' @@ -447,7 +447,7 @@ export default { delegatorAddress: this.selectedAddress, validatorAddress: this.selectedValidator, amount: { - amount: String((Number(this.amount) * 1000000).toFixed()), + amount: getUnitAmount(this.amount, this.token), denom: this.token, }, }, diff --git a/src/views/OperationRedelegateComponent.vue b/src/views/OperationRedelegateComponent.vue index ce546cdb..80ab3d81 100644 --- a/src/views/OperationRedelegateComponent.vue +++ b/src/views/OperationRedelegateComponent.vue @@ -253,7 +253,7 @@ import { required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, } from '@validations' import { - formatToken, formatTokenDenom, setLocalTxHistory, sign, timeIn, + formatToken, formatTokenDenom, getUnitAmount, setLocalTxHistory, sign, timeIn, } from '@/libs/data' import vSelect from 'vue-select' import ToastificationContent from '@core/components/toastification/ToastificationContent.vue' @@ -412,7 +412,7 @@ export default { validatorSrcAddress: this.validatorAddress, validatorDstAddress: this.toValidator, amount: { - amount: String((Number(this.amount) * 1000000).toFixed()), + amount: getUnitAmount(this.amount, this.token), denom: this.token, }, }, diff --git a/src/views/OperationTransfer2Component.vue b/src/views/OperationTransfer2Component.vue index 5f41c0c7..b01d1f36 100644 --- a/src/views/OperationTransfer2Component.vue +++ b/src/views/OperationTransfer2Component.vue @@ -286,7 +286,7 @@ import { required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, } from '@validations' import { - formatToken, formatTokenDenom, getLocalAccounts, getLocalChains, setLocalTxHistory, sign, timeIn, + formatToken, formatTokenDenom, getLocalAccounts, getLocalChains, getUnitAmount, setLocalTxHistory, sign, timeIn, } from '@/libs/data' import { Cosmos } from '@cosmostation/cosmosjs' import vSelect from 'vue-select' @@ -496,7 +496,7 @@ export default { value: { sourcePort: this.destination.port_id, sourceChannel: this.destination.channel_id, - token: coin(Number(this.amount) * 1000000, this.token), + token: coin(Number(getUnitAmount(this.amount, this.token)), this.token), sender: this.address, receiver: this.recipient, // timeoutHeight: undefined, // { revisionHeight: '0', revisionNumber: '0' }, diff --git a/src/views/OperationTransferComponent.vue b/src/views/OperationTransferComponent.vue index 0577574a..86b50955 100644 --- a/src/views/OperationTransferComponent.vue +++ b/src/views/OperationTransferComponent.vue @@ -255,7 +255,7 @@ import { required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, } from '@validations' import { - formatToken, formatTokenDenom, getLocalAccounts, getLocalChains, setLocalTxHistory, sign, timeIn, + formatToken, formatTokenDenom, getLocalAccounts, getLocalChains, getUnitAmount, setLocalTxHistory, sign, timeIn, } from '@/libs/data' import { Cosmos } from '@cosmostation/cosmosjs' import ToastificationContent from '@core/components/toastification/ToastificationContent.vue' @@ -418,7 +418,7 @@ export default { toAddress: this.recipient, amount: [ { - amount: String((Number(this.amount) * 1000000).toFixed()), + amount: getUnitAmount(this.amount, this.token), denom: this.token, }, ], diff --git a/src/views/OperationUnbondComponent.vue b/src/views/OperationUnbondComponent.vue index a308f117..67e29145 100644 --- a/src/views/OperationUnbondComponent.vue +++ b/src/views/OperationUnbondComponent.vue @@ -231,7 +231,7 @@ import { required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, } from '@validations' import { - formatToken, formatTokenDenom, setLocalTxHistory, sign, timeIn, + formatToken, formatTokenDenom, getUnitAmount, setLocalTxHistory, sign, timeIn, } from '@/libs/data' import vSelect from 'vue-select' import ToastificationContent from '@core/components/toastification/ToastificationContent.vue' @@ -390,7 +390,7 @@ export default { delegatorAddress: this.selectedAddress, validatorAddress: this.selectedValidator, amount: { - amount: String((Number(this.amount) * 1000000).toFixed()), + amount: getUnitAmount(this.amount, this.token), denom: this.token, }, },