Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
finnian0826 committed Oct 14, 2024
1 parent cf6c66c commit d1ccd77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/earn/EarnActivePools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AppAnalytics from 'src/analytics/AppAnalytics'
import { EarnEvents } from 'src/analytics/Events'
import { formatValueToDisplay } from 'src/components/TokenDisplay'
import Touchable from 'src/components/Touchable'
import { useEarnPositionBalanceValues } from 'src/earn/hooks'
import { EarnTabType } from 'src/earn/types'
import { useDollarsToLocalAmount } from 'src/localCurrency/hooks'
import { getLocalCurrencySymbol } from 'src/localCurrency/selectors'
Expand All @@ -26,13 +27,12 @@ export default function EarnActivePools() {
() => pools.filter((pool) => new BigNumber(pool.balance).gt(0)).length,
[pools]
)
const totalSuppliedValueUsd = useMemo(
() =>
pools.reduce(
(acc, pool) => acc.plus(new BigNumber(pool.balance).times(new BigNumber(pool.priceUsd))),
new BigNumber(0) ?? null
),
[pools]
const totalSuppliedValueUsd = pools.reduce(
(acc, pool) => {
const { poolBalanceInUsd } = useEarnPositionBalanceValues({ pool })

Check failure on line 32 in src/earn/EarnActivePools.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook "useEarnPositionBalanceValues" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function
return acc.plus(poolBalanceInUsd)
},
new BigNumber(0) ?? null
)
const totalSuppliedValue = useDollarsToLocalAmount(totalSuppliedValueUsd)
const totalSupplied = useMemo(
Expand Down
13 changes: 13 additions & 0 deletions src/earn/hooks.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import BigNumber from 'bignumber.js'
import { useEarnPositionBalanceValues } from 'src/earn/hooks'
import { mockEarnPositions } from 'test/values'

describe('useEarnPositionBalanceValues', () => {
it('should return the correct USD and depositToken crypto balances for a pool', () => {
const { poolBalanceInUsd, poolBalanceInDepositToken } = useEarnPositionBalanceValues({
pool: { ...mockEarnPositions[0], balance: '100' },
})
expect(poolBalanceInUsd).toEqual(new BigNumber(120))
expect(poolBalanceInDepositToken).toEqual(new BigNumber(110))
})
})

0 comments on commit d1ccd77

Please sign in to comment.