2023-05-06 14:56:04 +00:00
|
|
|
import { defineStore } from 'pinia';
|
2023-04-03 09:08:02 +00:00
|
|
|
|
2023-05-06 14:56:04 +00:00
|
|
|
import { useBlockchain } from './useBlockchain';
|
|
|
|
import { useStakingStore } from './useStakingStore';
|
|
|
|
import type { Coin, DenomTrace } from '@/types';
|
2023-04-03 09:08:02 +00:00
|
|
|
|
|
|
|
export const useBankStore = defineStore('bankstore', {
|
2023-05-06 14:56:04 +00:00
|
|
|
state: () => {
|
|
|
|
return {
|
|
|
|
supply: {} as Coin,
|
|
|
|
balances: {} as Record<string, Coin[]>,
|
|
|
|
totalSupply: { supply: [] as Coin[] },
|
2023-06-08 02:02:47 +00:00
|
|
|
ibcDenoms: {} as Record<string, DenomTrace>
|
2023-05-06 14:56:04 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
getters: {
|
|
|
|
blockchain() {
|
|
|
|
return useBlockchain();
|
2023-04-03 09:08:02 +00:00
|
|
|
},
|
2023-05-06 14:56:04 +00:00
|
|
|
staking() {
|
|
|
|
return useStakingStore();
|
2023-04-03 09:08:02 +00:00
|
|
|
},
|
2023-05-06 14:56:04 +00:00
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
initial() {
|
|
|
|
this.$reset();
|
|
|
|
this.supply = {} as Coin;
|
|
|
|
const denom =
|
|
|
|
this.staking.params.bond_denom ||
|
|
|
|
this.blockchain.current?.assets[0].base;
|
|
|
|
if (denom) {
|
|
|
|
this.blockchain.rpc.getBankSupplyByDenom(denom).then((res) => {
|
|
|
|
if (res.amount) this.supply = res.amount;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async fetchSupply(denom: string) {
|
|
|
|
return this.blockchain.rpc.getBankSupplyByDenom(denom);
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|