Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staked value fix #212

Merged
merged 10 commits into from
Oct 2, 2024
59 changes: 33 additions & 26 deletions src/pages/earn/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,33 @@
return Asset.fromUnits(result, $systemToken!.symbol)
}

const rexEOSBalance: Writable<Asset> = writable(Asset.from(0, $systemToken!.symbol))
onMount(async () => {
const client = getClient($activeBlockchain.chainId)
const unsubscribe = currentAccount.subscribe(async (account) => {
aaroncox marked this conversation as resolved.
Show resolved Hide resolved
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<REXInfo> = 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
Expand All @@ -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
Expand Down Expand Up @@ -190,29 +220,6 @@
return result
})

const rexEOSBalance: Writable<Asset> = 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<Step> = writable(initialStep, () => {
const unsubscribeStep = defaultStep.subscribe((s) => {
Expand Down
Loading