From c0a91784124e56d090776c78cb35c28dc27fc52e Mon Sep 17 00:00:00 2001
From: Finnian Jacobson-Schulte
<140328381+finnian0826@users.noreply.github.com>
Date: Thu, 3 Oct 2024 06:52:49 +1300
Subject: [PATCH] fix(earn): Show correct pool amount when LP to deposit is not
1:1 (#6121)
### Description
Also fix TVL, now assume that TVL is always in USD (will add note in
hooks).
### Test plan
Manual test:
### Related issues
- Fixes ACT-1397
### Backwards compatibility
Yes
### Network scalability
If a new NetworkId and/or Network are added in the future, the changes
in this PR will:
- [X] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
---
src/earn/EarnPoolInfoScreen.test.tsx | 10 +++++-----
src/earn/EarnPoolInfoScreen.tsx | 13 +++++--------
src/earn/PoolCard.test.tsx | 2 +-
src/earn/PoolCard.tsx | 4 +---
4 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/src/earn/EarnPoolInfoScreen.test.tsx b/src/earn/EarnPoolInfoScreen.test.tsx
index a8dbd9a0556..b3772a5db9e 100644
--- a/src/earn/EarnPoolInfoScreen.test.tsx
+++ b/src/earn/EarnPoolInfoScreen.test.tsx
@@ -103,7 +103,7 @@ describe('EarnPoolInfoScreen', () => {
)
).toBeTruthy()
expect(within(getByTestId('TvlCard')).getByText('earnFlow.poolInfoScreen.tvl')).toBeTruthy()
- expect(within(getByTestId('TvlCard')).getByText('₱2,170,560.00')).toBeTruthy()
+ expect(within(getByTestId('TvlCard')).getByText('₱1,808,800.00')).toBeTruthy()
expect(
within(getByTestId('AgeCard')).getByText('duration, {"context":"month","count":5}')
).toBeTruthy()
@@ -142,7 +142,7 @@ describe('EarnPoolInfoScreen', () => {
).toBeTruthy()
expect(
within(getByTestId('DepositAndEarningsCard')).getByText(
- ' earnFlow.poolInfoScreen.titleLocalAmountDisplay, {"localCurrencySymbol":"₱","localCurrencyAmount":"154.28"}'
+ ' earnFlow.poolInfoScreen.titleLocalAmountDisplay, {"localCurrencySymbol":"₱","localCurrencyAmount":"180.88"}'
)
).toBeTruthy()
expect(
@@ -182,7 +182,7 @@ describe('EarnPoolInfoScreen', () => {
).toBeTruthy()
expect(
within(getByTestId('DepositAndEarningsCard')).getByText(
- ' earnFlow.poolInfoScreen.titleLocalAmountDisplay, {"localCurrencySymbol":"₱","localCurrencyAmount":"133.00"}'
+ ' earnFlow.poolInfoScreen.titleLocalAmountDisplay, {"localCurrencySymbol":"₱","localCurrencyAmount":"159.60"}'
)
).toBeTruthy()
expect(
@@ -219,7 +219,7 @@ describe('EarnPoolInfoScreen', () => {
).toBeTruthy()
expect(
within(getByTestId('DepositAndEarningsCard')).getByText(
- 'earnFlow.poolInfoScreen.titleLocalAmountDisplay, {"localCurrencySymbol":"₱","localCurrencyAmount":"152.95"}'
+ 'earnFlow.poolInfoScreen.titleLocalAmountDisplay, {"localCurrencySymbol":"₱","localCurrencyAmount":"179.55"}'
)
).toBeTruthy()
expect(
@@ -266,7 +266,7 @@ describe('EarnPoolInfoScreen', () => {
).toBeTruthy()
expect(
within(getByTestId('DepositAndEarningsCard')).getByText(
- 'earnFlow.poolInfoScreen.titleLocalAmountDisplay, {"localCurrencySymbol":"₱","localCurrencyAmount":"152.95"}'
+ 'earnFlow.poolInfoScreen.titleLocalAmountDisplay, {"localCurrencySymbol":"₱","localCurrencyAmount":"179.55"}'
)
).toBeTruthy()
expect(
diff --git a/src/earn/EarnPoolInfoScreen.tsx b/src/earn/EarnPoolInfoScreen.tsx
index 1c27b65b630..4980df0f7f6 100644
--- a/src/earn/EarnPoolInfoScreen.tsx
+++ b/src/earn/EarnPoolInfoScreen.tsx
@@ -153,14 +153,14 @@ function DepositAndEarningsCard({
onInfoIconPress: () => void
}) {
const { t } = useTranslation()
- const { balance } = earnPosition
+ const { balance, priceUsd, pricePerShare } = earnPosition
const { earningItems, depositTokenId, cantSeparateCompoundedInterest } = earnPosition.dataProps
const depositTokenInfo = useTokenInfo(depositTokenId)
const localCurrencySymbol = useSelector(getLocalCurrencySymbol)
const localCurrencyExchangeRate = useSelector(usdToLocalCurrencyRateSelector)
// Deposit items used to calculate the total balance and total deposited
- const depositBalanceInUsd = depositTokenInfo?.priceUsd?.multipliedBy(balance)
+ const depositBalanceInUsd = new BigNumber(priceUsd).multipliedBy(balance)
const depositBalanceInLocalCurrency = new BigNumber(localCurrencyExchangeRate ?? 0).multipliedBy(
depositBalanceInUsd ?? 0
)
@@ -190,7 +190,7 @@ function DepositAndEarningsCard({
])
const totalDepositBalanceInCrypto = useMemo(() => {
- return new BigNumber(balance).minus(
+ return new BigNumber(balance).multipliedBy(new BigNumber(pricePerShare[0]) ?? 1).minus(
earningItems
.filter((item) => item.includedInPoolBalance)
.reduce((acc, item) => {
@@ -202,7 +202,7 @@ function DepositAndEarningsCard({
)
}, new BigNumber(0))
)
- }, [balance, earningItems, earningItemsTokenInfo, depositTokenInfo])
+ }, [balance, pricePerShare, earningItems, earningItemsTokenInfo, depositTokenInfo])
const totalDepositBalanceInLocalCurrency =
useDollarsToLocalAmount(
@@ -328,10 +328,7 @@ function TvlCard({
const localCurrencySymbol = useSelector(getLocalCurrencySymbol)
const { t } = useTranslation()
const tvl = earnPosition.dataProps.tvl
- const priceUsd = earnPosition.priceUsd
- const tvlInFiat = useDollarsToLocalAmount(
- tvl ? new BigNumber(tvl).times(new BigNumber(priceUsd)) : null
- )
+ const tvlInFiat = useDollarsToLocalAmount(tvl ?? null)
const tvlString = useMemo(() => {
return `${localCurrencySymbol}${tvlInFiat ? formatValueToDisplay(tvlInFiat) : '--'}`
}, [localCurrencySymbol, tvlInFiat])
diff --git a/src/earn/PoolCard.test.tsx b/src/earn/PoolCard.test.tsx
index 08bd982900e..dd6f6f2c350 100644
--- a/src/earn/PoolCard.test.tsx
+++ b/src/earn/PoolCard.test.tsx
@@ -44,7 +44,7 @@ describe('PoolCard', () => {
getByText('earnFlow.poolCard.onNetwork, {"networkName":"Arbitrum Sepolia"}')
).toBeTruthy()
expect(getByText('earnFlow.poolCard.percentage, {"percentage":"1.92"}')).toBeTruthy()
- expect(getByText('₱2,170,560.00')).toBeTruthy()
+ expect(getByText('₱1,808,800.00')).toBeTruthy()
})
it('correct behavior when tapping pool card', () => {
diff --git a/src/earn/PoolCard.tsx b/src/earn/PoolCard.tsx
index 00bc5264c63..edc7be146f0 100644
--- a/src/earn/PoolCard.tsx
+++ b/src/earn/PoolCard.tsx
@@ -75,9 +75,7 @@ export default function PoolCard({
[localCurrencySymbol, poolBalanceInFiat, rewardAmountInFiat]
)
- const tvlInFiat = useDollarsToLocalAmount(
- tvl ? new BigNumber(tvl).times(new BigNumber(priceUsd)) : null
- )
+ const tvlInFiat = useDollarsToLocalAmount(tvl ?? null)
const tvlString = useMemo(() => {
return `${localCurrencySymbol}${tvlInFiat ? formatValueToDisplay(tvlInFiat) : '--'}`
}, [localCurrencySymbol, tvlInFiat])