fix decimals for some chains

This commit is contained in:
liangping 2021-10-13 12:37:35 +08:00
parent dbb4f6183c
commit e15f391638
6 changed files with 25 additions and 10 deletions

View File

@ -268,12 +268,27 @@ export function formatTokenDenom(tokenDenom) {
return '' 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') { export function formatTokenAmount(tokenAmount, fraction = 2, denom = 'uatom') {
let amount let amount
if (denom.startsWith('rowan')) { if (denom.startsWith('rowan')) {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
amount = Number(BigInt(Number(tokenAmount)) / 1000000000000000000n) amount = Number(BigInt(Number(tokenAmount)) / 1000000000000000000n)
// } // }
} else if (denom.startsWith('basecro')) {
// eslint-disable-next-line no-undef
amount = Number(tokenAmount) / 100000000
// }
} else { } else {
amount = Number(tokenAmount) / 1000000 amount = Number(tokenAmount) / 1000000
} }

View File

@ -262,7 +262,7 @@ import {
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
} from '@validations' } from '@validations'
import { import {
abbrAddress, formatToken, formatTokenDenom, getLocalAccounts, setLocalTxHistory, sign, timeIn, abbrAddress, formatToken, formatTokenDenom, getLocalAccounts, getUnitAmount, setLocalTxHistory, sign, timeIn,
} from '@/libs/data' } from '@/libs/data'
import vSelect from 'vue-select' import vSelect from 'vue-select'
import ToastificationContent from '@core/components/toastification/ToastificationContent.vue' import ToastificationContent from '@core/components/toastification/ToastificationContent.vue'
@ -447,7 +447,7 @@ export default {
delegatorAddress: this.selectedAddress, delegatorAddress: this.selectedAddress,
validatorAddress: this.selectedValidator, validatorAddress: this.selectedValidator,
amount: { amount: {
amount: String((Number(this.amount) * 1000000).toFixed()), amount: getUnitAmount(this.amount, this.token),
denom: this.token, denom: this.token,
}, },
}, },

View File

@ -253,7 +253,7 @@ import {
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
} from '@validations' } from '@validations'
import { import {
formatToken, formatTokenDenom, setLocalTxHistory, sign, timeIn, formatToken, formatTokenDenom, getUnitAmount, setLocalTxHistory, sign, timeIn,
} from '@/libs/data' } from '@/libs/data'
import vSelect from 'vue-select' import vSelect from 'vue-select'
import ToastificationContent from '@core/components/toastification/ToastificationContent.vue' import ToastificationContent from '@core/components/toastification/ToastificationContent.vue'
@ -412,7 +412,7 @@ export default {
validatorSrcAddress: this.validatorAddress, validatorSrcAddress: this.validatorAddress,
validatorDstAddress: this.toValidator, validatorDstAddress: this.toValidator,
amount: { amount: {
amount: String((Number(this.amount) * 1000000).toFixed()), amount: getUnitAmount(this.amount, this.token),
denom: this.token, denom: this.token,
}, },
}, },

View File

@ -286,7 +286,7 @@ import {
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
} from '@validations' } from '@validations'
import { import {
formatToken, formatTokenDenom, getLocalAccounts, getLocalChains, setLocalTxHistory, sign, timeIn, formatToken, formatTokenDenom, getLocalAccounts, getLocalChains, getUnitAmount, setLocalTxHistory, sign, timeIn,
} from '@/libs/data' } from '@/libs/data'
import { Cosmos } from '@cosmostation/cosmosjs' import { Cosmos } from '@cosmostation/cosmosjs'
import vSelect from 'vue-select' import vSelect from 'vue-select'
@ -496,7 +496,7 @@ export default {
value: { value: {
sourcePort: this.destination.port_id, sourcePort: this.destination.port_id,
sourceChannel: this.destination.channel_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, sender: this.address,
receiver: this.recipient, receiver: this.recipient,
// timeoutHeight: undefined, // { revisionHeight: '0', revisionNumber: '0' }, // timeoutHeight: undefined, // { revisionHeight: '0', revisionNumber: '0' },

View File

@ -255,7 +255,7 @@ import {
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
} from '@validations' } from '@validations'
import { import {
formatToken, formatTokenDenom, getLocalAccounts, getLocalChains, setLocalTxHistory, sign, timeIn, formatToken, formatTokenDenom, getLocalAccounts, getLocalChains, getUnitAmount, setLocalTxHistory, sign, timeIn,
} from '@/libs/data' } from '@/libs/data'
import { Cosmos } from '@cosmostation/cosmosjs' import { Cosmos } from '@cosmostation/cosmosjs'
import ToastificationContent from '@core/components/toastification/ToastificationContent.vue' import ToastificationContent from '@core/components/toastification/ToastificationContent.vue'
@ -418,7 +418,7 @@ export default {
toAddress: this.recipient, toAddress: this.recipient,
amount: [ amount: [
{ {
amount: String((Number(this.amount) * 1000000).toFixed()), amount: getUnitAmount(this.amount, this.token),
denom: this.token, denom: this.token,
}, },
], ],

View File

@ -231,7 +231,7 @@ import {
required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, required, email, url, between, alpha, integer, password, min, digits, alphaDash, length,
} from '@validations' } from '@validations'
import { import {
formatToken, formatTokenDenom, setLocalTxHistory, sign, timeIn, formatToken, formatTokenDenom, getUnitAmount, setLocalTxHistory, sign, timeIn,
} from '@/libs/data' } from '@/libs/data'
import vSelect from 'vue-select' import vSelect from 'vue-select'
import ToastificationContent from '@core/components/toastification/ToastificationContent.vue' import ToastificationContent from '@core/components/toastification/ToastificationContent.vue'
@ -390,7 +390,7 @@ export default {
delegatorAddress: this.selectedAddress, delegatorAddress: this.selectedAddress,
validatorAddress: this.selectedValidator, validatorAddress: this.selectedValidator,
amount: { amount: {
amount: String((Number(this.amount) * 1000000).toFixed()), amount: getUnitAmount(this.amount, this.token),
denom: this.token, denom: this.token,
}, },
}, },