From ed92ffe83788a6937edf10ddffca20a077002d57 Mon Sep 17 00:00:00 2001
From: liangping <18786721@qq.com>
Date: Fri, 16 Jun 2023 08:21:29 +0800
Subject: [PATCH] improve portfolio
---
src/components/charts/apexChartConfig.ts | 33 +++++++++++++---------
src/modules/[chain]/index.vue | 4 +--
src/modules/wallet/portfolio.vue | 35 ++++++++++++++----------
src/stores/useFormatter.ts | 24 ++++++++++++++++
4 files changed, 67 insertions(+), 29 deletions(-)
diff --git a/src/components/charts/apexChartConfig.ts b/src/components/charts/apexChartConfig.ts
index c219ea83..3d5dcedd 100644
--- a/src/components/charts/apexChartConfig.ts
+++ b/src/components/charts/apexChartConfig.ts
@@ -258,17 +258,23 @@ export const getMarketPriceChartConfig = (
},
};
};
+
+// const donutColors = Array.from({length: 19}, () => (`#${Math.floor(Math.random()*16777215+100000).toString(16)}`))
+const donutColors = ['#c2992c', '#aa1cdb', '#83b0ad', '#bac470', '#cd1bb3', '#f65f30', '#5cfc8a', '#14aced', '#bf725b', '#2e9d9', '#2d5087', '#acfe3e', '#bbf511', '#53cd60', '#5d842d', '#61cd7c', '#c5cf75', '#ad5eb', '#164731']
+
export const getDonutChartConfig = (
theme: string,
labels: string[]
) => {
- const donutColors = {
- series1: '#fdd835',
- series2: '#00d4bd',
- series3: '#826bf8',
- series4: '#32baff',
- series5: '#ffa1a1',
- };
+ // const donutColors = {
+ // series1: '#fdd835',
+ // series2: '#00d4bd',
+ // series3: '#826bf8',
+ // series4: '#32baff',
+ // series5: '#ffa1a1',
+ // };
+
+ console.log(donutColors)
const { themeSecondaryTextColor, themePrimaryTextColor } =
colorVariables(theme);
@@ -276,12 +282,13 @@ export const getDonutChartConfig = (
return {
stroke: { width: 0 },
labels,
- colors: [
- donutColors.series1,
- donutColors.series5,
- donutColors.series3,
- donutColors.series2,
- ],
+ colors: donutColors,
+ // colors: [
+ // donutColors.series1,
+ // donutColors.series5,
+ // donutColors.series3,
+ // donutColors.series2,
+ // ],
dataLabels: {
enabled: true,
formatter: (val: string) => `${parseInt(val, 10)}%`,
diff --git a/src/modules/[chain]/index.vue b/src/modules/[chain]/index.vue
index 3b54f71a..ca89b720 100644
--- a/src/modules/[chain]/index.vue
+++ b/src/modules/[chain]/index.vue
@@ -202,7 +202,7 @@ const amount = computed({
-
Close
-
Buy {{ coinInfo.symbol || '' }}
diff --git a/src/modules/wallet/portfolio.vue b/src/modules/wallet/portfolio.vue
index f9890611..510bc3b1 100644
--- a/src/modules/wallet/portfolio.vue
+++ b/src/modules/wallet/portfolio.vue
@@ -27,17 +27,17 @@ scanLocalKeys().forEach((wallet) => {
// load balance & delegations
if (imported)
imported.forEach((x) => {
- if (x.endpoint) {
+ if (x.endpoint && x.address) {
const client = CosmosRestClient.newDefault(x.endpoint);
client.getBankBalances(x.address).then((res) => {
const bal = res.balances.filter((x) => x.denom.length < 10);
- balances.value[x.address] = bal;
+ if(bal) balances.value[x.address || ""] = bal;
bal.forEach((b) => {
tokenMeta.value[b.denom] = x;
});
});
client.getStakingDelegations(x.address).then((res) => {
- delegations.value[x.address] = res.delegation_responses;
+ if(res && res.delegation_responses) delegations.value[x.address || ""] = res.delegation_responses;
res.delegation_responses.forEach((del) => {
tokenMeta.value[del.balance.denom] = x;
});
@@ -98,9 +98,11 @@ const tokenList = computed(() => {
});
return list.filter((x) => x.value > 0).sort((a, b) => b.value - a.value);
});
+
+
{
d="M3 15.055v-.684c.126.053.255.1.39.142 2.092.642 4.313.987 6.61.987 2.297 0 4.518-.345 6.61-.987.135-.041.264-.089.39-.142v.684c0 1.347-.985 2.53-2.363 2.686a41.454 41.454 0 01-9.274 0C3.985 17.585 3 16.402 3 15.055z"
/>
- Manage all your assets in one page {{ totalValue }}
+ Manage all your assets in one page
-
+
+
Total Value
+
${{ format.formatNumber(totalValue, '0,0.[00]') }}
+
-
+
-
+
@@ -149,25 +155,26 @@ const tokenList = computed(() => {
-
-
+
+
- {{ x.chainName }}
+ {{ format.tokenDisplayDenom(x.denom) }} @
+ {{ x.chainName }}
|
- ${{ format.formatNumber(x.value) }} |
+ ${{ format.formatNumber(x.value, '0,0.[00]') }} |
{{ format.percent(x.percentage) }} |
|
-
- No Data
+
+ No Data, Import Address
diff --git a/src/stores/useFormatter.ts b/src/stores/useFormatter.ts
index b0bf7477..aae605b5 100644
--- a/src/stores/useFormatter.ts
+++ b/src/stores/useFormatter.ts
@@ -142,6 +142,30 @@ export const useFormatter = defineStore('formatter', {
}
return null
},
+ tokenDisplayDenom(denom?: string) {
+ if (denom) {
+ if (denom && denom.startsWith('ibc/')) {
+ let ibcDenom = this.ibcDenoms[denom.replace('ibc/', '')];
+ if (ibcDenom) {
+ denom = ibcDenom.base_denom;
+ }
+ }
+
+ const conf = this.findGlobalAssetConfig(denom)
+
+ if (conf) {
+ let unit = { exponent: 6, denom: '' };
+ // find the max exponent for display
+ conf.denom_units.forEach((x) => {
+ if (x.exponent >= unit.exponent) {
+ unit = x;
+ }
+ });
+ return unit.denom;
+ }
+ return denom;
+ }
+ },
tokenDisplayNumber(
token?: { denom: string; amount: string },
mode = 'all'