diff --git a/src/fiatExchanges/saga.test.ts b/src/fiatExchanges/saga.test.ts index af3cfcae488..403b4ecf3ee 100644 --- a/src/fiatExchanges/saga.test.ts +++ b/src/fiatExchanges/saga.test.ts @@ -27,10 +27,10 @@ import Logger from 'src/utils/Logger' import { Currency } from 'src/utils/currencies' import { mockAccount, - mockCusdAddress, - mockCusdTokenId, mockCeurAddress, mockCeurTokenId, + mockCusdAddress, + mockCusdTokenId, } from 'test/values' const now = Date.now() @@ -105,7 +105,7 @@ describe(watchBidaliPaymentRequests, () => { } ) ) - .dispatch(sendPaymentSuccess(amount)) + .dispatch(sendPaymentSuccess({ amount, tokenId: expectedTokenId })) .run() expect(navigate).toHaveBeenCalledWith(Screens.SendConfirmationModal, { diff --git a/src/send/actions.ts b/src/send/actions.ts index 8623695e21b..45a6d6e55d0 100644 --- a/src/send/actions.ts +++ b/src/send/actions.ts @@ -49,6 +49,7 @@ export interface SendPaymentAction { export interface SendPaymentSuccessAction { type: Actions.SEND_PAYMENT_SUCCESS amount: BigNumber + tokenId: string } export interface SendPaymentFailureAction { @@ -113,9 +114,16 @@ export const sendPayment = ( feeInfo, }) -export const sendPaymentSuccess = (amount: BigNumber): SendPaymentSuccessAction => ({ +export const sendPaymentSuccess = ({ + amount, + tokenId, +}: { + amount: BigNumber + tokenId: string +}): SendPaymentSuccessAction => ({ type: Actions.SEND_PAYMENT_SUCCESS, amount, + tokenId, }) export const sendPaymentFailure = (): SendPaymentFailureAction => ({ diff --git a/src/send/reducers.ts b/src/send/reducers.ts index 9f7f9956c08..bc8bab46531 100644 --- a/src/send/reducers.ts +++ b/src/send/reducers.ts @@ -65,8 +65,7 @@ export const sendReducer = ( ...state, isSending: false, recentPayments: [...paymentsLast24Hours, latestPayment], - // TODO(satish): set lastUsedToken once this is available in the send flow (after - // #4306 is merged) + lastUsedTokenId: action.tokenId, } case Actions.SEND_PAYMENT_FAILURE: return { diff --git a/src/send/saga.ts b/src/send/saga.ts index e915fcc4d44..85840de8a48 100644 --- a/src/send/saga.ts +++ b/src/send/saga.ts @@ -27,9 +27,9 @@ import { StatsigFeatureGates } from 'src/statsig/types' import { getERC20TokenContract, getStableTokenContract, + getTokenInfo, getTokenInfoByAddress, tokenAmountInSmallestUnit, - getTokenInfo, } from 'src/tokens/saga' import { TokenBalance } from 'src/tokens/slice' import { getTokenId } from 'src/tokens/utils' @@ -298,7 +298,7 @@ export function* sendPaymentSaga({ navigateHome() } - yield* put(sendPaymentSuccess(amount)) + yield* put(sendPaymentSuccess({ amount, tokenId })) SentryTransactionHub.finishTransaction(SentryTransaction.send_payment) } catch (e) { yield* put(showErrorOrFallback(e, ErrorMessages.SEND_PAYMENT_FAILED)) diff --git a/src/tokens/TokenDetails.test.tsx b/src/tokens/TokenDetails.test.tsx index bc622e9130a..79a6c7fb6dd 100644 --- a/src/tokens/TokenDetails.test.tsx +++ b/src/tokens/TokenDetails.test.tsx @@ -6,7 +6,7 @@ import { CICOFlow } from 'src/fiatExchanges/utils' import { navigate } from 'src/navigator/NavigationService' import { Screens } from 'src/navigator/Screens' import TokenDetailsScreen from 'src/tokens/TokenDetails' -import { Network } from 'src/transactions/types' +import { Network, NetworkId } from 'src/transactions/types' import { CiCoCurrency } from 'src/utils/currencies' import { ONE_DAY_IN_MILLIS } from 'src/utils/time' import MockedNavigator from 'test/MockedNavigator' @@ -14,6 +14,7 @@ import { createMockStore } from 'test/utils' import { exchangePriceHistory, mockCeloTokenId, + mockEthTokenId, mockPoofTokenId, mockTokenBalances, } from 'test/values' @@ -21,9 +22,9 @@ import { jest.mock('src/statsig', () => ({ getDynamicConfigParams: jest.fn(() => { return { - showCico: ['celo-alfajores'], - showSend: ['celo-alfajores'], - showSwap: ['celo-alfajores'], + showCico: ['celo-alfajores', 'ethereum-sepolia'], + showSend: ['celo-alfajores', 'ethereum-sepolia'], + showSwap: ['celo-alfajores', 'ethereum-sepolia'], } }), })) @@ -372,4 +373,41 @@ describe('TokenDetails', () => { expect(navigate).toHaveBeenCalledWith(Screens.WithdrawSpend) expect(ValoraAnalytics.track).toHaveBeenCalledTimes(5) // 4 actions + 1 more action }) + + // TODO(ACT-954): remove once we switch to passing just token ids, above test + // should be sufficient + it('add action sends appropriate network', async () => { + const store = createMockStore({ + tokens: { + tokenBalances: { + [mockEthTokenId]: { + symbol: 'ETH', + balance: '0', + showZeroBalance: true, + isCashInEligible: true, + tokenId: mockEthTokenId, + networkId: NetworkId['ethereum-sepolia'], + }, + }, + }, + app: { + showSwapMenuInDrawerMenu: true, + }, + }) + + const { getByTestId } = render( + + + + ) + + fireEvent.press(getByTestId('TokenDetails/Action/Add')) + expect(navigate).toHaveBeenCalledWith(Screens.FiatExchangeAmount, { + currency: CiCoCurrency.ETH, + tokenId: mockEthTokenId, + flow: CICOFlow.CashIn, + network: Network.Ethereum, + }) + expect(ValoraAnalytics.track).toHaveBeenCalledTimes(1) + }) }) diff --git a/src/tokens/TokenDetails.tsx b/src/tokens/TokenDetails.tsx index 990fa30d8ee..aa089133a72 100644 --- a/src/tokens/TokenDetails.tsx +++ b/src/tokens/TokenDetails.tsx @@ -47,7 +47,7 @@ import { import { TokenBalance } from 'src/tokens/slice' import { TokenDetailsAction, TokenDetailsActionName } from 'src/tokens/types' import { getTokenAnalyticsProps, isCicoToken, isHistoricalPriceUpdated } from 'src/tokens/utils' -import { Network } from 'src/transactions/types' +import { networkIdToNetwork } from 'src/web3/networkConfig' type Props = NativeStackScreenProps @@ -194,10 +194,11 @@ export const useActions = (token: TokenBalance) => { // token is CiCoCurrency, but adding it here to ensure type safety if (isCicoToken(tokenSymbol)) { navigate(Screens.FiatExchangeAmount, { + // TODO(ACT-954): only pass token id currency: tokenSymbol, tokenId: token.tokenId, flow: CICOFlow.CashIn, - network: Network.Celo, // TODO (ACT-954): use networkId from token + network: networkIdToNetwork[token.networkId], }) } },