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] 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 || ''
}}
+
@@ -98,3 +100,14 @@ chainStore.$subscribe((m, s) => {
+
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 @@
- Hello wallet
-
+
+
+
+
+
Accounts
+
+
+
+ Manage all your assets in one page
+
+
+
+
+
+
+
+
+
+ |
+ Account |
+ Delegation |
+ Balance |
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+ {{ acc.chainName }}
+ {{ acc.address }}
+
+
+
+ |
+
+
+ {{ 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)) }}%)
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
Import Accounts
+
+
+
+
+
Only shows blockchains on your favorite list
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ acc.chainName }}
+ {{ acc.address }}
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
Portfolio
+
+
+
+ Manage all your assets in one page {{ totalValue }}
+
+
+
+
+
+
+
+
+
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 @@
-
-
- Hello wallet
-
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