feat: wallet connect state

This commit is contained in:
Alisa | Side.one 2023-05-16 00:29:53 +08:00
parent d148bbe3b1
commit e8f2e03925
6 changed files with 59 additions and 25 deletions

View File

@ -40,7 +40,7 @@
"md-editor-v3": "^2.8.1", "md-editor-v3": "^2.8.1",
"numeral": "^2.0.6", "numeral": "^2.0.6",
"osmojs": "^14.0.0-rc.0", "osmojs": "^14.0.0-rc.0",
"ping-widget": "^0.0.8", "ping-widget": "^0.0.9",
"pinia": "^2.0.28", "pinia": "^2.0.28",
"postcss": "^8.4.23", "postcss": "^8.4.23",
"prismjs": "^1.29.0", "prismjs": "^1.29.0",

View File

@ -25,6 +25,12 @@ const tipMsg = computed(() => {
? { class: 'error', msg: 'Copy Error!' } ? { class: 'error', msg: 'Copy Error!' }
: { class: 'success', msg: 'Copy Success!' }; : { class: 'success', msg: 'Copy Success!' };
}); });
const addressChange = computed(() => {
return walletStore?.currentAddress || walletStore?.walletIsConnected
? true
: false;
});
</script> </script>
<template> <template>

View File

@ -1,3 +1,11 @@
<script setup lang="ts">
import { useWalletStore } from '@/stores';
const walletStore = useWalletStore();
function walletStateChange(res:any){
console.log(res.detail?.value, 8888888)
walletStore.setConnectedWallet(res.detail?.value)
}
</script>
<template> <template>
<footer class="footer items-center p-4 text-sm mb-4"> <footer class="footer items-center p-4 text-sm mb-4">
<div class="items-center grid-flow-col"> <div class="items-center grid-flow-col">
@ -32,7 +40,7 @@
</div> </div>
</footer> </footer>
<div class="footer-modal"> <div class="footer-modal">
<ping-connect-wallet :chain-id="'juno-1'" :hd-path="`m/44'/118/0'/0/0`" /> <ping-connect-wallet :chain-id="'juno-1'" :hd-path="`m/44'/118/0'/0/0`" @change="walletStateChange"/>
</div> </div>
</template> </template>

View File

@ -6,6 +6,7 @@ import type {
Coin, Coin,
UnbondingResponses, UnbondingResponses,
DelegatorRewards, DelegatorRewards,
WalletConnected,
} from '@/types'; } from '@/types';
import { useStakingStore } from './useStakingStore'; import { useStakingStore } from './useStakingStore';
@ -16,6 +17,7 @@ export const useWalletStore = defineStore('walletStore', {
delegations: [] as Delegation[], delegations: [] as Delegation[],
unbonding: [] as UnbondingResponses[], unbonding: [] as UnbondingResponses[],
rewards: {} as DelegatorRewards, rewards: {} as DelegatorRewards,
walletIsConnected: {} as WalletConnected | null
}; };
}, },
getters: { getters: {
@ -25,9 +27,11 @@ export const useWalletStore = defineStore('walletStore', {
connectedWallet() { connectedWallet() {
const chainStore = useBlockchain(); const chainStore = useBlockchain();
const key = chainStore.defaultHDPath; const key = chainStore.defaultHDPath;
let connected = this.walletIsConnected
const connected = JSON.parse(localStorage.getItem(key) || '{}'); if (!this.walletIsConnected?.cosmosAddress){
return connected; connected = JSON.parse(localStorage.getItem(key) || '{}');
}
return connected
}, },
balanceOfStakingToken(): Coin { balanceOfStakingToken(): Coin {
const stakingStore = useStakingStore(); const stakingStore = useStakingStore();
@ -80,6 +84,7 @@ export const useWalletStore = defineStore('walletStore', {
} }
}, },
actions: { actions: {
async loadMyAsset() { async loadMyAsset() {
if (!this.currentAddress) return; if (!this.currentAddress) return;
this.blockchain.rpc.getBankBalances(this.currentAddress).then((x) => { this.blockchain.rpc.getBankBalances(this.currentAddress).then((x) => {
@ -115,9 +120,18 @@ export const useWalletStore = defineStore('walletStore', {
disconnect() { disconnect() {
const chainStore = useBlockchain(); const chainStore = useBlockchain();
const key = chainStore.defaultHDPath; const key = chainStore.defaultHDPath;
console.log(key, 'key')
console.log(localStorage.getItem(key))
localStorage.removeItem(key); localStorage.removeItem(key);
this.walletIsConnected = null
this.$reset() this.$reset()
},
setConnectedWallet(value: any) {
const chainStore = useBlockchain();
const key = chainStore.defaultHDPath;
this.walletIsConnected = value || {}
// JSON.parse(localStorage.getItem(key) || '{}');
return this.walletIsConnected
} }
}, },
}); });

View File

@ -1,22 +1,28 @@
import type { Coin, PaginatedResponse } from "./common" import type { Coin, PaginatedResponse } from './common';
export interface DistributionParams { export interface DistributionParams {
params: { params: {
"community_tax": string, community_tax: string;
"base_proposer_reward": string, base_proposer_reward: string;
"bonus_proposer_reward": string, bonus_proposer_reward: string;
"withdraw_addr_enabled": boolean withdraw_addr_enabled: boolean;
} };
} }
export interface DelegatorRewards { export interface DelegatorRewards {
rewards: { rewards: {
validator_address: string, validator_address: string;
reward: Coin[], reward: Coin[];
}[], }[];
total: Coin[], total: Coin[];
} }
export interface PaginatedSlashes extends PaginatedResponse { export interface PaginatedSlashes extends PaginatedResponse {
slashes: any[] slashes: any[];
}
export interface WalletConnected {
wallet: string;
cosmosAddress: string;
hdPath: string;
} }

View File

@ -6736,10 +6736,10 @@ pify@^3.0.0:
resolved "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz" resolved "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz"
integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg== integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==
ping-widget@^0.0.8: ping-widget@^0.0.9:
version "0.0.8" version "0.0.9"
resolved "https://registry.yarnpkg.com/ping-widget/-/ping-widget-0.0.8.tgz#378ef1f3ac59645921a98920ebe83cc74c42e6db" resolved "https://registry.yarnpkg.com/ping-widget/-/ping-widget-0.0.9.tgz#56de5ee68320a37aadda614008d8c42c4cac39a0"
integrity sha512-NAFB6n+jJhjk4Xp8LCtRFzPOZdkKhecAKFg0Rimi0yilXL6EBRWJB+09zH89sjHcnUyhW6B2vSg42DpT8n3Rpw== integrity sha512-HXfH58FBCbuDMD56X1Wsxi4jKRWxWK7TsKYfGcDJPGOFQOreT2WDc6wEZr1pfG5Mjr4SOVJz84xR4S5SptXJqA==
dependencies: dependencies:
"@cosmjs/amino" "^0.30.1" "@cosmjs/amino" "^0.30.1"
"@cosmjs/ledger-amino" "^0.30.1" "@cosmjs/ledger-amino" "^0.30.1"