forked from cerc-io/cosmos-explorer
fix decimals for some chains
This commit is contained in:
parent
dbb4f6183c
commit
e15f391638
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
@ -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' },
|
||||
|
@ -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,
|
||||
},
|
||||
],
|
||||
|
@ -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,
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user