From 4ee2e7594d1faa755a76ceef4307557c77cda86e Mon Sep 17 00:00:00 2001 From: Andrey Sorokin Date: Fri, 6 Oct 2023 02:03:00 +0600 Subject: [PATCH] fix(mobile): staking balance calculation (#592) --- packages/mobile/src/utils/staking.ts | 8 +++++++- packages/shared/i18n/locales/en.json | 6 +++--- packages/shared/i18n/locales/ru.json | 2 +- .../WithdrawStakeRequestActionContent.tsx | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/mobile/src/utils/staking.ts b/packages/mobile/src/utils/staking.ts index 68ad71f36..d343b3ce4 100644 --- a/packages/mobile/src/utils/staking.ts +++ b/packages/mobile/src/utils/staking.ts @@ -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; }; diff --git a/packages/shared/i18n/locales/en.json b/packages/shared/i18n/locales/en.json index 8926ab12c..1917d56ed 100644 --- a/packages/shared/i18n/locales/en.json +++ b/packages/shared/i18n/locales/en.json @@ -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", @@ -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": { diff --git a/packages/shared/i18n/locales/ru.json b/packages/shared/i18n/locales/ru.json index 88797f9b3..8f2b6fce5 100644 --- a/packages/shared/i18n/locales/ru.json +++ b/packages/shared/i18n/locales/ru.json @@ -935,7 +935,7 @@ "title": "Следующий цикл", "reward_title": "Следующая награда", "desc": "Все транзакции исполняются только после завершения цикла.", - "desc_liquid": "Все запросы на вывод исполняются только после завершения цикла.", + "desc_liquid": "Запросы на вывод исполнятся после завершения цикла.", "in": "через" }, "cooldown": { diff --git a/packages/shared/modals/ActivityActionModal/content/WithdrawStakeRequestActionContent.tsx b/packages/shared/modals/ActivityActionModal/content/WithdrawStakeRequestActionContent.tsx index 1564efa0c..3ded0c3b5 100644 --- a/packages/shared/modals/ActivityActionModal/content/WithdrawStakeRequestActionContent.tsx +++ b/packages/shared/modals/ActivityActionModal/content/WithdrawStakeRequestActionContent.tsx @@ -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; @@ -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, @@ -27,6 +37,12 @@ export const WithdrawStakeRequestActionContent = }) : null; + const formattedFiat = action.amount + ? format(tokenPrice.totalFiat, { + currency: fiatCurrency, + }) + : ''; + return ( ) : null}