Skip to content

Commit

Permalink
Show matured balance
Browse files Browse the repository at this point in the history
  • Loading branch information
apporc committed Jun 25, 2024
1 parent 14c661a commit bf3cf53
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
20 changes: 19 additions & 1 deletion src/pages/earn/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@
}
)
const maturedBalance: Readable<Asset> = derived(
[currentAccount, stateREX, systemToken],
([$currentAccount, $stateREX, $systemToken]) => {
let value = 0
if ($currentAccount && $currentAccount.rex_info && $stateREX && $stateREX.value) {
if ($stateREX.value === 0.0001) {
value =
($stateREX.total_lendable.value / $stateREX.total_rex.value) *
Number($currentAccount.rex_info.matured_rex)
} else {
value = $stateREX.value * Number($currentAccount.rex_info.matured_rex)
}
}
return Asset.fromUnits(value, $systemToken!.symbol)
}
)
const rexToken: Readable<Token> = derived(
[systemToken, rexBalance],
([$systemToken, $rexBalance]) => {
Expand Down Expand Up @@ -248,6 +265,7 @@
/>
{:else if $step === Step.Overview}
<REXOverview
maturedBalance={$maturedBalance}
rexBalance={$rexBalance}
toStake={() => switchStep(Step.Stake)}
toUnstake={() => switchStep(Step.Unstake)}
Expand All @@ -263,7 +281,7 @@
<REXUnstake
bind:amount={selectedAmount}
token={$rexToken}
availableTokens={$rexBalance}
availableTokens={$maturedBalance}
nextStep={() => toStakeConfirm(Step.Unstake)}
/>
{:else if $step === Step.Confirm}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/earn/step/overview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Button from '~/components/elements/button.svelte'
export let maturedBalance: Asset
export let rexBalance: Asset
export let toStake: () => void
export let toUnstake: () => void
Expand Down Expand Up @@ -96,7 +97,8 @@
<div class="rex">
<div class="label">currently staked balance</div>
<div class="balance">
{rexBalance}
{maturedBalance.value} / {rexBalance.value}
{rexBalance.symbol.name}
</div>
<div class="buttons">
<Button
Expand Down
10 changes: 6 additions & 4 deletions src/pages/earn/step/unstake.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
export let availableTokens: Asset
export let nextStep: () => void
let selectedToken: Token
let tokenOptions: Token[] = []
if (token) {
let newToken = {...token}
newToken.balance = availableTokens
let newToken = {...token, balance: availableTokens}
selectedToken = newToken
tokenOptions = [newToken]
}
let amountValid = false
Expand Down Expand Up @@ -92,9 +94,9 @@
<InputLabel>amount to unstake</InputLabel>
<div class="token-selector">
<TokenSelector
defaultToken={token}
defaultToken={selectedToken}
{tokenOptions}
selectedToken={token}
{selectedToken}
onTokenSelect={() => {}}
/>
</div>
Expand Down

0 comments on commit bf3cf53

Please sign in to comment.