From b62602d63788a54546010ad99c5d519946a09ed0 Mon Sep 17 00:00:00 2001 From: Satish Ravi Date: Mon, 11 Mar 2024 13:00:24 -0700 Subject: [PATCH 1/2] feat(home): remove cash in bottom sheet --- e2e/src/usecases/Assets.js | 8 +- e2e/src/usecases/FiatConnectTransferOut.js | 2 - e2e/src/usecases/NewAccountOnboarding.js | 3 - .../usecases/NewAccountPhoneVerification.js | 2 - e2e/src/utils/retries.js | 4 +- e2e/src/utils/utils.js | 10 - src/app/reducers.ts | 3 - src/app/saga.ts | 1 - src/firebase/firebase.ts | 1 - .../remoteConfigValuesDefaults.e2e.ts | 1 - src/firebase/remoteConfigValuesDefaults.ts | 1 - src/home/CashInBottomSheet.test.tsx | 123 ----------- src/home/CashInBottomSheet.tsx | 205 ------------------ src/home/WalletHome.test.tsx | 174 +-------------- src/home/WalletHome.tsx | 54 +---- .../CashInBottomSheet.test.tsx.snap | 34 --- src/redux/migrations.ts | 4 + src/redux/store.test.ts | 3 +- src/redux/store.ts | 2 +- test/RootStateSchema.json | 4 - test/schemas.ts | 11 +- test/values.ts | 1 - 22 files changed, 22 insertions(+), 629 deletions(-) delete mode 100644 src/home/CashInBottomSheet.test.tsx delete mode 100644 src/home/CashInBottomSheet.tsx delete mode 100644 src/home/__snapshots__/CashInBottomSheet.test.tsx.snap diff --git a/e2e/src/usecases/Assets.js b/e2e/src/usecases/Assets.js index 2190e926be6..ed300228776 100644 --- a/e2e/src/usecases/Assets.js +++ b/e2e/src/usecases/Assets.js @@ -1,12 +1,7 @@ import { generateMnemonic } from '@celo/cryptographic-utils' import { DEFAULT_RECIPIENT_ADDRESS, SAMPLE_BACKUP_KEY } from '../utils/consts' import { launchApp } from '../utils/retries' -import { - quickOnboarding, - waitForElementByIdAndTap, - waitForElementId, - dismissCashInBottomSheet, -} from '../utils/utils' +import { quickOnboarding, waitForElementByIdAndTap, waitForElementId } from '../utils/utils' async function validateSendFlow(tokenSymbol) { // navigate to send amount screen to ensure the expected token symbol is pre-selected @@ -86,7 +81,6 @@ export default Assets = () => { mnemonic = await generateMnemonic() } await quickOnboarding(mnemonic) - await dismissCashInBottomSheet() }) it('navigates to Assets screen from home', async () => { diff --git a/e2e/src/usecases/FiatConnectTransferOut.js b/e2e/src/usecases/FiatConnectTransferOut.js index 54175e7f80c..68b8f7039ab 100644 --- a/e2e/src/usecases/FiatConnectTransferOut.js +++ b/e2e/src/usecases/FiatConnectTransferOut.js @@ -4,7 +4,6 @@ import fetch from 'node-fetch' import { MOCK_PROVIDER_API_KEY, MOCK_PROVIDER_BASE_URL } from 'react-native-dotenv' import { SAMPLE_PRIVATE_KEY } from '../utils/consts' import { - dismissCashInBottomSheet, enterPinUiIfNecessary, fundWallet, quickOnboarding, @@ -63,7 +62,6 @@ async function submitTransfer(expectZeroBalance = false) { // WalletHome if (expectZeroBalance) { - await dismissCashInBottomSheet() } await expect(element(by.id('HomeAction-Send'))).toBeVisible() // proxy for reaching home screen, imitating NewAccountOnboarding e2e test } diff --git a/e2e/src/usecases/NewAccountOnboarding.js b/e2e/src/usecases/NewAccountOnboarding.js index a84fe873113..e9fed752176 100644 --- a/e2e/src/usecases/NewAccountOnboarding.js +++ b/e2e/src/usecases/NewAccountOnboarding.js @@ -3,7 +3,6 @@ import { EXAMPLE_NAME } from '../utils/consts' import { launchApp } from '../utils/retries' import { completeProtectWalletScreen, - dismissCashInBottomSheet, enterPinUi, quickOnboarding, scrollIntoView, @@ -28,7 +27,6 @@ const quickEducation = async () => { const arriveAtHomeScreen = async () => { // Arrived to Home screen - await dismissCashInBottomSheet() await expect(element(by.id('HomeAction-Send'))).toBeVisible() } @@ -117,7 +115,6 @@ export default NewAccountOnboarding = () => { .withTimeout(10 * 1000) // Navigated to Home screen - await dismissCashInBottomSheet() await waitFor(element(by.id('HomeAction-Send'))) .toBeVisible() .withTimeout(10 * 1000) diff --git a/e2e/src/usecases/NewAccountPhoneVerification.js b/e2e/src/usecases/NewAccountPhoneVerification.js index 096542c2eed..004aaa7f7c7 100644 --- a/e2e/src/usecases/NewAccountPhoneVerification.js +++ b/e2e/src/usecases/NewAccountPhoneVerification.js @@ -7,7 +7,6 @@ import { EXAMPLE_NAME, EXAMPLE_PHONE_NUMBER } from '../utils/consts' import { launchApp } from '../utils/retries' import { checkBalance, receiveSms } from '../utils/twilio' import { - dismissCashInBottomSheet, enterPinUi, scrollIntoView, sleep, @@ -179,7 +178,6 @@ export default NewAccountPhoneVerification = () => { await element(by.text('Skip')).tap() // Assert we've arrived at the home screen - await dismissCashInBottomSheet() await waitForElementId('HomeAction-Send') // Assert that 'Connect phone number' is present in settings diff --git a/e2e/src/utils/retries.js b/e2e/src/utils/retries.js index b27fdc6fd97..ca685435c6f 100644 --- a/e2e/src/utils/retries.js +++ b/e2e/src/utils/retries.js @@ -1,5 +1,4 @@ import { retry } from 'ts-retry-promise' -import { dismissCashInBottomSheet } from './utils' export const launchApp = async ( launchArgs = { @@ -25,7 +24,7 @@ export const launchApp = async ( }) } -export const reloadReactNative = async (dismissBottomSheet = true) => { +export const reloadReactNative = async () => { await retry( async () => { try { @@ -38,5 +37,4 @@ export const reloadReactNative = async (dismissBottomSheet = true) => { }, { retries: 5, delay: 10 * 1000, timeout: 30 * 10000 } ) - if (dismissBottomSheet) await dismissCashInBottomSheet() } diff --git a/e2e/src/utils/utils.js b/e2e/src/utils/utils.js index e39c24cb603..9b925967f45 100644 --- a/e2e/src/utils/utils.js +++ b/e2e/src/utils/utils.js @@ -214,7 +214,6 @@ export async function quickOnboarding(mnemonic = SAMPLE_BACKUP_KEY) { } // Assert on Wallet Home Screen - await dismissCashInBottomSheet() await expect(element(by.id('HomeAction-Send'))).toBeVisible() } catch {} // Don't throw an error just silently continue } @@ -342,15 +341,6 @@ export async function confirmTransaction(commentText) { } } -export async function dismissCashInBottomSheet() { - try { - await waitFor(element(by.id('CashInBottomSheet'))) - .toBeVisible() - .withTimeout(15 * 1000) - await element(by.id('DismissBottomSheet')).tap() - } catch {} -} - export async function waitForElementByText(text, timeout = 30_000, index = 0) { try { index === 0 diff --git a/src/app/reducers.ts b/src/app/reducers.ts index bfde29e3746..715e509b294 100644 --- a/src/app/reducers.ts +++ b/src/app/reducers.ts @@ -31,7 +31,6 @@ interface State { googleMobileServicesAvailable?: boolean huaweiMobileServicesAvailable?: boolean pincodeUseExpandedBlocklist: boolean - rampCashInButtonExpEnabled: boolean sentryTracesSampleRate: number sentryNetworkErrors: string[] supportedBiometryType: BIOMETRY_TYPE | null @@ -81,7 +80,6 @@ const initialState = { googleMobileServicesAvailable: undefined, huaweiMobileServicesAvailable: undefined, pincodeUseExpandedBlocklist: REMOTE_CONFIG_VALUES_DEFAULTS.pincodeUseExpandedBlocklist, - rampCashInButtonExpEnabled: REMOTE_CONFIG_VALUES_DEFAULTS.rampCashInButtonExpEnabled, sentryTracesSampleRate: REMOTE_CONFIG_VALUES_DEFAULTS.sentryTracesSampleRate, sentryNetworkErrors: REMOTE_CONFIG_VALUES_DEFAULTS.sentryNetworkErrors.split(','), supportedBiometryType: null, @@ -204,7 +202,6 @@ export const appReducer = ( superchargeTokenConfigByToken: action.configValues.superchargeTokenConfigByToken, logPhoneNumberTypeEnabled: action.configValues.logPhoneNumberTypeEnabled, pincodeUseExpandedBlocklist: action.configValues.pincodeUseExpandedBlocklist, - rampCashInButtonExpEnabled: action.configValues.rampCashInButtonExpEnabled, sentryTracesSampleRate: action.configValues.sentryTracesSampleRate, sentryNetworkErrors: action.configValues.sentryNetworkErrors, skipVerification: action.configValues.skipVerification, diff --git a/src/app/saga.ts b/src/app/saga.ts index 27c5b6cde47..2ee42de4b1a 100644 --- a/src/app/saga.ts +++ b/src/app/saga.ts @@ -224,7 +224,6 @@ export interface RemoteConfigValues { superchargeApy: number superchargeTokenConfigByToken: SuperchargeTokenConfigByToken pincodeUseExpandedBlocklist: boolean - rampCashInButtonExpEnabled: boolean allowOtaTranslations: boolean sentryTracesSampleRate: number sentryNetworkErrors: string[] diff --git a/src/firebase/firebase.ts b/src/firebase/firebase.ts index 4b638850703..71d7329d61f 100644 --- a/src/firebase/firebase.ts +++ b/src/firebase/firebase.ts @@ -323,7 +323,6 @@ export async function fetchRemoteConfigValues(): Promise { - const mockFetch = fetch as FetchMock - - beforeEach(() => { - jest.clearAllMocks() - mockFetch.resetMocks() - }) - - it('renders correctly', () => { - const tree = render( - - - - ) - expect(tree).toMatchSnapshot() - }) - - it('navigates to the add funds page when the add funds button is clicked', async () => { - mockFetch.mockResponse(JSON.stringify([mockRampProvider])) - const { getByTestId } = render( - - - - ) - await act(() => { - jest.runOnlyPendingTimers() - }) - - await waitFor(() => expect(getByTestId('cashInBtn')).toBeTruthy()) - - fireEvent.press(getByTestId('cashInBtn')) - expect(navigate).toHaveBeenCalledWith(Screens.FiatExchangeCurrencyBottomSheet, { - flow: FiatExchangeFlow.CashIn, - }) - }) - - it.each` - rampCondition | providerResponse | rampCashInButtonExpEnabled - ${'does not have cash in'} | ${[mockRampProviderNoCashIn]} | ${true} - ${'is restricted'} | ${[mockRampProviderRestricted]} | ${true} - ${'is unavailable'} | ${[mockRampProviderUnavailable]} | ${true} - ${'is available but experiment is disabled'} | ${[mockRampProvider]} | ${false} - `( - 'Regular Version is visible when ramp $rampCondition', - async ({ providerResponse, rampCashInButtonExpEnabled }) => { - mockFetch.mockResponse(JSON.stringify(providerResponse)) - const { getByTestId } = render( - - - - ) - await act(() => { - jest.runOnlyPendingTimers() - }) - - await waitFor(() => expect(getByTestId('cashInBtn')).toBeTruthy()) - } - ) - - it('Ramp Version: navigates to ramp when add funds button is clicked', async () => { - mockFetch.mockResponse(JSON.stringify([mockRampProvider])) - const { getByTestId } = render( - - - - ) - await act(() => { - jest.runOnlyPendingTimers() - }) - - await waitFor(() => expect(getByTestId('cashInBtnRamp')).toBeTruthy()) - fireEvent.press(getByTestId('cashInBtnRamp')) - expect(navigateToURI).toHaveBeenCalledWith(mockRampProvider.url) - }) -}) diff --git a/src/home/CashInBottomSheet.tsx b/src/home/CashInBottomSheet.tsx deleted file mode 100644 index 05cbbf58487..00000000000 --- a/src/home/CashInBottomSheet.tsx +++ /dev/null @@ -1,205 +0,0 @@ -// import styles from 'src/styles/styles' -import { delay } from 'lodash' -import React, { useEffect, useState } from 'react' -import { useAsync } from 'react-async-hook' -import { useTranslation } from 'react-i18next' -import { StyleSheet, Text, View } from 'react-native' -import Modal from 'react-native-modal' -import { FiatExchangeEvents } from 'src/analytics/Events' -import ValoraAnalytics from 'src/analytics/ValoraAnalytics' -import Button, { BtnSizes } from 'src/components/Button' -import Touchable from 'src/components/Touchable' -import { fetchProviders, FiatExchangeFlow } from 'src/fiatExchanges/utils' -import Times from 'src/icons/Times' -import { LocalCurrencyCode } from 'src/localCurrency/consts' -import { getLocalCurrencyCode } from 'src/localCurrency/selectors' -import { navigate } from 'src/navigator/NavigationService' -import { Screens } from 'src/navigator/Screens' -import { userLocationDataSelector } from 'src/networkInfo/selectors' -import { useSelector } from 'src/redux/hooks' -import colors from 'src/styles/colors' -import fontStyles from 'src/styles/fonts' -import variables from 'src/styles/variables' -import { Currency } from 'src/utils/currencies' -import { navigateToURI } from 'src/utils/linking' -import Logger from 'src/utils/Logger' -import { currentAccountSelector } from 'src/web3/selectors' - -const TAG = 'CashInBottomSheet' - -function CashInBottomSheet() { - const { t } = useTranslation() - const [isModalVisible, setModalVisible] = useState(false) - - const userLocation = useSelector(userLocationDataSelector) - const account = useSelector(currentAccountSelector) - const localCurrency = useSelector(getLocalCurrencyCode) - const rampCashInButtonExpEnabled = useSelector((state) => state.app.rampCashInButtonExpEnabled) - - useEffect(() => { - ValoraAnalytics.track(FiatExchangeEvents.cico_add_bottom_sheet_impression) - }, []) - - const onDismissBottomSheet = () => { - setModalVisible(false) - } - - const asyncRampInfo = useAsync( - async () => { - if (!account) { - Logger.error(TAG, 'No account set') - return - } - // Use cEUR if that is their local currency, otherwise default to cUSD - const currencyToBuy = localCurrency === LocalCurrencyCode.EUR ? 'CEUR' : 'CUSD' - - try { - const providers = await fetchProviders({ - userLocation, - walletAddress: account, - fiatCurrency: localCurrency, - digitalAsset: currencyToBuy, - fiatAmount: 20, - digitalAssetAmount: 20, - txType: 'buy', - }) - const rampProvider = providers?.find((provider) => provider.name === 'Ramp') - const rampAvailable = !!( - rampProvider && - rampProvider?.cashIn && - !rampProvider.restricted && - !rampProvider.unavailable - ) - if (rampAvailable) { - // This event can be used as an activation event to limit the experiment - // analysis to users that have ramp available to them - ValoraAnalytics.track(FiatExchangeEvents.cico_add_bottom_sheet_ramp_available) - } - return { - rampAvailable, - rampURL: rampProvider?.url, - } - } catch (error) { - Logger.error(TAG, 'Failed to fetch CICO providers', error) - } - }, - [], - { - // The modal can freeze up on iOS if its visibility is quickly changed from false to true - // this delay prevents that, and is enough that its not very noticible to the user since - // the home page is also loading at this point. - onSuccess: () => delay(() => setModalVisible(true), 1000), - onError: () => delay(() => setModalVisible(true), 1000), - } - ) - - const { result: { rampAvailable = false, rampURL = '' } = {} } = asyncRampInfo - - const goToRamp = () => { - onDismissBottomSheet() - - navigateToURI(rampURL) - ValoraAnalytics.track(FiatExchangeEvents.cico_add_bottom_sheet_ramp_selected) - } - - const goToAddFunds = () => { - onDismissBottomSheet() - navigate(Screens.FiatExchangeCurrencyBottomSheet, { - flow: FiatExchangeFlow.CashIn, - }) - ValoraAnalytics.track(FiatExchangeEvents.cico_add_bottom_sheet_selected, { - rampAvailable, - }) - } - - return ( - - - - - - {rampAvailable && rampCashInButtonExpEnabled ? ( - <> - - {t('cashInBottomSheet.titleRamp', { - currency: localCurrency === LocalCurrencyCode.EUR ? Currency.Euro : Currency.Dollar, - })} - - {t('cashInBottomSheet.subtitleRamp')} -