From 01408d260702e4488f354e3df705f7f5fa470953 Mon Sep 17 00:00:00 2001 From: donne1226 <503124742@qq.com> Date: Tue, 5 Apr 2022 23:31:06 +0800 Subject: [PATCH] done save IBCDenoms to store --- src/App.vue | 7 ++--- src/libs/fetch.js | 3 ++- src/store/chains/index.js | 25 ++++++++++++++--- src/views/StakingRewardComponent.vue | 14 +++------- src/views/SummaryAssetsComponent.vue | 14 ++++------ src/views/WalletAccountDetail.vue | 12 +++------ .../OperationModal/components/Delegate.vue | 5 ++-- .../OperationModal/components/IBCTransfer.vue | 27 +++++-------------- .../OperationModal/components/Transfer.vue | 5 ++-- vue.config.js | 2 +- 10 files changed, 52 insertions(+), 62 deletions(-) diff --git a/src/App.vue b/src/App.vue index b67b9ca9..3b67e952 100644 --- a/src/App.vue +++ b/src/App.vue @@ -92,12 +92,13 @@ export default { store.commit('app/UPDATE_WINDOW_WIDTH', val) }) - store.dispatch('chains/getQuotes') - store.dispatch('chains/getAllIBCDenoms') - return { skinClasses, } }, + created() { + store.dispatch('chains/getQuotes') + store.dispatch('chains/getAllIBCDenoms', this) + }, } diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 8ea2bfa2..410f5ad7 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -325,7 +325,8 @@ export default class ChainFetch { } async getAllIBCDenoms(config = null) { - const sdkVersion = config ? config.sdk_version : this.config.sdk_version + const conf = config || this.getSelectedConfig() + const sdkVersion = conf.sdk_version if (compareVersions(sdkVersion, '0.44.2') < 0) { return this.get('/ibc/applications/transfer/v1beta1/denom_traces?pagination.limit=500', config).then(data => commonProcess(data)) } diff --git a/src/store/chains/index.js b/src/store/chains/index.js index a1d22667..5789fd11 100644 --- a/src/store/chains/index.js +++ b/src/store/chains/index.js @@ -8,6 +8,9 @@ import { isTestnet } from '@/libs/utils' import { sha256 } from '@cosmjs/crypto' import { toHex } from '@cosmjs/encoding' +import Vue from 'vue' + +console.log(Vue.prototype) let chains = {} @@ -39,6 +42,7 @@ export default { quotes: {}, defaultWallet: localStorage.getItem('default-wallet'), denoms: {}, + ibcPaths: {}, }, getters: { getchains: state => state.chains, @@ -73,6 +77,9 @@ export default { setIBCDenoms(state, denoms) { state.denoms = denoms }, + setIBCPaths(state, paths) { + state.ibcPaths = paths + }, }, actions: { async getQuotes(context) { @@ -81,15 +88,25 @@ export default { }) }, - async getAllIBCDenoms(context) { - this.$http.getAllIBCDenoms().then(x => { + async getAllIBCDenoms(context, _this) { + _this.$http.getAllIBCDenoms().then(x => { const denomsMap = {} + const pathsMap = {} x.denom_traces.forEach(trace => { const hash = toHex(sha256(new TextEncoder().encode(`${trace.path}/${trace.base_denom}`))) - denomsMap[`ibc/${hash.toUpperCase()}`] = trace.base_denom - // this.$set(this.denoms, `ibc/${hash.toUpperCase()}`, trace.base_denom) + const ibcDenom = `ibc/${hash.toUpperCase()}` + denomsMap[ibcDenom] = trace.base_denom + + const path = trace.path.split('/') + if (path.length >= 2) { + pathsMap[ibcDenom] = { + channel_id: path[path.length - 1], + port_id: path[path.length - 2], + } + } }) context.commit('setIBCDenoms', denomsMap) + context.commit('setIBCPaths', pathsMap) }) }, }, diff --git a/src/views/StakingRewardComponent.vue b/src/views/StakingRewardComponent.vue index e90bba72..65d10152 100644 --- a/src/views/StakingRewardComponent.vue +++ b/src/views/StakingRewardComponent.vue @@ -97,8 +97,6 @@ import { BCard, BCardHeader, BCardTitle, BCardBody, BMediaBody, BMedia, BMediaAside, BAvatar, BButton, } from 'bootstrap-vue' -import { sha256 } from '@cosmjs/crypto' -import { toHex } from '@cosmjs/encoding' import { formatToken, numberWithCommas } from '@/libs/utils' import OperationModal from '@/views/components/OperationModal/index.vue' @@ -131,16 +129,12 @@ 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) - }) - }) + computed: { + denoms() { + return this.$store.state.chains.denoms + }, }, methods: { formatNumber(value) { diff --git a/src/views/SummaryAssetsComponent.vue b/src/views/SummaryAssetsComponent.vue index b5b4e613..b605064a 100644 --- a/src/views/SummaryAssetsComponent.vue +++ b/src/views/SummaryAssetsComponent.vue @@ -15,8 +15,6 @@