From e011ec06917fbf700f689ac45ff40b974b6724cf Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Wed, 10 May 2023 11:12:06 +0800 Subject: [PATCH] add basic framework --- src/layouts/components/DefaultLayout.vue | 3 ++- src/layouts/components/NavBarWallet.vue | 14 +++++++++++ src/modules/[chain]/index.vue | 28 ++++++++++++++++----- src/stores/useBlockchain.ts | 8 ++++++ src/stores/useDashboard.ts | 2 ++ src/stores/useWalletStore.ts | 32 ++++++++++++++++++++++-- 6 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 src/layouts/components/NavBarWallet.vue diff --git a/src/layouts/components/DefaultLayout.vue b/src/layouts/components/DefaultLayout.vue index a0bf2b9c..25a16b95 100644 --- a/src/layouts/components/DefaultLayout.vue +++ b/src/layouts/components/DefaultLayout.vue @@ -15,6 +15,7 @@ import { VerticalNavLayout } from '@layouts'; import NavBarI18n from './NavBarI18n.vue'; import NavSearchBar from './NavSearchBar.vue'; import NavBarNotifications from './NavBarNotifications.vue'; +import NavBarWallet from './NavBarWallet.vue'; import TheCustomizer from '@/plugins/vuetify/@core/components/TheCustomizer.vue'; import Breadcrumbs from './Breadcrumbs.vue'; import { useBlockchain } from '@/stores'; @@ -68,7 +69,7 @@ blockchain.$subscribe((m, s) => { - + diff --git a/src/layouts/components/NavBarWallet.vue b/src/layouts/components/NavBarWallet.vue new file mode 100644 index 00000000..55aeaf47 --- /dev/null +++ b/src/layouts/components/NavBarWallet.vue @@ -0,0 +1,14 @@ + + + + + {{ walletStore.currentAddress }} + + + diff --git a/src/modules/[chain]/index.vue b/src/modules/[chain]/index.vue index c8ccb7e4..4e8d09f0 100644 --- a/src/modules/[chain]/index.vue +++ b/src/modules/[chain]/index.vue @@ -3,7 +3,7 @@ import MdEditor from 'md-editor-v3'; import PriceMarketChart from '@/components/charts/PriceMarketChart.vue'; import { Icon } from '@iconify/vue'; -import { useBlockchain, useFormatter } from '@/stores'; +import { useBlockchain, useFormatter, useWalletStore } from '@/stores'; import { onMounted, ref } from 'vue'; import { useIndexModule } from './indexStore'; import { computed } from '@vue/reactivity'; @@ -13,6 +13,7 @@ import ProposalListItem from '@/components/ProposalListItem.vue'; const blockchain = useBlockchain(); const store = useIndexModule(); +const walletStore = useWalletStore() const coinInfo = computed(() => { return store.coinInfo; @@ -62,6 +63,9 @@ const comLinks = [ href: store.github, }, ]; + +// wallet box + @@ -216,12 +220,24 @@ const comLinks = [ - - - Connect Wallet + + + {{ walletStore.currentAddress || "Not Connected" }} + More + + + 1 + 2 + 1 + 2 + + + + + + + diff --git a/src/stores/useBlockchain.ts b/src/stores/useBlockchain.ts index e41dbe80..b035d296 100644 --- a/src/stores/useBlockchain.ts +++ b/src/stores/useBlockchain.ts @@ -39,6 +39,14 @@ export const useBlockchain = defineStore('blockchain', { logo(): string { return this.current?.logo || ''; }, + defaultHDPath(): string { + const cointype = this.current?.coinType || "118" + // if(cointype === "60") { + // return `m/44'/${cointype}` + // } + // return `m/44'/${cointype}/0'/0/0` + return "connected-wallet" + }, dashboard() { return useDashboard(); }, diff --git a/src/stores/useDashboard.ts b/src/stores/useDashboard.ts index f92bf576..1347c49e 100644 --- a/src/stores/useDashboard.ts +++ b/src/stores/useDashboard.ts @@ -58,6 +58,7 @@ export interface ChainConfig { prettyName: string; bech32Prefix: string; chainId: string; + coinType: string; assets: Asset[]; themeColor?: string; endpoints: { @@ -127,6 +128,7 @@ export function fromLocal(lc: LocalConfig): ChainConfig { })); conf.bech32Prefix = lc.addr_prefix; conf.chainName = lc.chain_name; + conf.coinType = lc.coin_type; conf.prettyName = lc.chain_name; conf.endpoints = { rest: apiConverter(lc.api), diff --git a/src/stores/useWalletStore.ts b/src/stores/useWalletStore.ts index acc74820..c8d54718 100644 --- a/src/stores/useWalletStore.ts +++ b/src/stores/useWalletStore.ts @@ -1,9 +1,37 @@ import { defineStore } from 'pinia'; +import { useBlockchain } from './useBlockchain'; +import { fromBech32, toBech32 } from '@cosmjs/encoding'; export const useWalletStore = defineStore('walletStore', { state: () => { return {}; }, - getters: {}, - actions: {}, + 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) + } + }, });