Skip to content

Commit

Permalink
Fix staking claimable value
Browse files Browse the repository at this point in the history
  • Loading branch information
apporc committed Sep 9, 2024
1 parent 5767681 commit 582ca35
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/pages/earn/index.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type {Readable, Writable} from 'svelte/store'
import {derived, writable, get} from 'svelte/store'
import {AnyAction, Asset, Int128} from 'anchor-link'
import {AnyAction, Asset, Int128, Int64} from 'anchor-link'
import {currentAccount} from '~/store'
import {activeBlockchain, activeSession} from '~/store'
Expand Down Expand Up @@ -130,16 +130,26 @@
let matured = defaultZero
let apy = ''
const fiveYearsFromNow = new Date().getTime() + 1000 * 60 * 60 * 24 * 365 * 5
const now = new Date()
if ($stateREX && $stateREX.value) {
const annualReward = 31250000
const totalStaked = Number($stateREX.total_lendable.value)
apy = ((annualReward / totalStaked) * 100).toFixed(2)
if ($currentAccount && $currentAccount.rex_info) {
total = convertRexToEos($currentAccount.rex_info.rex_balance.value)
const claimableBuckets = $currentAccount.rex_info.rex_maturities.filter(
(maturity) => +new Date(maturity.first!.toString()) < +now
)
let claimable = claimableBuckets.reduce(
(acc, r) => acc.adding(r.second!),
Int64.from(0)
)
matured = convertRexToEos(
Asset.fromUnits(
$currentAccount.rex_info.matured_rex,
$currentAccount.rex_info.matured_rex.adding(claimable),
$currentAccount.rex_info.rex_balance.symbol
).value
)
Expand Down

0 comments on commit 582ca35

Please sign in to comment.