done save IBCDenoms to store

This commit is contained in:
donne1226 2022-04-05 23:31:06 +08:00
parent ccc4811fa5
commit 01408d2607
10 changed files with 52 additions and 62 deletions

View File

@ -92,12 +92,13 @@ export default {
store.commit('app/UPDATE_WINDOW_WIDTH', val) store.commit('app/UPDATE_WINDOW_WIDTH', val)
}) })
store.dispatch('chains/getQuotes')
store.dispatch('chains/getAllIBCDenoms')
return { return {
skinClasses, skinClasses,
} }
}, },
created() {
store.dispatch('chains/getQuotes')
store.dispatch('chains/getAllIBCDenoms', this)
},
} }
</script> </script>

View File

@ -325,7 +325,8 @@ export default class ChainFetch {
} }
async getAllIBCDenoms(config = null) { 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) { if (compareVersions(sdkVersion, '0.44.2') < 0) {
return this.get('/ibc/applications/transfer/v1beta1/denom_traces?pagination.limit=500', config).then(data => commonProcess(data)) return this.get('/ibc/applications/transfer/v1beta1/denom_traces?pagination.limit=500', config).then(data => commonProcess(data))
} }

View File

@ -8,6 +8,9 @@
import { isTestnet } from '@/libs/utils' import { isTestnet } from '@/libs/utils'
import { sha256 } from '@cosmjs/crypto' import { sha256 } from '@cosmjs/crypto'
import { toHex } from '@cosmjs/encoding' import { toHex } from '@cosmjs/encoding'
import Vue from 'vue'
console.log(Vue.prototype)
let chains = {} let chains = {}
@ -39,6 +42,7 @@ export default {
quotes: {}, quotes: {},
defaultWallet: localStorage.getItem('default-wallet'), defaultWallet: localStorage.getItem('default-wallet'),
denoms: {}, denoms: {},
ibcPaths: {},
}, },
getters: { getters: {
getchains: state => state.chains, getchains: state => state.chains,
@ -73,6 +77,9 @@ export default {
setIBCDenoms(state, denoms) { setIBCDenoms(state, denoms) {
state.denoms = denoms state.denoms = denoms
}, },
setIBCPaths(state, paths) {
state.ibcPaths = paths
},
}, },
actions: { actions: {
async getQuotes(context) { async getQuotes(context) {
@ -81,15 +88,25 @@ export default {
}) })
}, },
async getAllIBCDenoms(context) { async getAllIBCDenoms(context, _this) {
this.$http.getAllIBCDenoms().then(x => { _this.$http.getAllIBCDenoms().then(x => {
const denomsMap = {} const denomsMap = {}
const pathsMap = {}
x.denom_traces.forEach(trace => { x.denom_traces.forEach(trace => {
const hash = toHex(sha256(new TextEncoder().encode(`${trace.path}/${trace.base_denom}`))) const hash = toHex(sha256(new TextEncoder().encode(`${trace.path}/${trace.base_denom}`)))
denomsMap[`ibc/${hash.toUpperCase()}`] = trace.base_denom const ibcDenom = `ibc/${hash.toUpperCase()}`
// this.$set(this.denoms, `ibc/${hash.toUpperCase()}`, trace.base_denom) 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('setIBCDenoms', denomsMap)
context.commit('setIBCPaths', pathsMap)
}) })
}, },
}, },

View File

@ -97,8 +97,6 @@
import { import {
BCard, BCardHeader, BCardTitle, BCardBody, BMediaBody, BMedia, BMediaAside, BAvatar, BButton, BCard, BCardHeader, BCardTitle, BCardBody, BMediaBody, BMedia, BMediaAside, BAvatar, BButton,
} from 'bootstrap-vue' } from 'bootstrap-vue'
import { sha256 } from '@cosmjs/crypto'
import { toHex } from '@cosmjs/encoding'
import { formatToken, numberWithCommas } from '@/libs/utils' import { formatToken, numberWithCommas } from '@/libs/utils'
import OperationModal from '@/views/components/OperationModal/index.vue' import OperationModal from '@/views/components/OperationModal/index.vue'
@ -131,16 +129,12 @@ export default {
}, },
data() { data() {
return { return {
denoms: {},
} }
}, },
created() { computed: {
this.$http.getAllIBCDenoms().then(x => { denoms() {
x.denom_traces.forEach(trace => { return this.$store.state.chains.denoms
const hash = toHex(sha256(new TextEncoder().encode(`${trace.path}/${trace.base_denom}`))) },
this.$set(this.denoms, `ibc/${hash.toUpperCase()}`, trace.base_denom)
})
})
}, },
methods: { methods: {
formatNumber(value) { formatNumber(value) {

View File

@ -15,8 +15,6 @@
</template> </template>
<script> <script>
import { sha256 } from '@cosmjs/crypto'
import { toHex } from '@cosmjs/encoding'
import { BTable, BCardTitle, BCard } from 'bootstrap-vue' import { BTable, BCardTitle, BCard } from 'bootstrap-vue'
import { formatTokenAmount, formatTokenDenom } from '@/libs/utils' import { formatTokenAmount, formatTokenDenom } from '@/libs/utils'
@ -30,7 +28,6 @@ export default {
return { return {
islive: true, islive: true,
assets: [], assets: [],
denoms: {},
cfield: [ cfield: [
{ {
key: 'denom', key: 'denom',
@ -44,13 +41,12 @@ export default {
], ],
} }
}, },
computed: {
denoms() {
return this.$store.state.chains.denoms
},
},
created() { 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)
})
})
this.$http.getBankTotals().then(res => { this.$http.getBankTotals().then(res => {
const toshow = res.sort() const toshow = res.sort()
this.assets = toshow.reverse().map(x => { this.assets = toshow.reverse().map(x => {

View File

@ -402,8 +402,6 @@ import {
formatToken, formatTokenAmount, formatTokenDenom, getStakingValidatorOperator, percent, tokenFormatter, toDay, formatToken, formatTokenAmount, formatTokenDenom, getStakingValidatorOperator, percent, tokenFormatter, toDay,
toDuration, abbrMessage, abbrAddress, getUserCurrency, getUserCurrencySign, numberWithCommas, toDuration, abbrMessage, abbrAddress, getUserCurrency, getUserCurrencySign, numberWithCommas,
} from '@/libs/utils' } from '@/libs/utils'
import { sha256 } from '@cosmjs/crypto'
import { toHex } from '@cosmjs/encoding'
import OperationModal from '@/views/components/OperationModal/index.vue' import OperationModal from '@/views/components/OperationModal/index.vue'
import ObjectFieldComponent from './ObjectFieldComponent.vue' import ObjectFieldComponent from './ObjectFieldComponent.vue'
import ChartComponentDoughnut from './ChartComponentDoughnut.vue' import ChartComponentDoughnut from './ChartComponentDoughnut.vue'
@ -448,7 +446,6 @@ export default {
address, address,
account: null, account: null,
assets: [], assets: [],
denoms: {},
reward: [], reward: [],
delegations: [], delegations: [],
redelegations: [], redelegations: [],
@ -600,14 +597,11 @@ export default {
} }
return table return table
}, },
denoms() {
return this.$store.state.chains.denoms
},
}, },
created() { 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.$http.getAuthAccount(this.address).then(acc => {
this.account = acc this.account = acc
}) })

View File

@ -155,8 +155,6 @@ export default {
token: '', token: '',
amount: null, amount: null,
selectedChain: '', selectedChain: '',
IBCDenom: {},
required, required,
password, password,
email, email,
@ -201,6 +199,9 @@ export default {
}, },
}] }]
}, },
IBCDenom() {
return this.$store.state.chains.denoms
},
}, },
mounted() { mounted() {
this.$emit('update', { this.$emit('update', {

View File

@ -143,8 +143,6 @@ import {
import vSelect from 'vue-select' import vSelect from 'vue-select'
import { coin } from '@cosmjs/amino' import { coin } from '@cosmjs/amino'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { toHex } from '@cosmjs/encoding'
import { sha256 } from '@cosmjs/crypto'
export default { export default {
name: 'TransforDialogue', name: 'TransforDialogue',
@ -177,8 +175,6 @@ export default {
token: '', token: '',
amount: null, amount: null,
recipient: null, recipient: null,
IBCDenom: {},
paths: {},
destination: {}, destination: {},
channels: [], channels: [],
@ -228,6 +224,12 @@ export default {
selectedChain() { selectedChain() {
return this.$store.state.chains.selected return this.$store.state.chains.selected
}, },
IBCDenom() {
return this.$store.state.chains.denoms
},
paths() {
return this.$store.state.chains.ibcPaths
},
}, },
mounted() { mounted() {
this.$emit('update', { this.$emit('update', {
@ -244,23 +246,6 @@ export default {
this.token = '' this.token = ''
this.targetChainId = '' this.targetChainId = ''
if (this.address) { if (this.address) {
this.$http.getAllIBCDenoms(this.selectedChain).then(x => {
x.denom_traces.forEach(trace => {
const hash = toHex(sha256(new TextEncoder().encode(`${trace.path}/${trace.base_denom}`)))
const ibcDenom = `ibc/${hash.toUpperCase()}`
// add base_denom to cache
this.$set(this.IBCDenom, ibcDenom, trace.base_denom)
// store channel/part for ibc denoms
const path = trace.path.split('/')
if (path.length >= 2) {
this.paths[ibcDenom] = {
channel_id: path[path.length - 1],
port_id: path[path.length - 2],
}
}
})
})
this.$http.getIBCChannels(this.selectedChain, null).then(ret => { this.$http.getIBCChannels(this.selectedChain, null).then(ret => {
const chans = ret.channels.filter(x => x.state === 'STATE_OPEN').map(x => ({ channel_id: x.channel_id, port_id: x.port_id })) const chans = ret.channels.filter(x => x.state === 'STATE_OPEN').map(x => ({ channel_id: x.channel_id, port_id: x.port_id }))
this.$set(this, 'channels', chans) this.$set(this, 'channels', chans)

View File

@ -139,8 +139,6 @@ export default {
token: '', token: '',
amount: null, amount: null,
recipient: '', recipient: '',
IBCDenom: {},
required, required,
password, password,
email, email,
@ -175,6 +173,9 @@ export default {
balanceOptions() { balanceOptions() {
return this.setupBalance() return this.setupBalance()
}, },
IBCDenom() {
return this.$store.state.chains.denoms
},
}, },
mounted() { mounted() {
this.$emit('update', { this.$emit('update', {

View File

@ -27,7 +27,7 @@ module.exports = {
}, },
plugins: [ plugins: [
new BundleAnalyzerPlugin({ new BundleAnalyzerPlugin({
analyzerMode: 'static', analyzerMode: 'disabled',
openAnalyzer: false, openAnalyzer: false,
}), }),
new CompressionWebpackPlugin({ new CompressionWebpackPlugin({