From 93cb2ad541bf0e6570f8f6f927c8452b699e5c69 Mon Sep 17 00:00:00 2001 From: Vance Date: Thu, 3 Oct 2024 01:24:35 +0800 Subject: [PATCH] staked value fix (#212) * earn: add rexfund into staked value * Update src/pages/earn/index.svelte Co-authored-by: Daniel Fugere * Update src/pages/earn/index.svelte Co-authored-by: Daniel Fugere * Update src/pages/earn/index.svelte Co-authored-by: Daniel Fugere * Update src/pages/earn/index.svelte Co-authored-by: Daniel Fugere * Update src/pages/earn/index.svelte Co-authored-by: Daniel Fugere * Syntax fixes * browser list updates * Revert "browser list updates" This reverts commit c5ac2d17641b56e9e7313a2eb14c3db9814349bd. --------- Co-authored-by: Aaron Cox Co-authored-by: Daniel Fugere --- src/pages/earn/index.svelte | 59 +++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/pages/earn/index.svelte b/src/pages/earn/index.svelte index e3397b0c..c84bc957 100644 --- a/src/pages/earn/index.svelte +++ b/src/pages/earn/index.svelte @@ -121,9 +121,33 @@ return Asset.fromUnits(result, $systemToken!.symbol) } + const rexEOSBalance: Writable = writable(Asset.from(0, $systemToken!.symbol)) + onMount(async () => { + const client = getClient($activeBlockchain.chainId) + const unsubscribe = currentAccount.subscribe(async (account) => { + if (!$systemToken) return + const result = await client.v1.chain.get_table_rows({ + code: 'eosio', + scope: 'eosio', + table: 'rexfund', + json: true, + lower_bound: $currentAccount?.account_name, + upper_bound: $currentAccount?.account_name, + }) + if (result.rows.length > 0) { + rexEOSBalance.set(Asset.from(result.rows[0].balance, $systemToken.symbol)) + } else { + rexEOSBalance.set(Asset.from(0, $systemToken.symbol)) + } + }) + return () => { + unsubscribe() + } + }) + const rexInfo: Readable = derived( - [currentAccount, stateREX, systemToken], - ([$currentAccount, $stateREX, $systemToken]) => { + [currentAccount, stateREX, systemToken, rexEOSBalance], + ([$currentAccount, $stateREX, $systemToken, $rexEOSBalance]) => { let defaultZero = Asset.from(0, $systemToken!.symbol) let total = defaultZero let savings = defaultZero @@ -136,8 +160,14 @@ const annualReward = 31250000 const totalStaked = Number($stateREX.total_lendable.value) apy = ((annualReward / totalStaked) * 100).toFixed(2) - if ($currentAccount && $currentAccount.rex_info) { + if ($currentAccount && $systemToken && $currentAccount.rex_info) { total = convertRexToEos($currentAccount.rex_info.rex_balance.value) + if ($rexEOSBalance.value > 0) { + total = Asset.fromUnits( + total.units.adding($rexEOSBalance.units), + $systemToken.symbol + ) + } const claimableBuckets = $currentAccount.rex_info.rex_maturities.filter( (maturity) => +new Date(maturity.first!.toString()) < +now @@ -190,29 +220,6 @@ return result }) - const rexEOSBalance: Writable = writable(Asset.from(0, $systemToken!.symbol)) - onMount(async () => { - const client = getClient($activeBlockchain.chainId) - const unsubscribe = currentAccount.subscribe(async (account) => { - const result = await client.v1.chain.get_table_rows({ - code: 'eosio', - scope: 'eosio', - table: 'rexfund', - json: true, - lower_bound: $currentAccount?.account_name, - upper_bound: $currentAccount?.account_name, - }) - if (result.rows.length > 0) { - rexEOSBalance.set(Asset.from(result.rows[0].balance, $systemToken!.symbol)) - } else { - rexEOSBalance.set(Asset.from(0, $systemToken!.symbol)) - } - }) - return () => { - unsubscribe() - } - }) - const initialStep: Step = Step.Bootstrap const step: Writable = writable(initialStep, () => { const unsubscribeStep = defaultStep.subscribe((s) => {