cosmos-explorer/src/stores/useBankStore.ts

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-04-03 09:08:02 +00:00
import { defineStore } from "pinia";
import { useBlockchain } from "./useBlockchain";
import { useStakingStore } from "./useStakingStore";
2023-04-19 04:05:19 +00:00
import type { Coin, DenomTrace } from "@/types";
2023-04-03 09:08:02 +00:00
export const useBankStore = defineStore('bankstore', {
state: () => {
return {
2023-04-06 00:17:40 +00:00
supply: {} as Coin,
2023-04-03 09:08:02 +00:00
balances: {} as Record<string, Coin[]>,
2023-04-06 00:17:40 +00:00
totalSupply: {supply: [] as Coin[]} ,
2023-04-03 09:08:02 +00:00
}
},
getters: {
blockchain() {
return useBlockchain()
},
staking() {
return useStakingStore()
}
},
actions: {
initial() {
this.$reset()
this.supply = {} as Coin
2023-04-06 01:48:59 +00:00
const denom = this.staking.params.bond_denom || this.blockchain.current?.assets[0].base
2023-04-03 09:08:02 +00:00
if(denom) {
2023-04-06 00:17:40 +00:00
this.blockchain.rpc.getBankSupplyByDenom(denom).then(res => {
2023-04-03 09:08:02 +00:00
if(res.amount) this.supply = res.amount
})
}
},
async fetchSupply(denom: string) {
2023-04-06 00:17:40 +00:00
return this.blockchain.rpc.getBankSupplyByDenom( denom )
2023-04-19 04:05:19 +00:00
},
async fetchDenomTrace(denom: string) {
const hash = denom.replace("ibc/", "")
let trace = this.ibcDenoms[hash]
if(!trace) {
trace = (await this.blockchain.rpc.getIBCAppTransferDenom( hash )).denom_trace
this.ibcDenoms[hash] = trace
}
return trace
2023-04-03 09:08:02 +00:00
}
}
})