From 73f2fef4674ccd960bc57df2ee8be43a48d6ea91 Mon Sep 17 00:00:00 2001 From: Ivan Vershigora Date: Thu, 13 Jun 2024 12:09:11 +0100 Subject: [PATCH] fix: hide some debug options in prod build --- e2e/settings.e2e.js | 50 ++++---- src/screens/Settings/DevSettings/index.tsx | 126 +++++++++++---------- 2 files changed, 92 insertions(+), 84 deletions(-) diff --git a/e2e/settings.e2e.js b/e2e/settings.e2e.js index a903389e3..f89ac51f9 100644 --- a/e2e/settings.e2e.js +++ b/e2e/settings.e2e.js @@ -613,31 +613,31 @@ d('Settings', () => { }); }); - // d('Dev Settings', () => { - // it('Shows the crash error screen when triggering render error', async () => { - // if (checkComplete('settings-dev')) { - // return; - // } - - // await element(by.id('Settings')).tap(); - // if (!__DEV__) { - // await element(by.id('DevOptions')).multiTap(5); // enable dev mode - // } - // await element(by.id('DevSettings')).tap(); - - // // Error screen will not be rendered in development mode - // if (__DEV__) { - // markComplete('settings-dev'); - // return; - // } - - // await element(by.id('TriggerRenderError')).tap(); - // await expect(element(by.id('ErrorClose'))).toBeVisible(); - // await expect(element(by.id('ErrorReport'))).toBeVisible(); - - // markComplete('settings-dev'); - // }); - // }); + d('Dev Settings', () => { + it('Shows the crash error screen when triggering render error', async () => { + if (checkComplete('settings-dev')) { + return; + } + + await element(by.id('Settings')).tap(); + if (!__DEV__) { + await element(by.id('DevOptions')).multiTap(5); // enable dev mode + } + await element(by.id('DevSettings')).tap(); + + // Error screen will not be rendered in development mode + if (__DEV__) { + markComplete('settings-dev'); + return; + } + + await element(by.id('TriggerRenderError')).tap(); + await expect(element(by.id('ErrorClose'))).toBeVisible(); + await expect(element(by.id('ErrorReport'))).toBeVisible(); + + markComplete('settings-dev'); + }); + }); d('Support', () => { it('Can see app status', async () => { diff --git a/src/screens/Settings/DevSettings/index.tsx b/src/screens/Settings/DevSettings/index.tsx index 931a1fb1b..5fac2c415 100644 --- a/src/screens/Settings/DevSettings/index.tsx +++ b/src/screens/Settings/DevSettings/index.tsx @@ -42,6 +42,7 @@ import { getFakeTransaction } from '../../../utils/wallet/testing'; import Dialog from '../../../components/Dialog'; import { resetBackupState } from '../../../store/slices/backup'; import { updateUi } from '../../../store/slices/ui'; +import { __E2E__ } from '../../../constants/env'; const DevSettings = ({ navigation, @@ -49,7 +50,7 @@ const DevSettings = ({ const dispatch = useAppDispatch(); const { t } = useTranslation('lightning'); const [showDialog, setShowDialog] = useState(false); - // const [throwError, setThrowError] = useState(false); + const [throwError, setThrowError] = useState(false); const selectedWallet = useAppSelector(selectedWalletSelector); const selectedNetwork = useAppSelector(selectedNetworkSelector); const addressType = useAppSelector(addressTypeSelector); @@ -162,61 +163,6 @@ const DevSettings = ({ refreshWallet({ selectedWallet, selectedNetwork }).then(); }, }, - // { - // title: 'Trigger exception in React render', - // type: EItemType.button, - // testID: 'TriggerRenderError', - // onPress: (): void => { - // setThrowError(true); - // }, - // }, - { - title: 'Trigger exception in action handler', - type: EItemType.button, - testID: 'TriggerActionError', - onPress: (): void => { - throw new Error('test action error'); - }, - }, - { - title: 'Trigger unhandled async exception', - type: EItemType.button, - testID: 'TriggerAsyncError', - onPress: (): void => { - throw new Error('test async error'); - }, - }, - { - title: 'Trigger Storage Warning', - type: EItemType.button, - hide: selectedNetwork !== 'bitcoinRegtest', - testID: 'TriggerStorageWarning', - onPress: (): void => { - const wallet = getWalletStore(); - const addresses = - wallet.wallets[selectedWallet].addresses[selectedNetwork][ - addressType - ]; - Object.keys(addresses).map((key) => { - if (addresses[key].index === 0) { - addresses[key].address = - 'bcrt1qjp22nm804mtl6vtzf65z2jgmeaedrlvzlxffjv'; - } - }); - const changeAddresses = - wallet.wallets[selectedWallet].changeAddresses[selectedNetwork][ - addressType - ]; - Object.keys(changeAddresses).map((key) => { - if (changeAddresses[key].index === 0) { - changeAddresses[key].address = - 'bcrt1qwxfllzxchc9eq95zrcc9cjxhzqpkgtznc4wpzc'; - } - }); - updateWallet(wallet); - runChecks({ selectedWallet, selectedNetwork }).then(); - }, - }, ], }, { @@ -331,9 +277,71 @@ const DevSettings = ({ }, ]; - // if (throwError) { - // throw new Error('test render error'); - // } + // add only in dev or e2e mode + if (__DEV__ || __E2E__) { + settingsListData[1].data = [ + ...settingsListData[1].data, + { + title: 'Trigger exception in React render', + type: EItemType.button, + testID: 'TriggerRenderError', + onPress: (): void => { + setThrowError(true); + }, + }, + { + title: 'Trigger exception in action handler', + type: EItemType.button, + testID: 'TriggerActionError', + onPress: (): void => { + throw new Error('test action error'); + }, + }, + { + title: 'Trigger unhandled async exception', + type: EItemType.button, + testID: 'TriggerAsyncError', + onPress: (): void => { + throw new Error('test async error'); + }, + }, + { + title: 'Trigger Storage Warning', + type: EItemType.button, + hide: selectedNetwork !== 'bitcoinRegtest', + testID: 'TriggerStorageWarning', + onPress: (): void => { + const wallet = getWalletStore(); + const addresses = + wallet.wallets[selectedWallet].addresses[selectedNetwork][ + addressType + ]; + Object.keys(addresses).map((key) => { + if (addresses[key].index === 0) { + addresses[key].address = + 'bcrt1qjp22nm804mtl6vtzf65z2jgmeaedrlvzlxffjv'; + } + }); + const changeAddresses = + wallet.wallets[selectedWallet].changeAddresses[selectedNetwork][ + addressType + ]; + Object.keys(changeAddresses).map((key) => { + if (changeAddresses[key].index === 0) { + changeAddresses[key].address = + 'bcrt1qwxfllzxchc9eq95zrcc9cjxhzqpkgtznc4wpzc'; + } + }); + updateWallet(wallet); + runChecks({ selectedWallet, selectedNetwork }).then(); + }, + }, + ]; + } + + if (throwError) { + throw new Error('test render error'); + } return ( <>