diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 28781d87..b5b3c196 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -321,7 +321,10 @@ export default class ChainFetch { async getIBCDenomTrace(hash, config = null) { const h = hash.substring(hash.indexOf('/') + 1) - return this.get('/ibc/applications/transfer/v1beta1/denom_traces/'.concat(h), config).then(data => commonProcess(data)) + if (compareVersions(this.config.sdk_version, '0.42.6') < 0) { + return this.get('/ibc/applications/transfer/v1beta1/denom_traces/'.concat(h), config).then(data => commonProcess(data)) + } + return this.get('/ibc/apps/transfer/v1/denom_traces/'.concat(h), config).then(data => commonProcess(data)) } async getIBCChannels(config = null, key = null) { @@ -401,8 +404,9 @@ export default class ChainFetch { if (!config) { this.getSelectedConfig() } + const host = (config ? config.api : this.config.api) // Default options are marked with * - const response = await fetch((config ? config.api : this.config.api) + url, { + const response = await fetch((Array.isArray(host) ? host[0] : host) + url, { method: 'POST', // *GET, POST, PUT, DELETE, etc. // mode: 'cors', // no-cors, *cors, same-origin // credentials: 'same-origin', // redirect: 'follow', // manual, *follow, error diff --git a/src/libs/utils.js b/src/libs/utils.js index 946c4c60..40f8e823 100644 --- a/src/libs/utils.js +++ b/src/libs/utils.js @@ -294,8 +294,9 @@ export function formatTokenDenom(tokenDenom) { return '' } -export function getUnitAmount(amount, denom) { - let exp = 1 +export function getUnitAmount(amount, tokenDenom) { + const denom = tokenDenom.denom_trace ? tokenDenom.denom_trace.base_denom : tokenDenom + let exp = 6 const config = Object.values(getLocalChains()) config.forEach(x => { @@ -304,27 +305,14 @@ export function getUnitAmount(amount, denom) { if (asset) exp = asset.exponent } }) - // if (denom === 'boot') { - // return String(amount) - // } - // if (denom.startsWith('basecro')) { - // return String((Number(amount) * 100000000).toFixed()) - // } - // if (denom.startsWith('rowan') || denom.startsWith('aphoton')) { - // // eslint-disable-next-line no-undef - // return (BigInt(amount) * 1000000000000000000n).toString() - // } - // if (denom.startsWith('nanolike')) { - // // eslint-disable-next-line no-undef - // return String((Number(amount) * 1000000000).toFixed()) - // } return String((Number(amount) * (10 ** exp)).toFixed()) } -export function formatTokenAmount(tokenAmount, fraction = 2, denom = 'uatom') { +export function formatTokenAmount(tokenAmount, fraction = 2, tokenDenom = 'uatom') { + const denom = tokenDenom.denom_trace ? tokenDenom.denom_trace.base_denom : tokenDenom let amount = 0 - let exp = 1 + let exp = 6 const config = Object.values(getLocalChains()) config.forEach(x => { @@ -334,24 +322,6 @@ export function formatTokenAmount(tokenAmount, fraction = 2, denom = 'uatom') { } }) amount = Number(Number(tokenAmount)) / (10 ** exp) - - // if (denom === 'boot') { - // amount = Number(tokenAmount) - // } else if (denom.startsWith('inj')) { - // // eslint-disable-next-line no-undef - // amount = Number(BigInt(Number(tokenAmount)) / 1000000000000000000n) - // // } - // } else if (denom === 'rowan' || denom === 'aphoton') { - // // eslint-disable-next-line no-undef - // amount = Number(BigInt(Number(tokenAmount)) / 1000000000000000000n) - // // } - // } else if (denom.startsWith('basecro')) { - // amount = Number(tokenAmount) / 100000000 - // } else if (denom.startsWith('nanolike')) { - // amount = Number(tokenAmount) / 1000000000 - // } else { - // amount = Number(tokenAmount) / 1000000 - // } if (amount > 10) { return parseFloat(amount.toFixed(fraction)) } diff --git a/src/views/WalletAccounts.vue b/src/views/WalletAccounts.vue index f9480b46..cda0afa6 100644 --- a/src/views/WalletAccounts.vue +++ b/src/views/WalletAccounts.vue @@ -566,7 +566,8 @@ export default { }, formatAmount(v, denom = 'uatom') { if (!v) return '' - return formatTokenAmount(v, 2, denom) + const denom2 = (denom.startsWith('ibc') ? this.ibcDenom[denom] : denom) + return formatTokenAmount(v, 2, denom2) }, formatAddr(v) { return v.substring(0, 10).concat('...', v.substring(v.length - 10))