From 4b1da2b63da97b2fcfca33f7b4f4e4e4629d04c5 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Tue, 12 Oct 2021 17:01:06 +0800 Subject: [PATCH] add market cap change --- src/views/WalletAccounts.vue | 96 +++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 8 deletions(-) diff --git a/src/views/WalletAccounts.vue b/src/views/WalletAccounts.vue index 97185138..bd5e5ca8 100644 --- a/src/views/WalletAccounts.vue +++ b/src/views/WalletAccounts.vue @@ -37,9 +37,21 @@ KRW (대한민국원) -

+

{{ currency }}{{ calculateTotal }}

+ + +{{ calculateTotalChange }} (24h) + + + {{ calculateTotalChange }} (24h) + -

{{ currency }}{{ formatBalance(acc.addr) }}

+
+

{{ currency }}{{ formatBalance(acc.addr) }} +

+ {{ formatBalanceChanges(acc.addr) }} +
@@ -154,7 +170,7 @@ :key="i" class="d-flex justify-content-between align-items-center" > -
+
{{ formatDenom(b.denom) }} + {{ formatChanges(b.denom) }}
{{ formatAmount(b.amount, b.denom) }} @@ -178,7 +198,7 @@ :key="`d-${i}`" class="d-flex justify-content-between align-items-center" > -
+
{{ formatDenom(b.denom) }} + {{ formatChanges(b.denom) }}
{{ formatAmount(b.amount, b.denom) }} @@ -348,13 +372,30 @@ export default { } return parseFloat(total.toFixed(2)) }, + calculateTotalChange() { + const v = Object.values(this.balances) + let total = 0 + if (v) { + v.forEach(tokens => { + const subtotal = tokens.map(x => this.formatCurrency(x.amount, x.denom) * this.getChanges(x.denom) * 0.01).reduce((t, c) => t + c) + total += subtotal + }) + } + const d = Object.values(this.delegations) + if (d) { + d.forEach(tokens => { + const subtotal = tokens.map(x => this.formatCurrency(x.amount, x.denom) * this.getChanges(x.denom) * 0.01).reduce((t, c) => t + c, 0) + total += subtotal + }) + } + return parseFloat(total.toFixed(2)) + }, calculateByDenom() { const v = Object.values(this.balances) const total = {} const qty = {} if (v) { v.forEach(tokens => { - // const subtotal = tokens.map(x => ({ denom: x.denom, sub: this.formatCurrency(x.amount, x.denom) })) tokens.forEach(x => { const denom = this.formatDenom(x.denom) if (total[denom]) { @@ -373,7 +414,6 @@ export default { const d = Object.values(this.delegations) if (d) { d.forEach(tokens => { - // const subtotal = tokens.map(x => ({ denom: x.denom, sub: this.formatCurrency(x.amount, x.denom) })) tokens.forEach(x => { const denom = this.formatDenom(x.denom) if (total[denom]) { @@ -496,6 +536,28 @@ export default { } return 0 }, + priceColor(denom) { + const d2 = this.formatDenom(denom) + const quote = this.$store.state.chains.quotes[d2] + if (quote) { + const price = quote[`${this.currency2}_24h_change`] + return price > 0 ? 'text-success' : 'text-danger' + } + return '' + }, + getChanges(denom) { + const d2 = this.formatDenom(denom) + const quote = this.$store.state.chains.quotes[d2] + if (quote) { + const price = quote[`${this.currency2}_24h_change`] + return price + } + return 0 + }, + formatChanges(denom) { + const price = this.getChanges(denom) + return `${parseFloat(price.toFixed(2))}%` + }, formatBalance(v) { let total = 0 const balance = this.balances[v] @@ -510,6 +572,24 @@ export default { } return parseFloat(total.toFixed(2)) }, + formatBalanceChanges(v) { + let total = 0 + const balance = this.balances[v] + if (balance) { + const ret = balance.map(x => this.formatCurrency(x.amount, x.denom) * this.getChanges(x.denom) * 0.01).reduce((t, c) => t + c) + total += ret + } + const delegations = this.delegations[v] + if (delegations) { + const ret = delegations.map(x => this.formatCurrency(x.amount, x.denom) * this.getChanges(x.denom) * 0.01).reduce((t, c) => t + c, 0) + total += ret + } + return parseFloat(total.toFixed(2)) + }, + formatBalanceChangesColor(v) { + const total = this.formatBalanceChanges(v) + return total > 0 ? 'text-success' : 'text-danger' + }, removeAddress(v) { Object.keys(this.accounts).forEach(key => { const item = this.accounts[key]