Skip to content

Commit

Permalink
fix(mobile): staking balance calculation (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokin0andrey authored Oct 5, 2023
1 parent b10b337 commit 4ee2e75
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/mobile/src/utils/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ export const calculatePoolBalance = (pool: PoolInfo, stakingInfo: StakingInfo) =
const pendingDeposit = new BigNumber(
Ton.fromNano(stakingInfo[pool.address]?.pending_deposit || '0'),
);
const pendingWithdraw = new BigNumber(
Ton.fromNano(stakingInfo[pool.address]?.pending_withdraw || '0'),
);
const readyWithdraw = new BigNumber(
Ton.fromNano(stakingInfo[pool.address]?.ready_withdraw || '0'),
);
const balance = amount.plus(pendingDeposit).plus(readyWithdraw);
const balance = amount
.plus(pendingDeposit)
.plus(readyWithdraw)
.plus(pool.implementation === PoolImplementationType.LiquidTF ? pendingWithdraw : 0);

return balance;
};
6 changes: 3 additions & 3 deletions packages/shared/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
"confirmSendModal": {
"title": "Confirm action",
"network_fee": "Network fee",
"to_your_address":"To your address",
"to_your_address": "To your address",
"transaction_type": {
"send": "Send",
"receive": "Receive",
Expand Down Expand Up @@ -889,13 +889,13 @@
"pendingDeposit": "Pending Stake",
"pendingWithdraw": "Pending Unstake",
"pendingWithdrawDesc": "at the end of the cycle",
"readyWithdraw": "Withdrawal ready",
"readyWithdraw": "Unstake ready",
"tap_to_collect": "Tap to collect",
"next_cycle": {
"title": "Next cycle",
"reward_title": "Next reward",
"desc": "All transactions take effect once the cycle ends.",
"desc_liquid": "Unstake requests are complete after the cycle ends.",
"desc_liquid": "Unstake requests are complete after the cycle ends.",
"in": "in"
},
"cooldown": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/i18n/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@
"title": "Следующий цикл",
"reward_title": "Следующая награда",
"desc": "Все транзакции исполняются только после завершения цикла.",
"desc_liquid": "Все запросы на вывод исполняются только после завершения цикла.",
"desc_liquid": "Запросы на вывод исполнятся после завершения цикла.",
"in": "через"
},
"cooldown": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { t } from '../../../i18n';
import { memo } from 'react';
import { useHideableFormatter } from '@tonkeeper/mobile/src/core/HideableAmount/useHideableFormatter';
import { StakingIcon } from '../components/StakingIcon';
import { fiatCurrencySelector } from '@tonkeeper/mobile/src/store/main';
import { useTokenPrice } from '@tonkeeper/mobile/src/hooks/useTokenPrice';
import { useSelector } from 'react-redux';
import { formatter } from '../../../formatter';

interface WithdrawStakeRequestActionContentProps {
action: ActionItem<ActionType.WithdrawStakeRequest>;
Expand All @@ -18,6 +22,12 @@ export const WithdrawStakeRequestActionContent =

const { formatNano, format } = useHideableFormatter();

const fiatCurrency = useSelector(fiatCurrencySelector);
const tokenPrice = useTokenPrice(
'ton',
formatter.fromNano(action.amount?.value ?? '0'),
);

const formattedAmount = action.amount
? formatNano(action.amount.value, {
decimals: action.amount.decimals,
Expand All @@ -27,6 +37,12 @@ export const WithdrawStakeRequestActionContent =
})
: null;

const formattedFiat = action.amount
? format(tokenPrice.totalFiat, {
currency: fiatCurrency,
})
: '';

return (
<ActionModalContent
title={t('activityActionModal.withdrawal_request')}
Expand All @@ -46,6 +62,7 @@ export const WithdrawStakeRequestActionContent =
titleType="secondary"
title={t('transactionDetails.withdraw_amount')}
value={formattedAmount}
subvalue={formattedFiat}
/>
) : null}

Expand Down

0 comments on commit 4ee2e75

Please sign in to comment.