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.dispatch('chains/getQuotes')
store.dispatch('chains/getAllIBCDenoms')
return {
skinClasses,
}
},
created() {
store.dispatch('chains/getQuotes')
store.dispatch('chains/getAllIBCDenoms', this)
},
}
</script>

View File

@ -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))
}

View File

@ -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)
})
},
},

View File

@ -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) {

View File

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

View File

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

View File

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

View File

@ -143,8 +143,6 @@ import {
import vSelect from 'vue-select'
import { coin } from '@cosmjs/amino'
import dayjs from 'dayjs'
import { toHex } from '@cosmjs/encoding'
import { sha256 } from '@cosmjs/crypto'
export default {
name: 'TransforDialogue',
@ -177,8 +175,6 @@ export default {
token: '',
amount: null,
recipient: null,
IBCDenom: {},
paths: {},
destination: {},
channels: [],
@ -228,6 +224,12 @@ export default {
selectedChain() {
return this.$store.state.chains.selected
},
IBCDenom() {
return this.$store.state.chains.denoms
},
paths() {
return this.$store.state.chains.ibcPaths
},
},
mounted() {
this.$emit('update', {
@ -244,23 +246,6 @@ export default {
this.token = ''
this.targetChainId = ''
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 => {
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)

View File

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

View File

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