Update IBC denom

This commit is contained in:
liangping 2022-01-11 12:12:07 +08:00
parent 15ce00fda5
commit 62af7ccc27
8 changed files with 175 additions and 38 deletions

View File

@ -10,7 +10,7 @@
"assets": [{
"base": "inj",
"symbol": "INJ",
"exponent": "0",
"exponent": "18",
"coingecko_id": "injective-protocol",
"logo": "https://dl.airtable.com/.attachments/e024faae112ae873d301f9e1e17a921c/3f3671f7/9pOKAlQ5_400x400.jpg"
}]

View File

@ -13,5 +13,11 @@
"exponent": "6",
"coingecko_id": "osmosis",
"logo": "https://dl.airtable.com/.attachments/4ef30ec4008bc86cc3c0f74a6bb84050/0eeb4d64/aQ5W3zaT_400x400.jpg"
},{
"base": "uion",
"symbol": "ION",
"exponent": "6",
"coingecko_id": "ion",
"logo": "https://dl.airtable.com/.attachments/4ef30ec4008bc86cc3c0f74a6bb84050/0eeb4d64/aQ5W3zaT_400x400.jpg"
}]
}

View File

@ -13,5 +13,125 @@
"exponent": "6",
"coingecko_id": "terra-luna",
"logo": "https://dl.airtable.com/.attachments/275a6cbdbdc911856556e716a60d6ec4/87addd7f/terra.jpg"
},{
"base": "uusd",
"symbol": "UST",
"exponent": "6",
"coingecko_id": "terrausd",
"logo": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/ust.png"
},{
"base": "ukrw",
"symbol": "KRT",
"exponent": "6",
"coingecko_id": "terrakrw",
"logo": "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/images/krt.png"
},{
"base": "cw20:terra183cvzy6knvva6mpvzcq86uyfxw0nd4925m0d0m",
"symbol": "WHALE",
"exponent": "6",
"coingecko_id": "white-whale",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "uaud",
"symbol": "AUD",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "ucad",
"symbol": "CAD",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "uchf",
"symbol": "CHF",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "ucny",
"symbol": "CNY",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "udkk",
"symbol": "DKK",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "ueur",
"symbol": "EUR",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "ugbp",
"symbol": "GBP",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "uhkd",
"symbol": "HKD",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "uidr",
"symbol": "IDR",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "uinr",
"symbol": "INR",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "ujpy",
"symbol": "JPY",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "umnt",
"symbol": "MNT",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "uphp",
"symbol": "PHP",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "usdr",
"symbol": "SDR",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "usek",
"symbol": "SEK",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "usgd",
"symbol": "SGD",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
},{
"base": "uthb",
"symbol": "THB",
"exponent": "6",
"coingecko_id": "",
"logo": "https://www.whitewhale.money/tokenlogo.png"
}]
}

View File

@ -319,6 +319,14 @@ export default class ChainFetch {
return this.get('/bank/balances/'.concat(address), config).then(data => commonProcess(data))
}
async getAllIBCDenoms(config = null) {
const sdkVersion = config ? config.sdk_version : this.config.sdk_version
if (compareVersions(sdkVersion, '0.42.4') < 0) {
return this.get('/ibc/applications/transfer/v1beta1/denom_traces?pagination.limit=500', config).then(data => commonProcess(data))
}
return this.get('/ibc/apps/transfer/v1/denom_traces?pagination.limit=500', config).then(data => commonProcess(data))
}
async getIBCDenomTrace(hash, config = null) {
const h = hash.substring(hash.indexOf('/') + 1)
const sdkVersion = config ? config.sdk_version : this.config.sdk_version

View File

@ -288,8 +288,7 @@ export function formatTokenDenom(tokenDenom) {
if (asset) denom = asset.symbol
}
})
return denom.toUpperCase()
return denom.startsWith('ibc') ? `IBC...${denom.substring(denom.length - 3)}` : denom.toUpperCase()
}
return ''
}

View File

@ -34,7 +34,7 @@
<h6 class="transaction-title">
{{ formatNumber(d.amount) }}
</h6>
<small>{{ d.denom }} </small>
<small>{{ formatDenom(d.denom) }} </small>
</b-media-body>
</b-media>
<small
@ -65,7 +65,7 @@
<h6 class="transaction-title">
{{ formatNumber(d.amount) }}
</h6>
<small>{{ d.denom }}</small>
<small>{{ formatDenom(d.denom) }}</small>
</b-media-body>
</b-media>
<small
@ -96,6 +96,8 @@
import {
BCard, BCardHeader, BCardTitle, BCardBody, BMediaBody, BMedia, BMediaAside, BAvatar, BButton,
} from 'bootstrap-vue'
import { sha256 } from '@cosmjs/crypto'
import { toHex } from '@cosmjs/encoding'
import OperationWithdrawCommissionComponent from './OperationWithdrawCommissionComponent.vue'
export default {
@ -127,12 +129,24 @@ export default {
},
data() {
return {
denoms: {},
}
},
created() {
this.$http.getAllIBCDenoms().then(x => {
x.denom_traces.forEach(trace => {
const hash = toHex(sha256(new TextEncoder().encode(`${trace.path}/${trace.base_denom}`)))
this.$set(this.denoms, `ibc/${hash.toUpperCase()}`, trace.base_denom)
})
})
},
methods: {
formatNumber(value) {
return Number(value).toFixed(2)
},
formatDenom(value) {
return value.startsWith('ibc') ? this.denoms[value] : value
},
},
}
</script>

View File

@ -15,6 +15,8 @@
</template>
<script>
import { sha256 } from '@cosmjs/crypto'
import { toHex } from '@cosmjs/encoding'
import { BTable, BCardTitle, BCard } from 'bootstrap-vue'
import { formatNumber, formatTokenAmount, formatTokenDenom } from '@/libs/utils'
@ -28,7 +30,7 @@ export default {
return {
islive: true,
assets: [],
denoms: [],
denoms: {},
cfield: [
{
key: 'denom',
@ -43,27 +45,19 @@ export default {
}
},
created() {
const denoms = []
this.$http.getAllIBCDenoms().then(x => {
x.denom_traces.forEach(trace => {
const hash = toHex(sha256(new TextEncoder().encode(`${trace.path}/${trace.base_denom}`)))
this.$set(this.denoms, `ibc/${hash.toUpperCase()}`, trace.base_denom)
})
})
this.$http.getBankTotals().then(res => {
const toshow = res.sort()
this.assets = toshow.reverse().map(x => {
if (x.denom.startsWith('ibc/')) {
denoms.push(x.denom)
}
const xh = x
const amount = Number(x.amount) / 1000000
xh.abbr = amount > 1 ? formatNumber(formatTokenAmount(x.amount, 0, x.denom), true, 2) : amount
xh.abbr = x.amount > 1 ? formatNumber(formatTokenAmount(x.amount, 0, x.denom), true, 2) : x.amount
return xh
})
// let promise = Promise.resolve()
// denoms.forEach(x => {
// promise = promise.then(() => new Promise(resolve => {
// chainAPI.getIBCDenomTraceText(this.$http.config.api, x).then(denom => {
// if (this.islive) resolve()
// this.$set(this.denoms, x, denom)
// })
// }))
// })
})
},
beforeDestroy() {

View File

@ -371,6 +371,8 @@ import {
formatToken, formatTokenAmount, formatTokenDenom, getStakingValidatorOperator, percent, tokenFormatter, toDay,
toDuration, abbrMessage, abbrAddress, getUserCurrency, getUserCurrencySign,
} from '@/libs/utils'
import { sha256 } from '@cosmjs/crypto'
import { toHex } from '@cosmjs/encoding'
import ObjectFieldComponent from './ObjectFieldComponent.vue'
import OperationTransferComponent from './OperationTransferComponent.vue'
import OperationWithdrawComponent from './OperationWithdrawComponent.vue'
@ -560,7 +562,7 @@ export default {
re.push({
validator: getStakingValidatorOperator(this.$http.config.chain_name, e.delegation.validator_address, 8),
token: formatToken(e.balance, {}, 2),
reward: tokenFormatter(reward.reward),
reward: tokenFormatter(reward.reward, this.denoms),
action: e.delegation.validator_address,
})
})
@ -576,29 +578,23 @@ export default {
},
},
created() {
this.$http.getAllIBCDenoms().then(x => {
x.denom_traces.forEach(trace => {
const hash = toHex(sha256(new TextEncoder().encode(`${trace.path}/${trace.base_denom}`)))
this.$set(this.denoms, `ibc/${hash.toUpperCase()}`, trace.base_denom)
})
})
this.$http.getAuthAccount(this.address).then(acc => {
this.account = acc
})
this.$http.getBankAccountBalance(this.address).then(bal => {
this.assets = bal
bal.forEach(x => {
if (x.denom.startsWith('ibc/')) {
this.$http.getIBCDenomTrace(x.denom).then(denom => {
this.$set(this.denoms, x.denom, denom)
const symbol = formatTokenDenom(denom)
if (!this.quotes[symbol] && symbol.indexOf('/') === -1) {
chainAPI.fetchTokenQuote(symbol).then(quote => {
this.$set(this.quotes, symbol, quote)
})
}
const symbol = formatTokenDenom(x.denom)
if (!this.quotes[symbol] && symbol.indexOf('/') === -1) {
chainAPI.fetchTokenQuote(symbol).then(quote => {
this.$set(this.quotes, symbol, quote)
})
} else {
const symbol = formatTokenDenom(x.denom)
if (!this.quotes[symbol] && symbol.indexOf('/') === -1) {
chainAPI.fetchTokenQuote(symbol).then(quote => {
this.$set(this.quotes, symbol, quote)
})
}
}
})
})