From 30b4b05f5e18631202f44b36e7a07933e48361d9 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Fri, 13 Oct 2023 01:50:05 +0700 Subject: [PATCH] fix tvl --- src/components/YieldPools/ListItem.tsx | 8 ++++---- src/state/farms/classic/knUpdater.tsx | 7 +++---- src/state/farms/classic/rpcUpdater.tsx | 4 ++-- src/state/farms/classic/updater.tsx | 2 +- src/utils/numbers.ts | 3 +++ 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/YieldPools/ListItem.tsx b/src/components/YieldPools/ListItem.tsx index 6a60589dbf..1a87487393 100644 --- a/src/components/YieldPools/ListItem.tsx +++ b/src/components/YieldPools/ListItem.tsx @@ -46,7 +46,7 @@ import { currencyIdFromAddress } from 'utils/currencyId' import { getTradingFeeAPR, useFarmApr, useFarmRewards, useFarmRewardsUSD } from 'utils/dmm' import { formatTokenBalance, getFullDisplayBalance } from 'utils/formatBalance' import { getFormattedTimeFromSecond } from 'utils/formatTime' -import { formatDollarAmount } from 'utils/numbers' +import { formatDisplayNumber } from 'utils/numbers' import { unwrappedToken } from 'utils/wrappedCurrency' import { ModalContentWrapper } from './ElasticFarmModals/styled' @@ -368,7 +368,7 @@ const ListItem = ({ farm }: ListItemProps) => { {/* STAKED TVL */} - {formatDollarAmount(liquidity)} + {formatDisplayNumber(liquidity, { style: 'currency', significantDigits: 6 })} {/* AVG APR */} @@ -551,7 +551,7 @@ const ListItem = ({ farm }: ListItemProps) => { - {formatDollarAmount(liquidity)} + {formatDisplayNumber(liquidity, { style: 'currency', significantDigits: 6 })} {farm.version === FairLaunchVersion.V2 ? ( farm.startTime > currentTimestamp ? ( @@ -573,7 +573,7 @@ const ListItem = ({ farm }: ListItemProps) => { - {!!userStakedBalanceUSD ? formatDollarAmount(userStakedBalanceUSD) : '--'} + {formatDisplayNumber(userStakedBalanceUSD, { style: 'currency', significantDigits: 6, allowZero: false })} diff --git a/src/state/farms/classic/knUpdater.tsx b/src/state/farms/classic/knUpdater.tsx index 88faf69256..2c4d912a23 100644 --- a/src/state/farms/classic/knUpdater.tsx +++ b/src/state/farms/classic/knUpdater.tsx @@ -52,8 +52,8 @@ const KNUpdater = ({ isInterval = true }: { isInterval?: boolean }) => { const rewardTokens = farmPool.rewardTokens.map( ({ id, decimals, symbol, name }) => new Token(chainId, id, Number(decimals), symbol, name), ) - const totalStake = parseNum(farmPool.stakedTvl) - const stakeToken = id // todo namgold: check this + const totalStake = parseNum(farmPool.stakedAmount).divide(10 ** 18) + const stakeToken = id const token0 = { id: farmPool.pool.token0.id, symbol: farmPool.pool.token0.symbol } const token1 = { id: farmPool.pool.token1.id, symbol: farmPool.pool.token1.symbol } const amp = Number(farmPool.pool.amp) @@ -65,11 +65,10 @@ const KNUpdater = ({ isInterval = true }: { isInterval?: boolean }) => { .subtract(parseNum(farmPool.pool.feesUsdOneDayAgo)) .toFixed(18) const oneDayFeeUntracked = '0' - const userData = {} // todo namgold: fill this. - const rewardPerUnits: BigNumber[] = farmPool.rewardPerUnits.map(i => parseUnits(toFixed(i), 0)) const start = Number(farmPool.start) const end = Number(farmPool.end) + const userData = {} // todo namgold: fill this. if (version === FairLaunchVersion.V1) { return { diff --git a/src/state/farms/classic/rpcUpdater.tsx b/src/state/farms/classic/rpcUpdater.tsx index a1f7f8c7ff..bf2e2ed97c 100644 --- a/src/state/farms/classic/rpcUpdater.tsx +++ b/src/state/farms/classic/rpcUpdater.tsx @@ -140,13 +140,13 @@ export default function RPCUpdater({ isInterval = true }: { isInterval?: boolean (farmData: Farm) => farmData && farmData.id.toLowerCase() === poolInfo.stakeToken.toLowerCase(), ), ...poolInfo, + version: isV2 ? FairLaunchVersion.V2 : isV3 ? FairLaunchVersion.V3 : FairLaunchVersion.V1, rewardTokens: poolInfo.rewardTokens, fairLaunchAddress: contract.address, userData: { stakedBalance: stakedBalances[index], rewards: [FairLaunchVersion.V2, FairLaunchVersion.V3].includes(poolInfo.fairLaunchVersion) - ? pendingRewards[index] && - pendingRewards[index].map((pendingReward: BigNumber, pendingRewardIndex: number) => + ? pendingRewards[index]?.map((pendingReward: BigNumber, pendingRewardIndex: number) => pendingReward.div( isV3 ? poolInfo.multipliers[pendingRewardIndex] : poolInfo.rewardMultipliers[pendingRewardIndex], ), diff --git a/src/state/farms/classic/updater.tsx b/src/state/farms/classic/updater.tsx index e6f1875467..171f71accd 100644 --- a/src/state/farms/classic/updater.tsx +++ b/src/state/farms/classic/updater.tsx @@ -3,7 +3,7 @@ import KNUpdater from 'state/farms/classic/knUpdater' import RPCUpdater from 'state/farms/classic/rpcUpdater' export default function Updater({ isInterval = true }: { isInterval?: boolean }) { - // const { isEnableKNProtocol } = useKyberSwapConfig() + // const { isEnableKNProtocol } = useKyberSwapConfig() // todo namgold: revert const isEnableKNProtocol = true return isEnableKNProtocol ? : } diff --git a/src/utils/numbers.ts b/src/utils/numbers.ts index 3ee371ed66..553e8c4099 100644 --- a/src/utils/numbers.ts +++ b/src/utils/numbers.ts @@ -125,6 +125,7 @@ type FormatOptions = { significantDigits?: number // usually for decimal style fallback?: string allowNegative?: boolean + allowZero?: boolean } interface RequiredFraction extends FormatOptions { fractionDigits: number // usually for percent & currency styles @@ -156,6 +157,7 @@ export const formatDisplayNumber = ( fractionDigits, fallback = '--', allowNegative = false, + allowZero = true, }: RequiredFraction | RequiredSignificant, ): string => { const currency = style === 'currency' ? '$' : '' @@ -165,6 +167,7 @@ export const formatDisplayNumber = ( if (value === undefined || value === null || Number.isNaN(value)) return fallbackResult const parsedFraction = parseNum(value) if (!allowNegative && parsedFraction.lessThan(BIG_INT_ZERO)) return fallbackResult + if (!allowZero && parsedFraction.equalTo(BIG_INT_ZERO)) return fallbackResult const shownFraction = style === 'percent' ? parsedFraction.multiply(100) : parsedFraction const absShownFraction = shownFraction.lessThan(0) ? shownFraction.multiply(-1) : shownFraction