cosmos-explorer/src/stores/useWalletStore.ts

41 lines
1.1 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;
2023-05-10 03:12:06 +00:00
const connected = JSON.parse(localStorage.getItem(key) || '{}');
return connected;
2023-05-10 03:12:06 +00:00
},
currentAddress() {
if (!this.connectedWallet?.cosmosAddress) return '';
const { prefix, data } = fromBech32(this.connectedWallet.cosmosAddress);
const chainStore = useBlockchain();
return toBech32(chainStore.current?.bech32Prefix || prefix, data);
},
2023-05-10 03:12:06 +00:00
},
actions: {
myBalance() {
return this.blockchain.rpc.getBankBalances(this.currentAddress);
2023-05-10 03:12:06 +00:00
},
myDelegations() {
return this.blockchain.rpc.getStakingDelegations(this.currentAddress);
2023-05-10 03:12:06 +00:00
},
myUnbonding() {
return this.blockchain.rpc.getStakingDelegatorUnbonding(
this.currentAddress
);
},
2023-05-10 03:12:06 +00:00
},
2023-05-06 14:56:04 +00:00
});