Calculate 24h changes diff correctly

This commit is contained in:
Techno Freak 2024-02-03 18:31:44 +03:00
parent 036801fe90
commit a792c379a5
2 changed files with 34 additions and 16 deletions

View File

@ -82,24 +82,35 @@ const changes = computed(() => {
return changes; return changes;
}); });
const change24 = (key: Key) => { const change24 = (entry: { consensus_pubkey: Key; tokens: string }) => {
const txt = key.key; const txt = entry.consensus_pubkey.key;
// const n: number = latest.value[txt]; // const n: number = latest.value[txt];
// const o: number = yesterday.value[txt]; // const o: number = yesterday.value[txt];
// // console.log( txt, n, o) // // console.log( txt, n, o)
// return n > 0 && o > 0 ? n - o : 0; // return n > 0 && o > 0 ? n - o : 0;
return changes.value[txt];
const latestValue = latest.value[txt];
if (!latestValue) {
return;
}
const displayTokens = format.tokenAmountNumber({
amount: parseInt(entry.tokens, 10).toString(),
denom: staking.params.bond_denom,
});
const coefficient = displayTokens / latestValue;
return changes.value[txt] * coefficient;
}; };
const change24Text = (key?: Key) => { const change24Text = (entry: { consensus_pubkey: Key; tokens: string }) => {
if (!key) return ''; if (!entry) return '';
const v = change24(key); const v = change24(entry);
return v && v !== 0 ? format.showChanges(v) : ''; return v && v !== 0 ? format.showChanges(v) : '';
}; };
const change24Color = (key?: Key) => { const change24Color = (entry: { consensus_pubkey: Key; tokens: string }) => {
if (!key) return ''; if (!entry) return '';
const v = change24(key); const v = change24(entry);
if (v > 0) return 'text-success'; if (v > 0) return 'text-success';
if (v < 0) return 'text-error'; if (v < 0) return 'text-error';
}; };
@ -416,9 +427,9 @@ loadAvatars();
<!-- 👉 24h Changes --> <!-- 👉 24h Changes -->
<td <td
class="text-right text-xs" class="text-right text-xs"
:class="change24Color(v.consensus_pubkey)" :class="change24Color(v)"
> >
{{ change24Text(v.consensus_pubkey) }} {{ change24Text(v) }}
</td> </td>
<!-- 👉 commission --> <!-- 👉 commission -->
<td class="text-right text-xs"> <td class="text-right text-xs">

View File

@ -123,15 +123,22 @@ export const useFormatter = defineStore('formatter', {
} }
return 0 return 0
}, },
tokenValueNumber(token?: Coin) { tokenAmountNumber(token?: Coin) {
if(!token || !token.denom) return 0 if(!token || !token.denom) return 0
// find the symbol,
// find the symbol
const symbol = this.dashboard.coingecko[token.denom]?.symbol || token.denom const symbol = this.dashboard.coingecko[token.denom]?.symbol || token.denom
// convert denomation to to symbol // convert denomination to to symbol
const exponent = const exponent =
this.dashboard.coingecko[symbol?.toLowerCase()]?.exponent || this.specialDenom(token.denom); this.dashboard.coingecko[symbol?.toLowerCase()]?.exponent || this.specialDenom(token.denom);
// cacualte amount of symbol // caculate amount of symbol
const amount = Number(token.amount) / (10 ** exponent) const amount = Number(token.amount) / (10 ** exponent)
return amount
},
tokenValueNumber(token?: Coin) {
if(!token || !token.denom) return 0
const amount = this.tokenAmountNumber(token)
const value = amount * this.price(token.denom) const value = amount * this.price(token.denom)
return value return value
}, },