Skip to content

Commit

Permalink
Fix savings balance
Browse files Browse the repository at this point in the history
  • Loading branch information
apporc committed Jul 6, 2024
1 parent 46b92c5 commit 96bf165
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/pages/earn/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@
let savings = defaultZero
let matured = defaultZero
let rexPrice = 0
const fiveYearsFromNow = new Date().getTime() + 1000 * 60 * 60 * 24 * 365 * 5
if ($currentAccount && $currentAccount.rex_info && $stateREX && $stateREX.value) {
console.log(`currentAccount: ${JSON.stringify($currentAccount.rex_info)}`)
if ($stateREX.value === 0.0001) {
rexPrice = $stateREX.total_lendable.value / $stateREX.total_rex.value
} else {
Expand All @@ -82,14 +83,26 @@
$currentAccount.rex_info.rex_balance.value * rexPrice,
$systemToken!.symbol
)
savings = $currentAccount.rex_info.vote_stake
matured = Asset.from(
Asset.fromUnits(
$currentAccount.rex_info.matured_rex,
$currentAccount.rex_info.rex_balance.symbol
).value * rexPrice,
$systemToken!.symbol
)
let savingsBucket = $currentAccount.rex_info.rex_maturities.find(
(maturity) => +new Date(maturity.first!.toString()) > +fiveYearsFromNow
)
if (savingsBucket) {
savings = Asset.from(
Asset.fromUnits(
savingsBucket.second!,
$currentAccount.rex_info.rex_balance.symbol
).value * rexPrice,
$systemToken!.symbol
)
}
}
return {total, savings, matured, price: rexPrice}
}
Expand Down Expand Up @@ -184,7 +197,6 @@
function getUnstakeAction() {
let rexNumber = Number(selectedAmount) / $rexInfo.price
let rexAsset = Asset.from(rexNumber, $currentAccount!.rex_info!.rex_balance.symbol)
console.log(`rexAsset: ${JSON.stringify(rexAsset)}`)
return [
{
authorization: [$activeSession!.auth],
Expand Down

0 comments on commit 96bf165

Please sign in to comment.