From f48c9b8a79880097ca1f9208c0daba7df5d685e6 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Sun, 14 May 2023 14:23:49 +0800 Subject: [PATCH 1/3] update client --- src/libs/client.ts | 4 ++-- src/stores/useBlockchain.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/client.ts b/src/libs/client.ts index 391af7b3..d6ffe9f8 100644 --- a/src/libs/client.ts +++ b/src/libs/client.ts @@ -26,8 +26,8 @@ export class BaseRestClient { } export class CosmosRestClient extends BaseRestClient { - constructor(endpoint: string) { - super(endpoint, DEFAULT) + static newDefault(endpoint: string) { + return new CosmosRestClient(endpoint, DEFAULT) } // Auth Module async getAuthAccounts() { diff --git a/src/stores/useBlockchain.ts b/src/stores/useBlockchain.ts index 84f4bca0..9e11c3c8 100644 --- a/src/stores/useBlockchain.ts +++ b/src/stores/useBlockchain.ts @@ -44,8 +44,8 @@ export const useBlockchain = defineStore('blockchain', { // if(cointype === "60") { // return `m/44'/${cointype}` // } - // return `m/44'/${cointype}/0'/0/0` - return "connected-wallet" + return `m/44'/${cointype}/0'/0/0` + //return "connected-wallet" }, dashboard() { return useDashboard(); From ef747b2e22d8b1ba96b0445f2184db69fe403415 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Sun, 14 May 2023 14:24:07 +0800 Subject: [PATCH 2/3] fix gov proposal loading issue --- src/modules/[chain]/indexStore.ts | 14 +++++++++----- src/stores/useGovStore.ts | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/modules/[chain]/indexStore.ts b/src/modules/[chain]/indexStore.ts index 003878e3..964f36d7 100644 --- a/src/modules/[chain]/indexStore.ts +++ b/src/modules/[chain]/indexStore.ts @@ -72,7 +72,6 @@ export const useIndexModule = defineStore('module-index', { total_volumes: [] as number[], }, communityPool: [] as { amount: string; denom: string }[], - proposals: {} as PaginatedProposals, tally: {} as Record, }; }, @@ -130,6 +129,11 @@ export const useIndexModule = defineStore('module-index', { return staking.pool; }, + proposals() { + const gov = useGovStore() + return gov.proposals['2'] + }, + stats() { const base = useBaseStore(); const bank = useBankStore(); @@ -205,10 +209,10 @@ export const useIndexModule = defineStore('module-index', { denom: t.denom, })); }); - const gov = useGovStore(); - gov.fetchProposals('2').then((x) => { - this.proposals = x; - }); + // const gov = useGovStore(); + // gov.fetchProposals('2').then((x) => { + // this.proposals = x; + // }); }, tickerColor(color: string) { return colorMap(color); diff --git a/src/stores/useGovStore.ts b/src/stores/useGovStore.ts index 056fdaf3..0234a1c7 100644 --- a/src/stores/useGovStore.ts +++ b/src/stores/useGovStore.ts @@ -23,7 +23,9 @@ export const useGovStore = defineStore('govStore', { }, actions: { initial() { + this.$reset() this.fetchParams(); + this.fetchProposals("2"); }, async fetchProposals(status: string, pagination?: PageRequest) { if (!this.loading[status]) { From d956fdd9c794bc00b82dc00f8504fd66b53452f0 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Mon, 15 May 2023 12:29:10 +0800 Subject: [PATCH 3/3] finish accounts --- src/layouts/components/ChainProfile.vue | 15 +- src/modules/wallet/accounts.vue | 281 +++++++++++++++++++++++- src/modules/wallet/portfolio.vue | 87 ++++++++ src/modules/wallet/portfollio.vue | 15 -- src/modules/wallet/utils.ts | 49 +++++ src/stores/useFormatter.ts | 41 +++- 6 files changed, 456 insertions(+), 32 deletions(-) create mode 100644 src/modules/wallet/portfolio.vue delete mode 100644 src/modules/wallet/portfollio.vue create mode 100644 src/modules/wallet/utils.ts diff --git a/src/layouts/components/ChainProfile.vue b/src/layouts/components/ChainProfile.vue index b1049d80..b9d4628d 100644 --- a/src/layouts/components/ChainProfile.vue +++ b/src/layouts/components/ChainProfile.vue @@ -83,13 +83,15 @@ chainStore.$subscribe((m, s) => {
-
+
#{{ baseStore.latest?.block?.header?.height || chainStore.chainName || '' }}
+
+ diff --git a/src/modules/wallet/accounts.vue b/src/modules/wallet/accounts.vue index 47f1a442..e1248547 100644 --- a/src/modules/wallet/accounts.vue +++ b/src/modules/wallet/accounts.vue @@ -1,15 +1,278 @@ +
+
+
+
+

Accounts

+
+
+ + Manage all your assets in one page +
+
+
+
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
AccountDelegationBalance
+ + + +
+
+
+ +
+
+
+
{{ acc.chainName }}
+ +
+
+
+
+
+ {{ format.formatToken(acc.delegation, true, '0,0.[0000]', 'all') }} +
${{ + format.tokenValue(acc.delegation) }}
+
+
+
+ + {{ format.formatToken(b, true, '0,0.[0000]', 'all') }} +
${{ format.tokenValue(b) }} ({{ + format.showChanges(format.priceChanges(b.denom)) }}%)
+
+
+
+ +
+
+ +
+
+
+ + +
diff --git a/src/modules/wallet/portfolio.vue b/src/modules/wallet/portfolio.vue new file mode 100644 index 00000000..cb7a60f4 --- /dev/null +++ b/src/modules/wallet/portfolio.vue @@ -0,0 +1,87 @@ + + diff --git a/src/modules/wallet/portfollio.vue b/src/modules/wallet/portfollio.vue deleted file mode 100644 index 47f1a442..00000000 --- a/src/modules/wallet/portfollio.vue +++ /dev/null @@ -1,15 +0,0 @@ - - diff --git a/src/modules/wallet/utils.ts b/src/modules/wallet/utils.ts new file mode 100644 index 00000000..bdc90688 --- /dev/null +++ b/src/modules/wallet/utils.ts @@ -0,0 +1,49 @@ +import { useDashboard } from "@/stores" +import type { Coin } from "@/types" +import { fromBech32, toBech32 } from "@cosmjs/encoding" + +export interface AccountEntry { + chainName: string, + logo: string, + address: string, + coinType: string, + endpoint?: string, + delegation?: Coin, + balances?: Coin[], +} + +export function scanLocalKeys() { + const connected = [] as {cosmosAddress: string, hdPath: string}[] + for (let i = 0; i < localStorage.length; i++) { + const key = localStorage.key(i) + if (key?.startsWith("m/44")) { + const wallet = JSON.parse(localStorage.getItem(key) || "") + if (wallet) { + connected.push(wallet) + } + } + } + return connected + } + + +export function scanCompatibleAccounts() { + const dashboard = useDashboard() + const available = [] as AccountEntry[] + scanLocalKeys().forEach(wallet => { + dashboard.favorite.forEach(chainName => { + const chain = dashboard.chains[chainName] + if (chain && wallet.hdPath.indexOf(chain.coinType) === 6) { + const { data } = fromBech32(wallet.cosmosAddress) + available.push({ + chainName: chain.chainName, + logo: chain.logo, + address: toBech32(chain.bech32Prefix, data), + coinType: chain.coinType, + endpoint: chain.endpoints.rest?.at(0)?.address + }) + } + }) + }) + return available + } \ No newline at end of file diff --git a/src/stores/useFormatter.ts b/src/stores/useFormatter.ts index 2830718e..af6d5c80 100644 --- a/src/stores/useFormatter.ts +++ b/src/stores/useFormatter.ts @@ -73,6 +73,17 @@ export const useFormatter = defineStore('formatter', { const prices = this.dashboard.prices[id] return prices }, + priceColor(denom: string, currency = "usd") { + const change = this.priceChanges(denom, currency) + switch (true) { + case change > 0: + return "text-success" + case change < 0: + return "text-error" + default: + return "" + } + }, price(denom: string, currency = "usd") { const info = this.priceInfo(denom); return info? info[currency]||0 : 0 @@ -82,9 +93,13 @@ export const useFormatter = defineStore('formatter', { return info? info[`${currency}_24h_change`]||0 : 0 }, showChanges(v: number) { - return numeral(v).format("+0,0.[00]") + return v!==0 ? numeral(v).format("+0,0.[00]"): "" }, - tokenValue(token: Coin) { + tokenValue(token?: Coin) { + return token ? numeral(this.formatTokenAmount(token)).format('0,0.[00]') : "" + }, + tokenValueNumber(token?: Coin) { + if(!token) return 0 // find the symbol, const symbol = this.dashboard.coingecko[token.denom]?.symbol || "" // convert denomation to to symbol @@ -92,7 +107,7 @@ export const useFormatter = defineStore('formatter', { // cacualte amount of symbol const amount = Number(token.amount) / (10 ** exponent) const value = amount * this.price(token.denom) - return numeral(value).format('0,0.[00]') + return value }, formatTokenAmount(token: { denom: string; amount: string }) { return this.formatToken(token, false); @@ -100,10 +115,21 @@ export const useFormatter = defineStore('formatter', { formatToken2(token: { denom: string; amount: string }, withDenom = true) { return this.formatToken(token, true, '0,0.[00]'); }, + findGlobalAssetConfig(denom: string) { + const chains = Object.values(this.dashboard.chains) + for ( let i =0; i < chains.length; i++ ) { + const conf = chains[i].assets.find(a => a.base === denom) + if(conf) { + return conf + } + } + return null + }, formatToken( - token: { denom: string; amount: string }, + token?: { denom: string; amount: string }, withDenom = true, - fmt = '0.0a' + fmt = '0.0a', + mode = 'local' ): string { if (token && token.amount) { let amount = Number(token.amount); @@ -116,9 +142,10 @@ export const useFormatter = defineStore('formatter', { } } - const conf = this.blockchain.current?.assets?.find( + const conf = mode === 'local'? this.blockchain.current?.assets?.find( (x) => x.base === token.denom || x.base.denom === token.denom - ); + ): this.findGlobalAssetConfig(token.denom) + if (conf) { let unit = { exponent: 6, denom: '' }; // find the max exponent for display