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() {
|
2023-05-10 05:23:00 +00:00
|
|
|
const chainStore = useBlockchain();
|
|
|
|
const key = chainStore.defaultHDPath;
|
2023-05-10 03:12:06 +00:00
|
|
|
|
2023-05-10 05:23:00 +00:00
|
|
|
const connected = JSON.parse(localStorage.getItem(key) || '{}');
|
|
|
|
return connected;
|
2023-05-10 03:12:06 +00:00
|
|
|
},
|
|
|
|
currentAddress() {
|
2023-05-10 05:23:00 +00:00
|
|
|
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() {
|
2023-05-10 05:23:00 +00:00
|
|
|
return this.blockchain.rpc.getBankBalances(this.currentAddress);
|
2023-05-10 03:12:06 +00:00
|
|
|
},
|
|
|
|
myDelegations() {
|
2023-05-10 05:23:00 +00:00
|
|
|
return this.blockchain.rpc.getStakingDelegations(this.currentAddress);
|
2023-05-10 03:12:06 +00:00
|
|
|
},
|
|
|
|
myUnbonding() {
|
2023-05-10 05:23:00 +00:00
|
|
|
return this.blockchain.rpc.getStakingDelegatorUnbonding(
|
|
|
|
this.currentAddress
|
|
|
|
);
|
|
|
|
},
|
2023-05-10 03:12:06 +00:00
|
|
|
},
|
2023-05-06 14:56:04 +00:00
|
|
|
});
|