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",
"numeral": "^2.0.6",
"osmojs": "^14.0.0-rc.0",
"ping-widget": "^0.0.8",
"ping-widget": "^0.0.9",
"pinia": "^2.0.28",
"postcss": "^8.4.23",
"prismjs": "^1.29.0",

View File

@ -25,6 +25,12 @@ const tipMsg = computed(() => {
? { class: 'error', msg: 'Copy Error!' }
: { class: 'success', msg: 'Copy Success!' };
});
const addressChange = computed(() => {
return walletStore?.currentAddress || walletStore?.walletIsConnected
? true
: false;
});
</script>
<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>
<footer class="footer items-center p-4 text-sm mb-4">
<div class="items-center grid-flow-col">
@ -32,7 +40,7 @@
</div>
</footer>
<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>
</template>

View File

@ -6,6 +6,7 @@ import type {
Coin,
UnbondingResponses,
DelegatorRewards,
WalletConnected,
} from '@/types';
import { useStakingStore } from './useStakingStore';
@ -16,6 +17,7 @@ export const useWalletStore = defineStore('walletStore', {
delegations: [] as Delegation[],
unbonding: [] as UnbondingResponses[],
rewards: {} as DelegatorRewards,
walletIsConnected: {} as WalletConnected | null
};
},
getters: {
@ -25,9 +27,11 @@ export const useWalletStore = defineStore('walletStore', {
connectedWallet() {
const chainStore = useBlockchain();
const key = chainStore.defaultHDPath;
const connected = JSON.parse(localStorage.getItem(key) || '{}');
return connected;
let connected = this.walletIsConnected
if (!this.walletIsConnected?.cosmosAddress){
connected = JSON.parse(localStorage.getItem(key) || '{}');
}
return connected
},
balanceOfStakingToken(): Coin {
const stakingStore = useStakingStore();
@ -80,6 +84,7 @@ export const useWalletStore = defineStore('walletStore', {
}
},
actions: {
async loadMyAsset() {
if (!this.currentAddress) return;
this.blockchain.rpc.getBankBalances(this.currentAddress).then((x) => {
@ -115,9 +120,18 @@ export const useWalletStore = defineStore('walletStore', {
disconnect() {
const chainStore = useBlockchain();
const key = chainStore.defaultHDPath;
console.log(key, 'key')
console.log(localStorage.getItem(key))
localStorage.removeItem(key);
this.walletIsConnected = null
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 {
params: {
"community_tax": string,
"base_proposer_reward": string,
"bonus_proposer_reward": string,
"withdraw_addr_enabled": boolean
}
params: {
community_tax: string;
base_proposer_reward: string;
bonus_proposer_reward: string;
withdraw_addr_enabled: boolean;
};
}
export interface DelegatorRewards {
rewards: {
validator_address: string,
reward: Coin[],
}[],
total: Coin[],
rewards: {
validator_address: string;
reward: Coin[];
}[];
total: Coin[];
}
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"
integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==
ping-widget@^0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/ping-widget/-/ping-widget-0.0.8.tgz#378ef1f3ac59645921a98920ebe83cc74c42e6db"
integrity sha512-NAFB6n+jJhjk4Xp8LCtRFzPOZdkKhecAKFg0Rimi0yilXL6EBRWJB+09zH89sjHcnUyhW6B2vSg42DpT8n3Rpw==
ping-widget@^0.0.9:
version "0.0.9"
resolved "https://registry.yarnpkg.com/ping-widget/-/ping-widget-0.0.9.tgz#56de5ee68320a37aadda614008d8c42c4cac39a0"
integrity sha512-HXfH58FBCbuDMD56X1Wsxi4jKRWxWK7TsKYfGcDJPGOFQOreT2WDc6wEZr1pfG5Mjr4SOVJz84xR4S5SptXJqA==
dependencies:
"@cosmjs/amino" "^0.30.1"
"@cosmjs/ledger-amino" "^0.30.1"