cosmos-explorer/src/stores/useWalletStore.ts

38 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-05-06 14:56:04 +00:00
import { defineStore } from 'pinia';
2023-05-10 03:12:06 +00:00
import { useBlockchain } from './useBlockchain';
import { fromBech32, toBech32 } from '@cosmjs/encoding';
2023-04-30 03:47:39 +00:00
export const useWalletStore = defineStore('walletStore', {
2023-05-06 14:56:04 +00:00
state: () => {
return {};
},
2023-05-10 03:12:06 +00:00
getters: {
blockchain() {
return useBlockchain();
},
connectedWallet() {
const chainStore = useBlockchain()
const key = chainStore.defaultHDPath
const connected = JSON.parse(localStorage.getItem(key)||"{}")
return connected
},
currentAddress() {
const {prefix, data} = fromBech32(this.connectedWallet.cosmosAddress);
const chainStore = useBlockchain()
return toBech32(chainStore.current?.bech32Prefix || prefix, data)
}
},
actions: {
myBalance() {
return this.blockchain.rpc.getBankBalances(this.currentAddress)
},
myDelegations() {
return this.blockchain.rpc.getStakingDelegations(this.currentAddress)
},
myUnbonding() {
return this.blockchain.rpc.getStakingDelegatorUnbonding(this.currentAddress)
}
},
2023-05-06 14:56:04 +00:00
});