Skip to content

Commit

Permalink
earn: add rexfund into staked value
Browse files Browse the repository at this point in the history
  • Loading branch information
apporc committed Sep 23, 2024
1 parent add8eb7 commit 466a721
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
56 changes: 31 additions & 25 deletions src/pages/earn/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,32 @@
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) => {
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 @@ -138,6 +161,12 @@
apy = ((annualReward / totalStaked) * 100).toFixed(2)
if ($currentAccount && $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 +219,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
2 changes: 1 addition & 1 deletion src/pages/earn/step/bootstrap.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Form from '~/components/elements/form.svelte'
import InputAsset from '~/components/elements/input/asset.svelte'
import InputLabel from '~/components/elements/input/label.svelte'
import {REXInfo} from '../types'
import type {REXInfo} from '../types'
export let amount: string
export let availableTokens: Asset
Expand Down

0 comments on commit 466a721

Please sign in to comment.