From 9255af73b27e0af57cc8ef8e877fec410484624a Mon Sep 17 00:00:00 2001 From: Satish Ravi Date: Thu, 22 Aug 2024 15:41:03 -0700 Subject: [PATCH 1/6] refactor(earn): use earn position in deposit screen --- locales/base/translation.json | 1 + src/earn/EarnActivePool.test.tsx | 14 +++- src/earn/EarnActivePool.tsx | 6 +- src/earn/EarnApyAndAmount.tsx | 57 +++++--------- src/earn/EarnDepositBottomSheet.test.tsx | 51 ++++++------- src/earn/EarnDepositBottomSheet.tsx | 22 +++--- src/earn/EarnEnterAmount.test.tsx | 57 ++++++++++---- src/earn/EarnEnterAmount.tsx | 49 +++++++----- src/earn/EarnHome.test.tsx | 96 +----------------------- src/earn/EarnInfoScreen.test.tsx | 38 +++++++++- src/earn/EarnInfoScreen.tsx | 5 +- src/earn/PoolCard.test.tsx | 84 ++++++--------------- src/earn/PoolCard.tsx | 10 ++- src/earn/hooks.ts | 12 +++ src/earn/poolInfo.ts | 7 ++ src/navigator/types.tsx | 5 +- src/statsig/types.ts | 1 + test/values.ts | 96 +++++++++++++++++++++++- 18 files changed, 326 insertions(+), 285 deletions(-) diff --git a/locales/base/translation.json b/locales/base/translation.json index bbee5009c50..09d7170c051 100644 --- a/locales/base/translation.json +++ b/locales/base/translation.json @@ -2536,6 +2536,7 @@ "rate": "{{rate}}% APY", "continue": "Continue", "info": "This pool is powered by Aave", + "infoV1_93": "Powered by {{providerName}}", "infoBottomSheet": { "title": "Why this pool?", "description": "This Aave pool has over $150M TVL and more than 6,000 contributors, indicating strong liquidity and trustworthiness. It also uses USDC as its token and Arbitrum as its network, which reduces volatility and ensures users will receive inexpensive gas rates.\n\nAll together this makes it a safe and attractive option with competitive APY, ensuring a beneficial investment opportunity for our users.\n\nYou can explore other Aave pools <0>here.", diff --git a/src/earn/EarnActivePool.test.tsx b/src/earn/EarnActivePool.test.tsx index ec9ac7ccb54..4acea5d85a4 100644 --- a/src/earn/EarnActivePool.test.tsx +++ b/src/earn/EarnActivePool.test.tsx @@ -1,8 +1,8 @@ import { fireEvent, render } from '@testing-library/react-native' import React from 'react' import { Provider } from 'react-redux' -import { EarnEvents } from 'src/analytics/Events' import AppAnalytics from 'src/analytics/AppAnalytics' +import { EarnEvents } from 'src/analytics/Events' import EarnActivePool from 'src/earn/EarnActivePool' import { navigate } from 'src/navigator/NavigationService' import { Screens } from 'src/navigator/Screens' @@ -11,7 +11,7 @@ import { StatsigFeatureGates } from 'src/statsig/types' import { NetworkId } from 'src/transactions/types' import networkConfig from 'src/web3/networkConfig' import { createMockStore } from 'test/utils' -import { mockAaveArbUsdcAddress } from 'test/values' +import { mockAaveArbUsdcAddress, mockEarnPositions } from 'test/values' const store = createMockStore({ tokens: { @@ -27,6 +27,10 @@ const store = createMockStore({ }, }, }, + positions: { + positions: mockEarnPositions, + earnPositionIds: mockEarnPositions.map((position) => position.positionId), + }, }) jest.mock('src/statsig') @@ -34,7 +38,9 @@ jest.mock('src/statsig') describe('EarnActivePool', () => { beforeEach(() => { jest.clearAllMocks() - jest.mocked(getFeatureGate).mockReturnValue(false) + jest + .mocked(getFeatureGate) + .mockImplementation((gate) => gate === StatsigFeatureGates.SHOW_POSITIONS) }) it('should render correctly with ExitAndDeposit cta', () => { @@ -153,7 +159,7 @@ describe('EarnActivePool', () => { networkId: NetworkId['arbitrum-sepolia'], }) expect(navigate).toBeCalledWith(Screens.EarnEnterAmount, { - tokenId: networkConfig.arbUsdcTokenId, + pool: mockEarnPositions[0], }) }) }) diff --git a/src/earn/EarnActivePool.tsx b/src/earn/EarnActivePool.tsx index cb09b174020..e1e70f11177 100644 --- a/src/earn/EarnActivePool.tsx +++ b/src/earn/EarnActivePool.tsx @@ -1,12 +1,13 @@ import React, { useEffect } from 'react' import { useTranslation } from 'react-i18next' import { StyleSheet, Text, View } from 'react-native' -import { EarnEvents } from 'src/analytics/Events' import AppAnalytics from 'src/analytics/AppAnalytics' +import { EarnEvents } from 'src/analytics/Events' import Button, { BtnSizes, BtnTypes } from 'src/components/Button' import SkeletonPlaceholder from 'src/components/SkeletonPlaceholder' import TokenDisplay from 'src/components/TokenDisplay' import { PROVIDER_ID } from 'src/earn/constants' +import { useEarnPosition } from 'src/earn/hooks' import { poolInfoFetchStatusSelector, poolInfoSelector } from 'src/earn/selectors' import { fetchPoolInfo } from 'src/earn/slice' import { navigate } from 'src/navigator/NavigationService' @@ -50,6 +51,7 @@ export default function EarnActivePool({ depositTokenId, poolTokenId, cta }: Pro const poolToken = useTokenInfo(poolTokenId) const poolInfo = useSelector(poolInfoSelector) const poolInfoFetchStatus = useSelector(poolInfoFetchStatusSelector) + const earnPosition = useEarnPosition(poolTokenId) useEffect(() => { dispatch(fetchPoolInfo()) @@ -125,7 +127,7 @@ export default function EarnActivePool({ depositTokenId, poolTokenId, cta }: Pro providerId: PROVIDER_ID, networkId: poolToken.networkId, }) - navigate(Screens.EarnEnterAmount, { tokenId: depositTokenId }) + earnPosition && navigate(Screens.EarnEnterAmount, { pool: earnPosition }) }} text={t('earnFlow.activePools.depositMore')} type={BtnTypes.PRIMARY} diff --git a/src/earn/EarnApyAndAmount.tsx b/src/earn/EarnApyAndAmount.tsx index 8ae461d7e24..fa8f59ef1f7 100644 --- a/src/earn/EarnApyAndAmount.tsx +++ b/src/earn/EarnApyAndAmount.tsx @@ -1,41 +1,38 @@ import BigNumber from 'bignumber.js' -import React, { useEffect } from 'react' +import React from 'react' import { Trans, useTranslation } from 'react-i18next' import { StyleSheet, Text, View } from 'react-native' -import SkeletonPlaceholder from 'src/components/SkeletonPlaceholder' import TokenDisplay from 'src/components/TokenDisplay' import TokenIcon, { IconSize } from 'src/components/TokenIcon' -import { poolInfoFetchStatusSelector, poolInfoSelector } from 'src/earn/selectors' -import { fetchPoolInfo } from 'src/earn/slice' -import { useDispatch, useSelector } from 'src/redux/hooks' +import { getTotalYieldRate } from 'src/earn/poolInfo' +import { EarnPosition } from 'src/positions/types' import { Colors } from 'src/styles/colors' import { typeScale } from 'src/styles/fonts' import { Spacing } from 'src/styles/styles' -import { TokenBalance } from 'src/tokens/slice' +import { useTokenInfo } from 'src/tokens/hooks' export function EarnApyAndAmount({ tokenAmount, - token, + pool, testIDPrefix = 'Earn', }: { tokenAmount: BigNumber | null - token: TokenBalance + pool: EarnPosition testIDPrefix?: string }) { const { t } = useTranslation() - const dispatch = useDispatch() - const poolInfo = useSelector(poolInfoSelector) - const poolInfoFetchStatus = useSelector(poolInfoFetchStatusSelector) - useEffect(() => { - dispatch(fetchPoolInfo()) - }, []) + const apy = getTotalYieldRate(pool) + const token = useTokenInfo(pool.dataProps.depositTokenId) - const apy = poolInfo?.apy + if (!token) { + // should never happen + throw new Error(`Token not found ${pool.dataProps.depositTokenId}`) + } - const apyString = apy ? (apy * 100).toFixed(2) : '--' + const apyString = apy.toFixed(2) const earnUpTo = - apy && tokenAmount?.gt(0) ? tokenAmount.multipliedBy(new BigNumber(apy)) : new BigNumber(0) + apy && tokenAmount?.gt(0) ? tokenAmount.multipliedBy(apy).dividedBy(100) : new BigNumber(0) return ( <> @@ -57,21 +54,11 @@ export function EarnApyAndAmount({ - {poolInfoFetchStatus === 'loading' ? ( - - - - ) : ( - - {t('earnFlow.enterAmount.rate', { - rate: apyString, - })} - - )} + + {t('earnFlow.enterAmount.rate', { + rate: apyString, + })} + @@ -99,10 +86,4 @@ const styles = StyleSheet.create({ ...typeScale.labelSemiBoldSmall, marginVertical: Spacing.Tiny4, }, - loadingSkeleton: { - ...typeScale.labelSemiBoldSmall, - marginVertical: Spacing.Smallest8, - width: 100, - borderRadius: 100, - }, }) diff --git a/src/earn/EarnDepositBottomSheet.test.tsx b/src/earn/EarnDepositBottomSheet.test.tsx index e6f1f807763..029186bd023 100644 --- a/src/earn/EarnDepositBottomSheet.test.tsx +++ b/src/earn/EarnDepositBottomSheet.test.tsx @@ -2,19 +2,23 @@ import { fireEvent, render } from '@testing-library/react-native' import BigNumber from 'bignumber.js' import React from 'react' import { Provider } from 'react-redux' -import { EarnEvents } from 'src/analytics/Events' import AppAnalytics from 'src/analytics/AppAnalytics' +import { EarnEvents } from 'src/analytics/Events' import EarnDepositBottomSheet from 'src/earn/EarnDepositBottomSheet' -import { PROVIDER_ID } from 'src/earn/constants' -import { depositStart, fetchPoolInfo } from 'src/earn/slice' +import { depositStart } from 'src/earn/slice' import { navigate } from 'src/navigator/NavigationService' import { getDynamicConfigParams, getFeatureGate } from 'src/statsig' import { StatsigDynamicConfigs, StatsigFeatureGates } from 'src/statsig/types' import { NetworkId } from 'src/transactions/types' import { PreparedTransactionsPossible } from 'src/viem/prepareTransactions' import { getSerializablePreparedTransactions } from 'src/viem/preparedTransactionSerialization' -import { createMockStore, mockStoreBalancesToTokenBalances } from 'test/utils' -import { mockArbEthTokenId, mockTokenBalances } from 'test/values' +import { createMockStore } from 'test/utils' +import { + mockArbEthTokenId, + mockArbUsdcTokenId, + mockEarnPositions, + mockTokenBalances, +} from 'test/values' jest.mock('src/statsig') @@ -49,14 +53,12 @@ const mockPreparedTransaction: PreparedTransactionsPossible = { }, } -const mockToken = mockStoreBalancesToTokenBalances([mockTokenBalances[mockArbEthTokenId]])[0] - describe('EarnDepositBottomSheet', () => { const expectedAnalyticsProperties = { - depositTokenId: mockArbEthTokenId, + depositTokenId: mockArbUsdcTokenId, tokenAmount: '100', networkId: NetworkId['arbitrum-sepolia'], - providerId: PROVIDER_ID, + providerId: mockEarnPositions[0].appId, } beforeEach(() => { @@ -81,27 +83,25 @@ describe('EarnDepositBottomSheet', () => { ) expect(getByText('earnFlow.depositBottomSheet.title')).toBeTruthy() expect(getByText('earnFlow.depositBottomSheet.description')).toBeTruthy() - expect(getByTestId('EarnDepositBottomSheet/EarnApyAndAmount/Apy/Loading')).toBeTruthy() + expect(getByTestId('EarnDepositBottomSheet/EarnApyAndAmount/Apy')).toBeTruthy() expect(queryByTestId('EarnDeposit/GasSubsidized')).toBeFalsy() expect(getByText('earnFlow.depositBottomSheet.amount')).toBeTruthy() - expect(getByTestId('EarnDeposit/Amount')).toHaveTextContent('100.00 ETH') + expect(getByTestId('EarnDeposit/Amount')).toHaveTextContent('100.00 USDC') expect(getByText('earnFlow.depositBottomSheet.fee')).toBeTruthy() expect(getByTestId('EarnDeposit/Fee')).toHaveTextContent('0.06 ETH') @@ -127,8 +127,7 @@ describe('EarnDepositBottomSheet', () => { forwardedRef={{ current: null }} amount={new BigNumber(100)} preparedTransaction={mockPreparedTransaction} - token={mockToken} - networkId={NetworkId['arbitrum-sepolia']} + pool={mockEarnPositions[0]} /> ) @@ -139,14 +138,11 @@ describe('EarnDepositBottomSheet', () => { expectedAnalyticsProperties ) expect(store.getActions()).toEqual([ - { - type: fetchPoolInfo.type, - }, { type: depositStart.type, payload: { amount: '100', - tokenId: mockArbEthTokenId, + tokenId: mockArbUsdcTokenId, preparedTransactions: getSerializablePreparedTransactions( mockPreparedTransaction.transactions ), @@ -162,8 +158,7 @@ describe('EarnDepositBottomSheet', () => { forwardedRef={{ current: null }} amount={new BigNumber(100)} preparedTransaction={mockPreparedTransaction} - token={mockToken} - networkId={NetworkId['arbitrum-sepolia']} + pool={mockEarnPositions[0]} /> ) @@ -182,8 +177,7 @@ describe('EarnDepositBottomSheet', () => { forwardedRef={{ current: null }} amount={new BigNumber(100)} preparedTransaction={mockPreparedTransaction} - token={mockToken} - networkId={NetworkId['arbitrum-sepolia']} + pool={mockEarnPositions[0]} /> ) @@ -203,8 +197,7 @@ describe('EarnDepositBottomSheet', () => { forwardedRef={{ current: null }} amount={new BigNumber(100)} preparedTransaction={mockPreparedTransaction} - token={mockToken} - networkId={NetworkId['arbitrum-sepolia']} + pool={mockEarnPositions[0]} /> ) @@ -228,8 +221,7 @@ describe('EarnDepositBottomSheet', () => { forwardedRef={{ current: null }} amount={new BigNumber(100)} preparedTransaction={mockPreparedTransaction} - token={mockToken} - networkId={NetworkId['arbitrum-sepolia']} + pool={mockEarnPositions[0]} /> ) @@ -252,8 +244,7 @@ describe('EarnDepositBottomSheet', () => { forwardedRef={{ current: null }} amount={new BigNumber(100)} preparedTransaction={mockPreparedTransaction} - token={mockToken} - networkId={NetworkId['arbitrum-sepolia']} + pool={mockEarnPositions[0]} /> ) diff --git a/src/earn/EarnDepositBottomSheet.tsx b/src/earn/EarnDepositBottomSheet.tsx index b096f09ca90..ac4b61ea528 100644 --- a/src/earn/EarnDepositBottomSheet.tsx +++ b/src/earn/EarnDepositBottomSheet.tsx @@ -12,13 +12,13 @@ import Button, { BtnSizes, BtnTypes } from 'src/components/Button' import TokenDisplay from 'src/components/TokenDisplay' import Touchable from 'src/components/Touchable' import { EarnApyAndAmount } from 'src/earn/EarnApyAndAmount' -import { PROVIDER_ID } from 'src/earn/constants' import { depositStatusSelector } from 'src/earn/selectors' import { depositStart } from 'src/earn/slice' import InfoIcon from 'src/icons/InfoIcon' import Logo from 'src/icons/Logo' import { navigate } from 'src/navigator/NavigationService' import { Screens } from 'src/navigator/Screens' +import { EarnPosition } from 'src/positions/types' import { useSelector } from 'src/redux/hooks' import { NETWORK_NAMES } from 'src/shared/conts' import { getDynamicConfigParams, getFeatureGate } from 'src/statsig' @@ -27,8 +27,6 @@ import { StatsigDynamicConfigs, StatsigFeatureGates } from 'src/statsig/types' import Colors from 'src/styles/colors' import { typeScale } from 'src/styles/fonts' import { Shadow, Spacing, getShadowStyle } from 'src/styles/styles' -import { TokenBalance } from 'src/tokens/slice' -import { NetworkId } from 'src/transactions/types' import { PreparedTransactionsPossible, getFeeCurrencyAndAmounts, @@ -41,14 +39,12 @@ export default function EarnDepositBottomSheet({ forwardedRef, preparedTransaction, amount, - token, - networkId, + pool, }: { forwardedRef: RefObject preparedTransaction: PreparedTransactionsPossible amount: BigNumber - token: TokenBalance - networkId: NetworkId + pool: EarnPosition }) { const { t } = useTranslation() const dispatch = useDispatch() @@ -56,10 +52,10 @@ export default function EarnDepositBottomSheet({ const transactionSubmitted = depositStatus === 'loading' const commonAnalyticsProperties = { - providerId: PROVIDER_ID, - depositTokenId: token.tokenId, + providerId: pool.appId, + depositTokenId: pool.dataProps.depositTokenId, tokenAmount: amount.toString(), - networkId, + networkId: pool.networkId, } const { estimatedFeeAmount, feeCurrency } = getFeeCurrencyAndAmounts(preparedTransaction) @@ -94,7 +90,7 @@ export default function EarnDepositBottomSheet({ dispatch( depositStart({ amount: amount.toString(), - tokenId: token.tokenId, + tokenId: pool.dataProps.depositTokenId, preparedTransactions: getSerializablePreparedTransactions(preparedTransaction.transactions), }) ) @@ -115,7 +111,7 @@ export default function EarnDepositBottomSheet({ @@ -123,7 +119,7 @@ export default function EarnDepositBottomSheet({ diff --git a/src/earn/EarnEnterAmount.test.tsx b/src/earn/EarnEnterAmount.test.tsx index cb8b7d3f94d..c3fdfdd2839 100644 --- a/src/earn/EarnEnterAmount.test.tsx +++ b/src/earn/EarnEnterAmount.test.tsx @@ -3,20 +3,30 @@ import BigNumber from 'bignumber.js' import React from 'react' import { getNumberFormatSettings } from 'react-native-localize' import { Provider } from 'react-redux' -import { EarnEvents } from 'src/analytics/Events' import AppAnalytics from 'src/analytics/AppAnalytics' +import { EarnEvents } from 'src/analytics/Events' import EarnEnterAmount from 'src/earn/EarnEnterAmount' import { usePrepareSupplyTransactions } from 'src/earn/prepareTransactions' +import { getDynamicConfigParams, getFeatureGate, getMultichainFeatures } from 'src/statsig' +import { DynamicConfigs } from 'src/statsig/constants' +import { StatsigFeatureGates, StatsigMultiNetworkDynamicConfig } from 'src/statsig/types' import { TokenBalance } from 'src/tokens/slice' import { NetworkId } from 'src/transactions/types' import { PreparedTransactionsPossible } from 'src/viem/prepareTransactions' import networkConfig from 'src/web3/networkConfig' import MockedNavigator from 'test/MockedNavigator' import { createMockStore } from 'test/utils' -import { mockAccount, mockArbEthTokenId, mockTokenBalances } from 'test/values' +import { + mockAccount, + mockArbEthTokenId, + mockArbUsdcTokenId, + mockEarnPositions, + mockTokenBalances, +} from 'test/values' jest.mock('src/earn/prepareTransactions') jest.mock('react-native-localize') +jest.mock('src/statsig') const mockPreparedTransaction: PreparedTransactionsPossible = { type: 'possible' as const, @@ -64,8 +74,8 @@ const priceFetchedAt = Date.now() const store = createMockStore({ tokens: { tokenBalances: { - [networkConfig.arbUsdcTokenId]: { - tokenId: networkConfig.arbUsdcTokenId, + [mockArbUsdcTokenId]: { + tokenId: mockArbUsdcTokenId, symbol: 'USDC', priceUsd: '1', priceFetchedAt: priceFetchedAt, @@ -91,7 +101,7 @@ jest.mocked(usePrepareSupplyTransactions).mockReturnValue({ }) const params = { - tokenId: networkConfig.arbUsdcTokenId, + pool: mockEarnPositions[0], } describe('EarnEnterAmount', () => { @@ -101,6 +111,15 @@ describe('EarnEnterAmount', () => { .mocked(getNumberFormatSettings) .mockReturnValue({ decimalSeparator: '.', groupingSeparator: ',' }) store.clearActions() + jest + .mocked(getFeatureGate) + .mockImplementation((gate) => gate === StatsigFeatureGates.SHOW_MULTIPLE_EARN_POOLS) + jest.mocked(getDynamicConfigParams).mockImplementation(({ defaultValues }) => defaultValues) + jest + .mocked(getMultichainFeatures) + .mockReturnValue( + DynamicConfigs[StatsigMultiNetworkDynamicConfig.MULTI_CHAIN_FEATURES].defaultValues + ) }) it('should render APY and EarnUpTo', async () => { @@ -109,11 +128,14 @@ describe('EarnEnterAmount', () => { ) - // Loading states - expect(getByTestId('EarnEnterAmount/EarnApyAndAmount/Apy/Loading')).toBeTruthy() + expect(getByTestId('EarnEnterAmount/EarnApyAndAmount/Apy')).toBeTruthy() + expect(getByTestId('EarnEnterAmount/EarnApyAndAmount/Apy')).toHaveTextContent( + 'earnFlow.enterAmount.rate, {"rate":"1.92"}' + ) }) - it('should be able to tap info icon', async () => { + it('should be able to tap info icon (for single pool)', async () => { + jest.mocked(getFeatureGate).mockReturnValue(false) const { getByTestId } = render( @@ -124,6 +146,15 @@ describe('EarnEnterAmount', () => { expect(AppAnalytics.track).toHaveBeenCalledWith(EarnEvents.earn_enter_amount_info_press) }) + it('hides info icon for multiple pools', async () => { + const { queryByTestId } = render( + + + + ) + expect(queryByTestId('EarnEnterAmount/InfoIcon')).toBeNull() + }) + it('should prepare transactions with the expected inputs', async () => { const { getByTestId } = render( @@ -137,7 +168,7 @@ describe('EarnEnterAmount', () => { expect(refreshPreparedTransactionsSpy).toHaveBeenCalledWith({ amount: '0.25', token: { - tokenId: networkConfig.arbUsdcTokenId, + tokenId: mockArbUsdcTokenId, symbol: 'USDC', priceUsd: new BigNumber(1), lastKnownPriceUsd: new BigNumber(1), @@ -176,7 +207,7 @@ describe('EarnEnterAmount', () => { amountInUsd: '8.00', networkId: NetworkId['arbitrum-sepolia'], tokenAmount: '8', - depositTokenId: networkConfig.arbUsdcTokenId, + depositTokenId: mockArbUsdcTokenId, userHasFunds: true, providerId: 'aave-v3', }) @@ -207,7 +238,7 @@ describe('EarnEnterAmount', () => { amountInUsd: '12.00', networkId: NetworkId['arbitrum-sepolia'], tokenAmount: '12', - depositTokenId: networkConfig.arbUsdcTokenId, + depositTokenId: mockArbUsdcTokenId, userHasFunds: false, providerId: 'aave-v3', }) @@ -263,8 +294,8 @@ describe('EarnEnterAmount', () => { const mockStore = createMockStore({ tokens: { tokenBalances: { - [networkConfig.arbUsdcTokenId]: { - tokenId: networkConfig.arbUsdcTokenId, + [mockArbUsdcTokenId]: { + tokenId: mockArbUsdcTokenId, symbol: 'USDC', priceUsd: '1', priceFetchedAt: priceFetchedAt, diff --git a/src/earn/EarnEnterAmount.tsx b/src/earn/EarnEnterAmount.tsx index c879f5a1430..2e6acf8da3f 100644 --- a/src/earn/EarnEnterAmount.tsx +++ b/src/earn/EarnEnterAmount.tsx @@ -4,10 +4,11 @@ import BigNumber from 'bignumber.js' import React, { useEffect, useMemo, useRef, useState } from 'react' import { Trans, useTranslation } from 'react-i18next' import { TextInput as RNTextInput, StyleSheet, Text, TouchableOpacity, View } from 'react-native' +import FastImage from 'react-native-fast-image' import { getNumberFormatSettings } from 'react-native-localize' import { SafeAreaView } from 'react-native-safe-area-context' -import { EarnEvents, SendEvents } from 'src/analytics/Events' import AppAnalytics from 'src/analytics/AppAnalytics' +import { EarnEvents, SendEvents } from 'src/analytics/Events' import BackButton from 'src/components/BackButton' import BottomSheet, { BottomSheetRefType } from 'src/components/BottomSheet' import Button, { BtnSizes, BtnTypes } from 'src/components/Button' @@ -29,13 +30,14 @@ import { getLocalCurrencySymbol } from 'src/localCurrency/selectors' import { navigate } from 'src/navigator/NavigationService' import { Screens } from 'src/navigator/Screens' import { StackParamList } from 'src/navigator/types' +import { EarnPosition } from 'src/positions/types' import { useSelector } from 'src/redux/hooks' import { AmountInput, ProceedArgs } from 'src/send/EnterAmount' import { AmountEnteredIn } from 'src/send/types' import { NETWORK_NAMES } from 'src/shared/conts' -import { getDynamicConfigParams } from 'src/statsig' +import { getDynamicConfigParams, getFeatureGate } from 'src/statsig' import { DynamicConfigs } from 'src/statsig/constants' -import { StatsigDynamicConfigs } from 'src/statsig/types' +import { StatsigDynamicConfigs, StatsigFeatureGates } from 'src/statsig/types' import Colors from 'src/styles/colors' import { typeScale } from 'src/styles/fonts' import { Spacing } from 'src/styles/styles' @@ -62,16 +64,17 @@ type ProceedComponentProps = Omit & { disabled: boolean tokenAmount: BigNumber | null loading: boolean + pool: EarnPosition } function EarnEnterAmount({ route }: Props) { const { t } = useTranslation() - const { tokenId } = route.params - const token = useTokenInfo(tokenId) + const { pool } = route.params + const token = useTokenInfo(pool.dataProps.depositTokenId) if (!token) { - throw new Error(`Token info not found for token ID ${tokenId}`) + throw new Error(`Token info not found for token ID ${pool.dataProps.depositTokenId}`) } const infoBottomSheetRef = useRef(null) @@ -366,6 +369,7 @@ function EarnEnterAmount({ route }: Props) { onPressInfo={onPressInfo} disabled={disabled} loading={isPreparingTransactions} + pool={pool} /> @@ -380,8 +384,7 @@ function EarnEnterAmount({ route }: Props) { forwardedRef={reviewBottomSheetRef} preparedTransaction={prepareTransactionsResult} amount={tokenAmount} - token={token} - networkId={token.networkId} + pool={pool} /> )} @@ -397,12 +400,14 @@ function EarnProceed({ onPressProceed, onPressInfo, loading, + pool, }: ProceedComponentProps) { const { t } = useTranslation() + const showMultiplePools = getFeatureGate(StatsigFeatureGates.SHOW_MULTIPLE_EARN_POOLS) return ( - +