From 9caa640d6e6152370c508803eb23ff22539d6d84 Mon Sep 17 00:00:00 2001 From: Juliano Lazzarotto <30806844+stackchain@users.noreply.github.com> Date: Wed, 29 May 2024 16:57:07 +0100 Subject: [PATCH 1/4] fix(wallet-mobile): open/restore redirect and sync (#3276) --- apps/wallet-mobile/.env | 4 +- .../.storybook/storybook.requires.js | 2 +- apps/wallet-mobile/src/YoroiApp.tsx | 10 +- .../Exchange/common/useNavigateTo.tsx | 24 ---- .../CreateExchangeOrderScreen.tsx | 4 +- .../SetupWallet/SetupWalletNavigator.tsx | 7 + .../PreparingWallet/PreparingWallet.tsx | 34 ----- .../PreparingWalletScreen.stories.tsx} | 4 +- .../PreparingWalletScreen.tsx | 52 +++++++ .../legacy/CheckNanoX/CheckNanoXScreen.tsx | 4 +- .../ConnectNanoX/ConnectNanoXScreen.tsx | 4 +- .../ImportReadOnlyWalletScreen.tsx | 4 +- .../ChooseMnemonicTypeScreen.tsx | 4 +- .../ChooseNetwork/ChooseNetworkScreen.tsx | 4 +- .../ChooseSetupType/ChooseSetupTypeScreen.tsx | 4 +- .../AboutRecoveryPhraseScreen.tsx | 4 +- .../CreateWallet/RecoveryPhraseScreen.tsx | 4 +- .../VerifyRecoveryPhraseScreen.tsx | 4 +- .../CreateWallet/WalletDetailsScreen.tsx | 27 ++-- .../RestoreWalletDetailsScreen.tsx | 29 ++-- .../RestoreWallet/RestoreWalletScreen.tsx | 10 +- .../src/features/Swap/common/navigation.ts | 58 +++----- .../common/useLaunchWalletAfterSyncing.tsx | 73 ++++++++++ .../common/useSyncTemporarilyPaused.tsx | 39 +++++ .../WalletManager/common/walletManager.ts | 48 +++++-- .../wallet-mobile/src/hooks/useApiDialogs.tsx | 62 -------- .../src/hooks/useApiErrorResolver.tsx | 136 +++++++++++++++--- .../src/hooks/useApiStringsErrors.tsx | 26 ---- apps/wallet-mobile/src/kernel/constants.ts | 1 + apps/wallet-mobile/src/kernel/env.ts | 3 + .../kernel/logger/hooks/useSetupLogger.tsx | 9 +- .../wallet-mobile/src/kernel/logger/logger.ts | 2 + apps/wallet-mobile/src/kernel/navigation.tsx | 7 +- .../src/legacy/TxHistory/ActionsBanner.tsx | 2 +- .../SetupWallet/SetupWalletNavigator.json | 96 ++++++------- .../legacy/CheckNanoX/CheckNanoXScreen.json | 4 +- .../ConnectNanoX/ConnectNanoXScreen.json | 4 +- .../ImportReadOnlyWalletScreen.json | 16 +-- packages/common/src/utils/arrays.test.ts | 2 +- .../provider/SetupWalletProvider.test.tsx | 10 ++ .../reactjs/provider/SetupWalletProvider.tsx | 2 + .../translators/reactjs/state/state.test.ts | 12 ++ .../src/translators/reactjs/state/state.ts | 13 ++ packages/theme/src/atoms/atoms.ts | 4 +- 44 files changed, 531 insertions(+), 341 deletions(-) delete mode 100644 apps/wallet-mobile/src/features/SetupWallet/common/PreparingWallet/PreparingWallet.tsx rename apps/wallet-mobile/src/features/SetupWallet/common/{PreparingWallet/PreparingWallet.stories.tsx => PreparingWalletScreen/PreparingWalletScreen.stories.tsx} (74%) create mode 100644 apps/wallet-mobile/src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.tsx create mode 100644 apps/wallet-mobile/src/features/WalletManager/common/useLaunchWalletAfterSyncing.tsx create mode 100644 apps/wallet-mobile/src/features/WalletManager/common/useSyncTemporarilyPaused.tsx delete mode 100644 apps/wallet-mobile/src/hooks/useApiDialogs.tsx delete mode 100644 apps/wallet-mobile/src/hooks/useApiStringsErrors.tsx diff --git a/apps/wallet-mobile/.env b/apps/wallet-mobile/.env index 17db531d54..a1031aea55 100644 --- a/apps/wallet-mobile/.env +++ b/apps/wallet-mobile/.env @@ -3,7 +3,7 @@ COMMIT=093dec95a BUILD_VARIANT=STAGING SENTRY_DSN=https://fb3745d47d994059917e358dae581466@o1138840.ingest.sentry.io/4505319746764800 -DISABLE_LOGBOX=true +DISABLE_LOGBOX=false WALLET_1_MNEMONIC=abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon address WALLET_1_NETWORK_ID=300 @@ -20,3 +20,5 @@ FRONTEND_FEE_ADDRESS_MAINNET=addr1q9ry6jfdgm0lcrtfpgwrgxg7qfahv80jlghhrthy6w8hmy FRONTEND_FEE_ADDRESS_PREPROD=addr_test1qrgpjmyy8zk9nuza24a0f4e7mgp9gd6h3uayp0rqnjnkl54v4dlyj0kwfs0x4e38a7047lymzp37tx0y42glslcdtzhqzp57km UNSTOPPABLE_API_KEY=czsajliz-wxgu6tujd1zqq7hey_pclfqhdjsqolsxjfsurgh + +LOGGER_FILTER= diff --git a/apps/wallet-mobile/.storybook/storybook.requires.js b/apps/wallet-mobile/.storybook/storybook.requires.js index 3c33e85fd6..cfe07ed9ad 100644 --- a/apps/wallet-mobile/.storybook/storybook.requires.js +++ b/apps/wallet-mobile/.storybook/storybook.requires.js @@ -197,7 +197,7 @@ const getStories = () => { "./src/features/SetupWallet/common/CardAboutPhrase/CardAboutPhrase.stories.tsx": require("../src/features/SetupWallet/common/CardAboutPhrase/CardAboutPhrase.stories.tsx"), "./src/features/SetupWallet/common/LearnMoreButton/LearnMoreButton.stories.tsx": require("../src/features/SetupWallet/common/LearnMoreButton/LearnMoreButton.stories.tsx"), "./src/features/SetupWallet/common/LogoBanner/LogoBanner.stories.tsx": require("../src/features/SetupWallet/common/LogoBanner/LogoBanner.stories.tsx"), - "./src/features/SetupWallet/common/PreparingWallet/PreparingWallet.stories.tsx": require("../src/features/SetupWallet/common/PreparingWallet/PreparingWallet.stories.tsx"), + "./src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.stories.tsx": require("../src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.stories.tsx"), "./src/features/SetupWallet/common/StepperProgress/StepperProgress.stories.tsx": require("../src/features/SetupWallet/common/StepperProgress/StepperProgress.stories.tsx"), "./src/features/SetupWallet/common/TextInput/TextInput.stories.tsx": require("../src/features/SetupWallet/common/TextInput/TextInput.stories.tsx"), "./src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.stories.tsx": require("../src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.stories.tsx"), diff --git a/apps/wallet-mobile/src/YoroiApp.tsx b/apps/wallet-mobile/src/YoroiApp.tsx index 1bc359cd7d..6346417967 100644 --- a/apps/wallet-mobile/src/YoroiApp.tsx +++ b/apps/wallet-mobile/src/YoroiApp.tsx @@ -18,7 +18,7 @@ import {SelectedWalletProvider} from './features/WalletManager/context/SelectedW import {SelectedWalletMetaProvider} from './features/WalletManager/context/SelectedWalletMetaContext' import {WalletManagerProvider} from './features/WalletManager/context/WalletManagerContext' import {InitApp} from './InitApp' -import {disableLogbox} from './kernel/env' +import {disableLogbox, loggerFilter} from './kernel/env' import {LanguageProvider} from './kernel/i18n' import {useSetupLogger} from './kernel/logger/hooks/useSetupLogger' import {makeMetricsManager, MetricsProvider} from './kernel/metrics/metricsManager' @@ -29,7 +29,11 @@ import {useThemeStorageMaker} from './yoroi-wallets/hooks' enableScreens(true) enableFreeze(true) -if (disableLogbox) LogBox.ignoreAllLogs() +if (disableLogbox) { + LogBox.ignoreAllLogs() +} else { + LogBox.ignoreLogs(['Require cycle:']) +} const queryClient = new QueryClient() const metricsManager = makeMetricsManager() @@ -74,7 +78,7 @@ const Yoroi = () => { } export const YoroiApp = () => { - const isReady = useSetupLogger() + const isReady = useSetupLogger(loggerFilter) if (!isReady) return null diff --git a/apps/wallet-mobile/src/features/Exchange/common/useNavigateTo.tsx b/apps/wallet-mobile/src/features/Exchange/common/useNavigateTo.tsx index d725d7c6ee..ac52b02a1a 100644 --- a/apps/wallet-mobile/src/features/Exchange/common/useNavigateTo.tsx +++ b/apps/wallet-mobile/src/features/Exchange/common/useNavigateTo.tsx @@ -9,29 +9,5 @@ export const useNavigateTo = () => { return useRef({ exchangeSelectBuyProvider: () => navigation.navigate('exchange-select-buy-provider'), exchangeSelectSellProvider: () => navigation.navigate('exchange-select-sell-provider'), - exchangeOpenOrder: () => - navigation.reset({ - index: 0, - routes: [ - { - name: 'manage-wallets', - state: { - routes: [ - {name: 'wallet-selection'}, - { - name: 'main-wallet-routes', - state: { - routes: [ - { - name: 'history-list', - }, - ], - }, - }, - ], - }, - }, - ], - }), }).current } diff --git a/apps/wallet-mobile/src/features/Exchange/useCases/CreateExchangeOrderScreen/CreateExchangeOrderScreen.tsx b/apps/wallet-mobile/src/features/Exchange/useCases/CreateExchangeOrderScreen/CreateExchangeOrderScreen.tsx index 762deb2c02..dd0dae5a17 100644 --- a/apps/wallet-mobile/src/features/Exchange/useCases/CreateExchangeOrderScreen/CreateExchangeOrderScreen.tsx +++ b/apps/wallet-mobile/src/features/Exchange/useCases/CreateExchangeOrderScreen/CreateExchangeOrderScreen.tsx @@ -12,6 +12,7 @@ import {Space} from '../../../../components/Space/Space' import {Warning} from '../../../../components/Warning' import {banxaTestWallet} from '../../../../kernel/env' import {useMetrics} from '../../../../kernel/metrics/metricsManager' +import {useWalletNavigation} from '../../../../kernel/navigation' import {useTokenInfo} from '../../../../yoroi-wallets/hooks' import {Quantities} from '../../../../yoroi-wallets/utils' import {useSelectedWallet} from '../../../WalletManager/context/SelectedWalletContext' @@ -31,6 +32,7 @@ export const CreateExchangeOrderScreen = () => { const styles = useStyles() const {track} = useMetrics() const wallet = useSelectedWallet() + const walletNavigation = useWalletNavigation() const [contentHeight, setContentHeight] = React.useState(0) const navigateTo = useNavigateTo() @@ -88,7 +90,7 @@ export const CreateExchangeOrderScreen = () => { if (referralLink.toString() !== '') { Linking.openURL(referralLink.toString()) track.exchangeSubmitted({ramp_type: orderType === 'sell' ? 'Sell' : 'Buy', ada_amount: orderAmount}) - navigateTo.exchangeOpenOrder() + walletNavigation.navigateToTxHistory() } }, }, diff --git a/apps/wallet-mobile/src/features/SetupWallet/SetupWalletNavigator.tsx b/apps/wallet-mobile/src/features/SetupWallet/SetupWalletNavigator.tsx index 6afdcacef2..eab1b3538a 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/SetupWalletNavigator.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/SetupWalletNavigator.tsx @@ -4,6 +4,7 @@ import * as React from 'react' import {defineMessages, useIntl} from 'react-intl' import {defaultStackNavigationOptions, WalletInitRoutes} from '../../kernel/navigation' +import {PreparingWalletScreen} from './common/PreparingWalletScreen/PreparingWalletScreen' import {CheckNanoXScreen} from './legacy/CheckNanoX/CheckNanoXScreen' import {ConnectNanoXScreen} from './legacy/ConnectNanoX/ConnectNanoXScreen' import {ImportReadOnlyWalletScreen} from './legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen' @@ -134,6 +135,12 @@ export const SetupWalletNavigator = () => { component={VerifyRecoveryPhraseScreen} options={{title: strings.createWalletTitle}} /> + + ) } diff --git a/apps/wallet-mobile/src/features/SetupWallet/common/PreparingWallet/PreparingWallet.tsx b/apps/wallet-mobile/src/features/SetupWallet/common/PreparingWallet/PreparingWallet.tsx deleted file mode 100644 index 8d5b09a75f..0000000000 --- a/apps/wallet-mobile/src/features/SetupWallet/common/PreparingWallet/PreparingWallet.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import {useTheme} from '@yoroi/theme' -import * as React from 'react' -import {StyleSheet, Text, View} from 'react-native' - -import {useStrings} from '../useStrings' - -export const PreparingWallet = () => { - const strings = useStrings() - const {styles} = useStyles() - - return ( - - {strings.preparingWallet} - - ) -} - -const useStyles = () => { - const {atoms, color} = useTheme() - const styles = StyleSheet.create({ - root: { - flex: 1, - alignItems: 'center', - justifyContent: 'center', - }, - title: { - color: color.primary_c500, - textAlign: 'center', - ...atoms.heading_2_medium, - }, - }) - - return {styles} as const -} diff --git a/apps/wallet-mobile/src/features/SetupWallet/common/PreparingWallet/PreparingWallet.stories.tsx b/apps/wallet-mobile/src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.stories.tsx similarity index 74% rename from apps/wallet-mobile/src/features/SetupWallet/common/PreparingWallet/PreparingWallet.stories.tsx rename to apps/wallet-mobile/src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.stories.tsx index 7f59e3acdd..93fc7f8ee3 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/common/PreparingWallet/PreparingWallet.stories.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.stories.tsx @@ -2,11 +2,11 @@ import {storiesOf} from '@storybook/react-native' import React from 'react' import {StyleSheet, View} from 'react-native' -import {PreparingWallet} from './PreparingWallet' +import {PreparingWalletScreen} from './PreparingWalletScreen' storiesOf('AddWallet PreparingWallet', module) .addDecorator((story) => {story()}) - .add('initial', () => ) + .add('initial', () => ) const styles = StyleSheet.create({ container: { diff --git a/apps/wallet-mobile/src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.tsx new file mode 100644 index 0000000000..60d7808868 --- /dev/null +++ b/apps/wallet-mobile/src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.tsx @@ -0,0 +1,52 @@ +import {useSetupWallet} from '@yoroi/setup-wallet' +import {useTheme} from '@yoroi/theme' +import * as React from 'react' +import {StyleSheet, Text} from 'react-native' +import {SafeAreaView} from 'react-native-safe-area-context' + +import {logger} from '../../../../kernel/logger/logger' +import {isEmptyString} from '../../../../kernel/utils' +import {useLaunchWalletAfterSyncing} from '../../../WalletManager/common/useLaunchWalletAfterSyncing' +import {useSyncTemporarilyPaused} from '../../../WalletManager/common/useSyncTemporarilyPaused' +import {useStrings} from '../useStrings' + +/** + * It requests the global syncing to stop on mounting to favor the sync of a specific wallet + * and resume the global syncing after the wallet is sync and the screen is unmounted. + */ +export const PreparingWalletScreen = () => { + const strings = useStrings() + const {styles} = useStyles() + const {walletId} = useSetupWallet() + const isGlobalSyncPaused = useSyncTemporarilyPaused() + useLaunchWalletAfterSyncing({isGlobalSyncPaused, walletId}) + + if (isEmptyString(walletId)) { + const error = new Error('PreparingWalletScreen: walletId is empty, reached an invalid state.') + logger.error(error) + throw error + } + + return ( + + {strings.preparingWallet} + + ) +} + +const useStyles = () => { + const {atoms, color} = useTheme() + const styles = StyleSheet.create({ + root: { + ...atoms.flex_1, + ...atoms.align_center, + ...atoms.justify_center, + }, + title: { + color: color.primary_c500, + ...atoms.text_center, + ...atoms.heading_2_medium, + }, + }) + return {styles} as const +} diff --git a/apps/wallet-mobile/src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.tsx index ded8afe055..a1826069a0 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.tsx @@ -9,13 +9,13 @@ import {SafeAreaView} from 'react-native-safe-area-context' import image from '../../../../assets/img/ledger_1.png' import {BulletPointItem, Button, ProgressStep, Spacer, Text} from '../../../../components' import {confirmationMessages, ledgerMessages} from '../../../../kernel/i18n/global-messages' -import {WalletInitRouteNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' export const CheckNanoXScreen = () => { const strings = useStrings() const styles = useStyles() - const navigation = useNavigation() + const navigation = useNavigation() const onContinue = () => navigation.navigate('setup-wallet-connect-nano-x') const {useUSB} = useSetupWallet() diff --git a/apps/wallet-mobile/src/features/SetupWallet/legacy/ConnectNanoX/ConnectNanoXScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/legacy/ConnectNanoX/ConnectNanoXScreen.tsx index e0e9e6c134..b918b36101 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/legacy/ConnectNanoX/ConnectNanoXScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/legacy/ConnectNanoX/ConnectNanoXScreen.tsx @@ -10,7 +10,7 @@ import {ProgressStep} from '../../../../components' import {showErrorDialog} from '../../../../kernel/dialogs' import {errorMessages} from '../../../../kernel/i18n/global-messages' import LocalizableError from '../../../../kernel/i18n/LocalizableError' -import {WalletInitRouteNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' import {LedgerConnect} from '../../../../legacy/HW' import {getHWDeviceInfo} from '../../../../yoroi-wallets/cardano/hw' import {DeviceId, DeviceObj, HWDeviceInfo} from '../../../../yoroi-wallets/hw' @@ -30,7 +30,7 @@ export const ConnectNanoXScreen = ({defaultDevices}: Props) => { const intl = useIntl() const strings = useStrings() const styles = useStyles() - const navigation = useNavigation() + const navigation = useNavigation() const {hwDeviceInfoChanged, walletImplementationId, useUSB} = useSetupWallet() diff --git a/apps/wallet-mobile/src/features/SetupWallet/legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen.tsx index 1c09f29db7..fefbf46dd6 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen.tsx @@ -8,13 +8,13 @@ import {BulletPointItem, CameraCodeScanner, Spacer, Text} from '../../../../comp import {showErrorDialog} from '../../../../kernel/dialogs' import {errorMessages} from '../../../../kernel/i18n/global-messages' import {logger} from '../../../../kernel/logger/logger' -import {WalletInitRouteNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' import {isCIP1852AccountPath, isValidPublicKey} from '../../../../yoroi-wallets/cardano/bip44Validators' export const ImportReadOnlyWalletScreen = () => { const intl = useIntl() const strings = useStrings() - const navigation = useNavigation() + const navigation = useNavigation() const {publicKeyHexChanged, pathChanged} = useSetupWallet() const onRead = async (event: {data: string}): Promise => { diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseMnemonicType/ChooseMnemonicTypeScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseMnemonicType/ChooseMnemonicTypeScreen.tsx index b976f5f30f..0d8ed7d1f9 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseMnemonicType/ChooseMnemonicTypeScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseMnemonicType/ChooseMnemonicTypeScreen.tsx @@ -7,7 +7,7 @@ import {SafeAreaView} from 'react-native-safe-area-context' import {Space} from '../../../../components/Space/Space' import {useMetrics} from '../../../../kernel/metrics/metricsManager' -import {WalletInitRouteNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' import {ButtonCard} from '../../common/ButtonCard/ButtonCard' import {LogoBanner} from '../../common/LogoBanner/LogoBanner' import {useStrings} from '../../common/useStrings' @@ -20,7 +20,7 @@ export const ChooseMnemonicTypeScreen = () => { const {mnemonicTypeChanged} = useSetupWallet() const {track} = useMetrics() - const navigation = useNavigation() + const navigation = useNavigation() const handle15Words = () => { mnemonicTypeChanged(15) diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseNetwork/ChooseNetworkScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseNetwork/ChooseNetworkScreen.tsx index bcd10eff6f..d31356fae9 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseNetwork/ChooseNetworkScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseNetwork/ChooseNetworkScreen.tsx @@ -6,7 +6,7 @@ import {ScrollView, StyleSheet, View} from 'react-native' import {SafeAreaView} from 'react-native-safe-area-context' import {Space} from '../../../../components/Space/Space' -import {WalletInitRouteNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' import * as HASKELL_SHELLEY from '../../../../yoroi-wallets/cardano/constants/mainnet/constants' import * as SANCHONET from '../../../../yoroi-wallets/cardano/constants/sanchonet/constants' import * as HASKELL_SHELLEY_TESTNET from '../../../../yoroi-wallets/cardano/constants/testnet/constants' @@ -91,7 +91,7 @@ const useNavigate = () => { } export const useNavigateTo = () => { - const navigation = useNavigation() + const navigation = useNavigation() return React.useRef({ create: () => navigation.navigate('setup-wallet-about-recovery-phase'), diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseSetupType/ChooseSetupTypeScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseSetupType/ChooseSetupTypeScreen.tsx index 31d9f2f909..cdfd15b7f9 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseSetupType/ChooseSetupTypeScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseSetupType/ChooseSetupTypeScreen.tsx @@ -8,7 +8,7 @@ import {SafeAreaView} from 'react-native-safe-area-context' import {Space} from '../../../../components/Space/Space' import {isProduction} from '../../../../kernel/env' import {useMetrics} from '../../../../kernel/metrics/metricsManager' -import {WalletInitRouteNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' import {LedgerTransportSwitchModal} from '../../../../legacy/HW' import * as HASKELL_SHELLEY from '../../../../yoroi-wallets/cardano/constants/mainnet/constants' import {ButtonCard} from '../../common/ButtonCard/ButtonCard' @@ -36,7 +36,7 @@ export const ChooseSetupTypeScreen = () => { }, [track]), ) - const navigation = useNavigation() + const navigation = useNavigation() const handleCreate = () => { walletImplementationIdChanged(HASKELL_SHELLEY.WALLET_IMPLEMENTATION_ID) diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/AboutRecoveryPhraseScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/AboutRecoveryPhraseScreen.tsx index 0abc4bf99d..7ea2c70abb 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/AboutRecoveryPhraseScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/AboutRecoveryPhraseScreen.tsx @@ -8,7 +8,7 @@ import {ViewProps} from 'react-native-svg/lib/typescript/fabric/utils' import {Button, Spacer} from '../../../../components' import {Space} from '../../../../components/Space/Space' import {useMetrics} from '../../../../kernel/metrics/metricsManager' -import {WalletInitRouteNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' import {CardAboutPhrase} from '../../common/CardAboutPhrase/CardAboutPhrase' import {YoroiZendeskLink} from '../../common/constants' import {LearnMoreButton} from '../../common/LearnMoreButton/LearnMoreButton' @@ -19,7 +19,7 @@ export const AboutRecoveryPhraseScreen = () => { const bold = useBold() const {styles} = useStyles() const strings = useStrings() - const navigation = useNavigation() + const navigation = useNavigation() const {track} = useMetrics() useFocusEffect( diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/RecoveryPhraseScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/RecoveryPhraseScreen.tsx index 41f82ae5d3..5af1e8bb54 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/RecoveryPhraseScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/RecoveryPhraseScreen.tsx @@ -10,7 +10,7 @@ import {SafeAreaView} from 'react-native-safe-area-context' import {Button, Spacer, useModal} from '../../../../components' import {Space} from '../../../../components/Space/Space' import {useMetrics} from '../../../../kernel/metrics/metricsManager' -import {WalletInitRouteNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' import {generateAdaMnemonic} from '../../../../yoroi-wallets/cardano/mnemonic' import {CardAboutPhrase} from '../../common/CardAboutPhrase/CardAboutPhrase' import {YoroiZendeskLink} from '../../common/constants' @@ -25,7 +25,7 @@ export const RecoveryPhraseScreen = () => { const {styles, colors} = useStyles() const {openModal, closeModal} = useModal() const [isBlur, setIsBlur] = React.useState(true) - const navigation = useNavigation() + const navigation = useNavigation() const strings = useStrings() const {mnemonicChanged, showCreateWalletInfoModal, showCreateWalletInfoModalChanged} = useSetupWallet() const {track} = useMetrics() diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/VerifyRecoveryPhraseScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/VerifyRecoveryPhraseScreen.tsx index 4f039e0f83..5c4cfadbc4 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/VerifyRecoveryPhraseScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/VerifyRecoveryPhraseScreen.tsx @@ -11,7 +11,7 @@ import {SafeAreaView} from 'react-native-safe-area-context' import {Button} from '../../../../components' import {Space} from '../../../../components/Space/Space' import {useMetrics} from '../../../../kernel/metrics/metricsManager' -import {WalletInitRouteNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' import {makeKeys} from '../../../../yoroi-wallets/cardano/shelley/makeKeys' import {StepperProgress} from '../../common/StepperProgress/StepperProgress' import {useStrings} from '../../common/useStrings' @@ -21,7 +21,7 @@ import {Check2 as Check2Illustration} from '../../illustrations/Check2' export const VerifyRecoveryPhraseScreen = () => { const {styles} = useStyles() const bold = useBold() - const navigation = useNavigation() + const navigation = useNavigation() const strings = useStrings() const {mnemonic, publicKeyHexChanged} = useSetupWallet() const {track} = useMetrics() diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx index 8b8ec711bc..ea614e00f6 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx @@ -1,4 +1,4 @@ -import {useFocusEffect} from '@react-navigation/native' +import {useFocusEffect, useNavigation} from '@react-navigation/native' import {useAsyncStorage} from '@yoroi/common' import {useSetupWallet} from '@yoroi/setup-wallet' import {useTheme} from '@yoroi/theme' @@ -23,8 +23,9 @@ import {Button, Icon, KeyboardAvoidingView, TextInput, useModal} from '../../../ import {Space} from '../../../../components/Space/Space' import {showErrorDialog} from '../../../../kernel/dialogs' import {errorMessages} from '../../../../kernel/i18n/global-messages' +import {logger} from '../../../../kernel/logger/logger' import {useMetrics} from '../../../../kernel/metrics/metricsManager' -import {useWalletNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' import {isEmptyString} from '../../../../kernel/utils' import {useCreateWallet, usePlate, useWalletNames} from '../../../../yoroi-wallets/hooks' import {WalletImplementationId} from '../../../../yoroi-wallets/types' @@ -41,7 +42,6 @@ import {useWalletManager} from '../../../WalletManager/context/WalletManagerCont import {CardAboutPhrase} from '../../common/CardAboutPhrase/CardAboutPhrase' import {YoroiZendeskLink} from '../../common/constants' import {LearnMoreButton} from '../../common/LearnMoreButton/LearnMoreButton' -import {PreparingWallet} from '../../common/PreparingWallet/PreparingWallet' import {StepperProgress} from '../../common/StepperProgress/StepperProgress' import {useStrings} from '../../common/useStrings' import {Info as InfoIcon} from '../../illustrations/Info' @@ -63,15 +63,15 @@ const useSizeModal = () => { // when restoring, later will be part of the onboarding const addressMode: AddressMode = 'single' export const WalletDetailsScreen = () => { - const bold = useBold() + const navigation = useNavigation() + const strings = useStrings() const {styles} = useStyles() + const {track} = useMetrics() + const bold = useBold() const {HEIGHT_MODAL_NAME_PASSWORD, HEIGHT_MODAL_CHECKSUM} = useSizeModal() const {openModal, closeModal} = useModal() - const {resetToTxHistory} = useWalletNavigation() - const strings = useStrings() const walletManager = useWalletManager() const {walletNames} = useWalletNames(walletManager) - const {track} = useMetrics() const intl = useIntl() const storage = useAsyncStorage() const { @@ -81,6 +81,7 @@ export const WalletDetailsScreen = () => { walletImplementationId, showRestoreWalletInfoModal, showRestoreWalletInfoModalChanged, + walletIdChanged, } = useSetupWallet() const plate = usePlate({networkId, publicKeyHex}) const [name, setName] = React.useState(features.prefillWalletInfo ? debugWalletInfo.WALLET_NAME : '') @@ -111,15 +112,19 @@ export const WalletDetailsScreen = () => { isSuccess: isCreateWalletSuccess, } = useCreateWallet({ onSuccess: async (wallet) => { + walletIdChanged(wallet.id) const walletStorage = storage.join('wallet/') const walletMeta = await walletStorage.getItem(wallet.id, parseWalletMeta) - if (!walletMeta) throw new Error('invalid wallet meta') + if (!walletMeta) { + const error = new Error('WalletDetailsScreen: wallet meta is invalid, reached an invalid state.') + logger.error(error) + throw error + } track.createWalletDetailsSettled() - // TODO: revisit needs to open the new wallet - should wait for done sync event from manager - resetToTxHistory() + navigation.navigate('setup-wallet-preparing-wallet') }, onError: (error) => { InteractionManager.runAfterInteractions(() => { @@ -251,8 +256,6 @@ export const WalletDetailsScreen = () => { ) } - if (isLoading) return - return ( diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx index 2659c2d5ff..f6d0758ebb 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx @@ -1,4 +1,4 @@ -import {useFocusEffect} from '@react-navigation/native' +import {useFocusEffect, useNavigation} from '@react-navigation/native' import {useAsyncStorage} from '@yoroi/common' import {useSetupWallet} from '@yoroi/setup-wallet' import {useTheme} from '@yoroi/theme' @@ -22,8 +22,9 @@ import {Button, Icon, KeyboardAvoidingView, TextInput, useModal} from '../../../ import {Space} from '../../../../components/Space/Space' import {showErrorDialog} from '../../../../kernel/dialogs' import {errorMessages} from '../../../../kernel/i18n/global-messages' +import {logger} from '../../../../kernel/logger/logger' import {useMetrics} from '../../../../kernel/metrics/metricsManager' -import {useWalletNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation} from '../../../../kernel/navigation' import {isEmptyString} from '../../../../kernel/utils' import {useCreateWallet, usePlate, useWalletNames} from '../../../../yoroi-wallets/hooks' import {WalletImplementationId} from '../../../../yoroi-wallets/types' @@ -40,7 +41,6 @@ import {useWalletManager} from '../../../WalletManager/context/WalletManagerCont import {CardAboutPhrase} from '../../common/CardAboutPhrase/CardAboutPhrase' import {YoroiZendeskLink} from '../../common/constants' import {LearnMoreButton} from '../../common/LearnMoreButton/LearnMoreButton' -import {PreparingWallet} from '../../common/PreparingWallet/PreparingWallet' import {StepperProgress} from '../../common/StepperProgress/StepperProgress' import {useStrings} from '../../common/useStrings' import {Info as InfoIcon} from '../../illustrations/Info' @@ -62,18 +62,18 @@ const useSizeModal = () => { // when restoring, later will be part of the onboarding const addressMode: AddressMode = 'single' export const RestoreWalletDetailsScreen = () => { - const bold = useBold() + const navigation = useNavigation() + const strings = useStrings() const {styles} = useStyles() + const {track} = useMetrics() + const bold = useBold() const {HEIGHT_MODAL_NAME_PASSWORD, HEIGHT_MODAL_CHECKSUM} = useSizeModal() const {openModal, closeModal} = useModal() - const strings = useStrings() - const {resetToTxHistory} = useWalletNavigation() const walletManager = useWalletManager() - const {track} = useMetrics() const {walletNames} = useWalletNames(walletManager) const [name, setName] = React.useState(features.prefillWalletInfo ? debugWalletInfo.WALLET_NAME : '') const storage = useAsyncStorage() - const {mnemonic, networkId, publicKeyHex, walletImplementationId} = useSetupWallet() + const {mnemonic, networkId, publicKeyHex, walletImplementationId, walletIdChanged} = useSetupWallet() const plate = usePlate({networkId, publicKeyHex}) const passwordRef = React.useRef(null) @@ -99,14 +99,19 @@ export const RestoreWalletDetailsScreen = () => { isSuccess: isCreateWalletSuccess, } = useCreateWallet({ onSuccess: async (wallet) => { + walletIdChanged(wallet.id) const walletStorage = storage.join('wallet/') const walletMeta = await walletStorage.getItem(wallet.id, parseWalletMeta) - if (!walletMeta) throw new Error('invalid wallet meta') + if (!walletMeta) { + const error = new Error('RestoreWalletDetailsScreen: wallet meta is invalid, reached an invalid state.') + logger.error(error) + throw error + } track.restoreWalletDetailsSettled() - // TODO: revist should open the wallet and navigate to it - resetToTxHistory() + + navigation.navigate('setup-wallet-preparing-wallet') }, onError: (error) => { InteractionManager.runAfterInteractions(() => { @@ -123,8 +128,6 @@ export const RestoreWalletDetailsScreen = () => { }, [track]), ) - if (isLoading) return - const nameErrors = validateWalletName(name, null, walletNames && !isCreateWalletSuccess ? walletNames : []) const walletNameErrorText = getWalletNameError( {tooLong: strings.tooLong, nameAlreadyTaken: strings.nameAlreadyTaken, mustBeFilled: strings.mustBeFilled}, diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx index f427d52499..74492f1b48 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx @@ -11,7 +11,7 @@ import {SafeAreaView} from 'react-native-safe-area-context' import {Button, Icon, KeyboardAvoidingView, useModal} from '../../../../components' import {Space} from '../../../../components/Space/Space' import {useMetrics} from '../../../../kernel/metrics/metricsManager' -import {useWalletNavigation, WalletInitRouteNavigation} from '../../../../kernel/navigation' +import {SetupWalletRouteNavigation, useWalletNavigation} from '../../../../kernel/navigation' import {isEmptyString} from '../../../../kernel/utils' import {makeKeys} from '../../../../yoroi-wallets/cardano/shelley/makeKeys' import {usePlate, useWalletMetas} from '../../../../yoroi-wallets/hooks' @@ -33,13 +33,13 @@ export const RestoreWalletScreen = () => { const strings = useStrings() const bold = useBold() const [mnemonic, setMnemonic] = React.useState('') - const navigation = useNavigation() + const navigation = useNavigation() const {publicKeyHexChanged, mnemonicChanged, mnemonicType} = useSetupWallet() const {track} = useMetrics() const walletManager = useWalletManager() const {walletMetas} = useWalletMetas(walletManager) const {openModal} = useModal() - const {navigateToTxHistory} = useWalletNavigation() + const {resetToTxHistory} = useWalletNavigation() const selectWalletMeta = useSetSelectedWalletMeta() const selectWallet = useSetSelectedWallet() const [focusedIndex, setFocusedIndex] = React.useState(0) @@ -120,9 +120,9 @@ export const RestoreWalletScreen = () => { const wallet = walletManager.getOpenedWalletById(walletMeta.id) selectWallet(wallet) walletManager.setSelectedWalletId(walletMeta.id) - navigateToTxHistory() + resetToTxHistory() }, - [selectWalletMeta, walletManager, selectWallet, navigateToTxHistory], + [selectWalletMeta, walletManager, selectWallet, resetToTxHistory], ) const handleOnNext = React.useCallback(async () => { diff --git a/apps/wallet-mobile/src/features/Swap/common/navigation.ts b/apps/wallet-mobile/src/features/Swap/common/navigation.ts index 556fe8450c..93d89633e8 100644 --- a/apps/wallet-mobile/src/features/Swap/common/navigation.ts +++ b/apps/wallet-mobile/src/features/Swap/common/navigation.ts @@ -4,50 +4,30 @@ import {useRef} from 'react' import {SwapTokenRouteseNavigation} from '../../../kernel/navigation' export const useNavigateTo = () => { - const navigation = useNavigation() + const swapNavigation = useNavigation() + const navigation = useNavigation() return useRef({ - selectPool: () => navigation.navigate('swap-select-pool'), - editSlippage: () => navigation.navigate('swap-edit-slippage'), - selectBuyToken: () => navigation.navigate('swap-select-buy-token'), - selectSellToken: () => navigation.navigate('swap-select-sell-token'), - startSwap: () => navigation.navigate('swap-start-swap'), - confirmTx: () => navigation.navigate('swap-confirm-tx'), - submittedTx: (txId: string) => navigation.navigate('swap-submitted-tx', {txId}), - failedTx: () => navigation.navigate('swap-failed-tx'), + selectPool: () => swapNavigation.navigate('swap-select-pool'), + editSlippage: () => swapNavigation.navigate('swap-edit-slippage'), + selectBuyToken: () => swapNavigation.navigate('swap-select-buy-token'), + selectSellToken: () => swapNavigation.navigate('swap-select-sell-token'), + startSwap: () => swapNavigation.navigate('swap-start-swap', {screen: 'token-swap'}), + confirmTx: () => swapNavigation.navigate('swap-confirm-tx'), + submittedTx: (txId: string) => swapNavigation.navigate('swap-submitted-tx', {txId}), + failedTx: () => swapNavigation.navigate('swap-failed-tx'), swapOpenOrders: () => - navigation.reset({ - index: 0, - routes: [ - { - name: 'manage-wallets', - state: { - routes: [ - {name: 'wallet-selection'}, - { - name: 'main-wallet-routes', - state: { - routes: [ - { - name: 'history', - state: { - routes: [ - { - name: 'swap-start-swap', - state: { - routes: [{name: 'orders'}], - }, - }, - ], - }, - }, - ], - }, - }, - ], + navigation.navigate('manage-wallets', { + screen: 'main-wallet-routes', + params: { + screen: 'history', + params: { + screen: 'swap-start-swap', + params: { + screen: 'orders', }, }, - ], + }, }), }).current } diff --git a/apps/wallet-mobile/src/features/WalletManager/common/useLaunchWalletAfterSyncing.tsx b/apps/wallet-mobile/src/features/WalletManager/common/useLaunchWalletAfterSyncing.tsx new file mode 100644 index 0000000000..7bd094a417 --- /dev/null +++ b/apps/wallet-mobile/src/features/WalletManager/common/useLaunchWalletAfterSyncing.tsx @@ -0,0 +1,73 @@ +import * as React from 'react' + +import {time} from '../../../kernel/constants' +import {logger} from '../../../kernel/logger/logger' +import {useWalletNavigation} from '../../../kernel/navigation' +import {YoroiWallet} from '../../../yoroi-wallets/cardano/types' +import {useSetSelectedWallet} from '../context/SelectedWalletContext' +import {useSetSelectedWalletMeta} from '../context/SelectedWalletMetaContext' +import {useWalletManager} from '../context/WalletManagerContext' + +/** + * Custom hook to launch a new wallet first time or when a previous sync is required, it will follow these steps: + * preconditions: + * 1. wallet should be previously created + * process: + * 2. wait 1s to display any UI feedback (like a spinner) + * 3. request pause of global sync + * 4. open the wallets (to populate the wallets in the manager) + * 5. check if the wallet provided is there (if not, silently redirect to wallet selection) (error is reported if user has enabled crash reporting) + * 6. sync the wallet (with force flag) + * 7. redirect user to the tx history screen (aka home screen) + * + * This **must be used only** to launch a wallet after it has been created/restore or in last case when it **requires** a sync + * for every other case use wallet manager setCurrentWallet (setSelectedWallet and setSelectedWalletMeta will be deprecated) + * check `SelectWalletFromList` useCase in the WalletManager feature for more details + * + * @param {YoroiWallet['id']} id - The ID of the wallet to launch + * @summary This is for launching a wallet after it has been created/restore/required-sync **only**, don't use to select a wallet + */ +export function useLaunchWalletAfterSyncing({ + isGlobalSyncPaused = false, + walletId, +}: { + isGlobalSyncPaused: boolean + walletId: YoroiWallet['id'] | null +}) { + const walletNavigation = useWalletNavigation() + const manager = useWalletManager() + const setSelectedWallet = useSetSelectedWallet() + const setSelectedWalletMeta = useSetSelectedWalletMeta() + + React.useEffect(() => { + let started = false + if (!isGlobalSyncPaused || started || walletId == null) return + + const process = async () => { + started = true + // openning wallets force manager to add it to the sync queue + // it's ok if the wallet is already opened by manager + const {metas} = await manager.openWallets() + + const wallet = manager.getOpenedWalletById(walletId) + const meta = metas.find(({id}) => id === walletId) + if (!wallet || !meta) { + const error = new Error( + 'useLaunchWalletAfterSyncing: New wallet/meta has not been found, reached an invalid state', + ) + logger.error(error) + walletNavigation.resetToWalletSelection() + return + } + + setSelectedWallet(wallet) + setSelectedWalletMeta(meta) + await wallet.sync({isForced: true}) + + walletNavigation.resetToTxHistory() + } + + const timer = setTimeout(() => process(), time.oneSecond) + return () => clearTimeout(timer) + }, [isGlobalSyncPaused, walletId, manager, walletNavigation, setSelectedWallet, setSelectedWalletMeta]) +} diff --git a/apps/wallet-mobile/src/features/WalletManager/common/useSyncTemporarilyPaused.tsx b/apps/wallet-mobile/src/features/WalletManager/common/useSyncTemporarilyPaused.tsx new file mode 100644 index 0000000000..64bc45d9cf --- /dev/null +++ b/apps/wallet-mobile/src/features/WalletManager/common/useSyncTemporarilyPaused.tsx @@ -0,0 +1,39 @@ +import * as React from 'react' + +import {useWalletManager} from '../context/WalletManagerContext' + +/** + * This is used to stop syncing and resume syncing automaticaly + * (stop on mount and resume on unmount) + * when there is an action that requires syncing to be stopped + * + * @summary This is for stopping syncing and resuming syncing automaticaly + * when the screen is unmounted + * @returns {boolean} isTemporarilyPaused - A boolean to indicate if syncing is stopped + */ +export function useSyncTemporarilyPaused() { + const manager = useWalletManager() + const [isSyncTemporarilyPaused, setIsSyncTemporarilyPaused] = React.useState( + !manager.isSyncActive && !manager.isSyncing, + ) + + React.useEffect(() => { + manager.pauseSyncing() + + const subSyncActivity = manager.syncActive$.subscribe((isActive) => { + setIsSyncTemporarilyPaused(() => !isActive && !manager.isSyncing) + }) + const subIsSyncing = manager.syncing$.subscribe((isSyncing) => { + setIsSyncTemporarilyPaused(() => !isSyncing) + }) + + return () => { + subSyncActivity.unsubscribe() + subIsSyncing.unsubscribe() + + manager.resumeSyncing() + } + }, [manager]) + + return isSyncTemporarilyPaused +} diff --git a/apps/wallet-mobile/src/features/WalletManager/common/walletManager.ts b/apps/wallet-mobile/src/features/WalletManager/common/walletManager.ts index d97f62a5a1..56da7bfdd3 100644 --- a/apps/wallet-mobile/src/features/WalletManager/common/walletManager.ts +++ b/apps/wallet-mobile/src/features/WalletManager/common/walletManager.ts @@ -1,4 +1,4 @@ -import {parseSafe} from '@yoroi/common' +import {difference, parseSafe} from '@yoroi/common' import {App, Chain} from '@yoroi/types' import { BehaviorSubject, @@ -15,6 +15,7 @@ import { } from 'rxjs' import uuid from 'uuid' +import {logger} from '../../../kernel/logger/logger' import {makeWalletEncryptedStorage} from '../../../kernel/storage/EncryptedStorage' import {Keychain} from '../../../kernel/storage/Keychain' import {rootStorage} from '../../../kernel/storage/rootStorage' @@ -67,6 +68,25 @@ export class WalletManager { return this.#selectedWalletId } + private initWalletInfos(wallets: ReadonlyArray) { + for (const wallet of wallets) { + this.#walletInfos.set(wallet.id, { + sync: {status: 'waiting', updatedAt: Date.now()}, + }) + this.walletInfos$.next(new Map(this.#walletInfos)) + } + + // drop wallets that are not returned by the list (deleted wallets) + // can't delete on removeWallet cuz a wallet can be marked to be deleted while it's syncing + difference( + wallets.map(({id}) => id), + Array.from(this.#walletInfos.keys()), + ).forEach((id) => { + this.#walletInfos.delete(id) + this.walletInfos$.next(new Map(this.#walletInfos)) + }) + } + startSyncingAllWallets() { const syncWallets = () => { if (this.#isSyncing$.value) return @@ -75,27 +95,26 @@ export class WalletManager { from(this.openWallets()) .pipe( - concatMap((wallets) => { - this.#walletInfos.clear() - wallets.forEach((wallet) => { - this.#walletInfos.set(wallet.id, {sync: {status: 'waiting', updatedAt: Date.now()}}) - this.walletInfos$.next(new Map(this.#walletInfos)) - }) + concatMap(({wallets}) => { + this.initWalletInfos(wallets) return from(wallets) }), concatMap((wallet) => { this.#walletInfos.set(wallet.id, {sync: {status: 'syncing', updatedAt: Date.now()}}) this.walletInfos$.next(new Map(this.#walletInfos)) + logger.debug('WalletManager: startSyncingAllWallets syncing walet', {walletId: wallet.id}) return from(wallet.sync({isForced: false})).pipe( catchError((error) => { this.#walletInfos.set(wallet.id, {sync: {status: 'error', error, updatedAt: Date.now()}}) this.walletInfos$.next(new Map(this.#walletInfos)) + logger.error('WalletManager: startSyncingAllWallets error syncing walet', {error, walletId: wallet.id}) return of() }), finalize(() => { if (this.#walletInfos.get(wallet.id)?.sync.status !== 'error') { this.#walletInfos.set(wallet.id, {sync: {status: 'done', updatedAt: Date.now()}}) this.walletInfos$.next(new Map(this.#walletInfos)) + logger.debug('WalletManager: startSyncingAllWallets done syncing walet', {walletId: wallet.id}) } }), ) @@ -141,10 +160,12 @@ export class WalletManager { } pauseSyncing() { + logger.debug('WalletManager: pauseSyncing requested') this.#syncControl$.next(false) } resumeSyncing() { + logger.debug('WalletManager: resumeSyncing requested') this.#syncControl$.next(true) } @@ -164,12 +185,19 @@ export class WalletManager { return this.#openedWallets.get(id) } + /** + * It populates the wallet manager with the wallets stored in the storage + * and ensures that after a wallet is loaded that instance is returned on subsequent calls + * A wallet should be instantianted only here, otherwise the stream mechanism will not work + * + * @returns {Promise<{wallets: YoroiWallet[]; metas: WalletMeta[]}>} + */ async openWallets() { const walletMetas = await this.listWallets() const closedWallets = walletMetas.filter((meta) => !this.#openedWallets.has(meta.id)) const wallets = await Promise.all(closedWallets.map((meta) => this.openWallet(meta))) wallets.forEach((wallet) => this.#openedWallets.set(wallet.id, wallet)) - return [...this.#openedWallets.values()] + return {wallets: Array.from(this.#openedWallets.values()), metas: walletMetas} } async listWallets() { @@ -293,8 +321,10 @@ export class WalletManager { async removeWallet(id: string) { const deletedWalletIds = await this.deletedWalletIds() - this.#openedWallets.delete(id) await this.#rootStorage.setItem('deletedWalletIds', [...deletedWalletIds, id]) + + // can't update the walletInfo here cuz it might be in the middle of wallet syncing + this.#openedWallets.delete(id) } // TODO(ppershing): how should we deal with race conditions? diff --git a/apps/wallet-mobile/src/hooks/useApiDialogs.tsx b/apps/wallet-mobile/src/hooks/useApiDialogs.tsx deleted file mode 100644 index ec9ff80d42..0000000000 --- a/apps/wallet-mobile/src/hooks/useApiDialogs.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import * as React from 'react' - -import {useApiStringsErrors} from './useApiStringsErrors' - -export const useApiDialogs = () => { - const strings = useApiStringsErrors() - - return React.useRef({ - errorBadRequest: { - title: strings.errorTitle, - message: strings.badRequest, - }, - errorUnauthorized: { - title: strings.errorTitle, - message: strings.unauthorized, - }, - errorForbidden: { - title: strings.errorTitle, - message: strings.forbidden, - }, - errorNotFound: { - title: strings.errorTitle, - message: strings.notFound, - }, - errorConflict: { - title: strings.errorTitle, - message: strings.conflict, - }, - errorGone: { - title: strings.errorTitle, - message: strings.gone, - }, - errorTooEarly: { - title: strings.errorTitle, - message: strings.tooEarly, - }, - errorTooManyRequests: { - title: strings.errorTitle, - message: strings.tooManyRequests, - }, - errorServerSide: { - title: strings.errorTitle, - message: strings.serverSide, - }, - errorUnknown: { - title: strings.errorTitle, - message: strings.unknown, - }, - errorNetwork: { - title: strings.errorTitle, - message: strings.network, - }, - errorInvalidState: { - title: strings.errorTitle, - message: strings.invalidState, - }, - errorResponseMalformed: { - title: strings.errorTitle, - message: strings.responseMalformed, - }, - } as const).current -} diff --git a/apps/wallet-mobile/src/hooks/useApiErrorResolver.tsx b/apps/wallet-mobile/src/hooks/useApiErrorResolver.tsx index be5f8673ed..79062802a2 100644 --- a/apps/wallet-mobile/src/hooks/useApiErrorResolver.tsx +++ b/apps/wallet-mobile/src/hooks/useApiErrorResolver.tsx @@ -1,27 +1,123 @@ import {Api} from '@yoroi/types' +import * as React from 'react' +import {useIntl} from 'react-intl' -import {useApiDialogs} from './useApiDialogs' +import {apiErrors} from '../kernel/i18n/global-messages' export const useApiErrorResolver = () => { - const dialogs = useApiDialogs() - - const resolver = (error: unknown) => { - if (error instanceof Api.Errors.BadRequest) return dialogs.errorBadRequest - if (error instanceof Api.Errors.Conflict) return dialogs.errorConflict - if (error instanceof Api.Errors.Forbidden) return dialogs.errorForbidden - if (error instanceof Api.Errors.Gone) return dialogs.errorGone - if (error instanceof Api.Errors.InvalidState) return dialogs.errorInvalidState - if (error instanceof Api.Errors.Network) return dialogs.errorNetwork - if (error instanceof Api.Errors.NotFound) return dialogs.errorNotFound - if (error instanceof Api.Errors.ResponseMalformed) return dialogs.errorResponseMalformed - if (error instanceof Api.Errors.ServerSide) return dialogs.errorServerSide - if (error instanceof Api.Errors.TooEarly) return dialogs.errorTooEarly - if (error instanceof Api.Errors.TooManyRequests) return dialogs.errorTooManyRequests - if (error instanceof Api.Errors.Unauthorized) return dialogs.errorUnauthorized - if (error instanceof Api.Errors.Unknown) return dialogs.errorUnknown - - return dialogs.errorUnknown - } + const strings = useApiStringsErrors() + + const dialogs = React.useRef({ + errorBadRequest: { + title: strings.errorTitle, + message: strings.badRequest, + }, + errorUnauthorized: { + title: strings.errorTitle, + message: strings.unauthorized, + }, + errorForbidden: { + title: strings.errorTitle, + message: strings.forbidden, + }, + errorNotFound: { + title: strings.errorTitle, + message: strings.notFound, + }, + errorConflict: { + title: strings.errorTitle, + message: strings.conflict, + }, + errorGone: { + title: strings.errorTitle, + message: strings.gone, + }, + errorTooEarly: { + title: strings.errorTitle, + message: strings.tooEarly, + }, + errorTooManyRequests: { + title: strings.errorTitle, + message: strings.tooManyRequests, + }, + errorServerSide: { + title: strings.errorTitle, + message: strings.serverSide, + }, + errorUnknown: { + title: strings.errorTitle, + message: strings.unknown, + }, + errorNetwork: { + title: strings.errorTitle, + message: strings.network, + }, + errorInvalidState: { + title: strings.errorTitle, + message: strings.invalidState, + }, + errorResponseMalformed: { + title: strings.errorTitle, + message: strings.responseMalformed, + }, + } as const).current + + const resolver = React.useCallback( + (error: unknown) => { + if (error instanceof Api.Errors.BadRequest) return dialogs.errorBadRequest + if (error instanceof Api.Errors.Conflict) return dialogs.errorConflict + if (error instanceof Api.Errors.Forbidden) return dialogs.errorForbidden + if (error instanceof Api.Errors.Gone) return dialogs.errorGone + if (error instanceof Api.Errors.InvalidState) return dialogs.errorInvalidState + if (error instanceof Api.Errors.Network) return dialogs.errorNetwork + if (error instanceof Api.Errors.NotFound) return dialogs.errorNotFound + if (error instanceof Api.Errors.ResponseMalformed) return dialogs.errorResponseMalformed + if (error instanceof Api.Errors.ServerSide) return dialogs.errorServerSide + if (error instanceof Api.Errors.TooEarly) return dialogs.errorTooEarly + if (error instanceof Api.Errors.TooManyRequests) return dialogs.errorTooManyRequests + if (error instanceof Api.Errors.Unauthorized) return dialogs.errorUnauthorized + if (error instanceof Api.Errors.Unknown) return dialogs.errorUnknown + + return dialogs.errorUnknown + }, + [ + dialogs.errorBadRequest, + dialogs.errorConflict, + dialogs.errorForbidden, + dialogs.errorGone, + dialogs.errorInvalidState, + dialogs.errorNetwork, + dialogs.errorNotFound, + dialogs.errorResponseMalformed, + dialogs.errorServerSide, + dialogs.errorTooEarly, + dialogs.errorTooManyRequests, + dialogs.errorUnauthorized, + dialogs.errorUnknown, + ], + ) return resolver } + +const useApiStringsErrors = () => { + const intl = useIntl() + + return React.useRef({ + errorTitle: intl.formatMessage(apiErrors.title), + + badRequest: intl.formatMessage(apiErrors.badRequest), + conflict: intl.formatMessage(apiErrors.conflict), + forbidden: intl.formatMessage(apiErrors.forbidden), + gone: intl.formatMessage(apiErrors.gone), + invalidState: intl.formatMessage(apiErrors.invalidState), + network: intl.formatMessage(apiErrors.network), + notFound: intl.formatMessage(apiErrors.notFound), + responseMalformed: intl.formatMessage(apiErrors.responseMalformed), + serverSide: intl.formatMessage(apiErrors.serverSide), + tooEarly: intl.formatMessage(apiErrors.tooEarly), + tooManyRequests: intl.formatMessage(apiErrors.tooManyRequests), + unauthorized: intl.formatMessage(apiErrors.unauthorized), + unknown: intl.formatMessage(apiErrors.unknown), + } as const).current +} diff --git a/apps/wallet-mobile/src/hooks/useApiStringsErrors.tsx b/apps/wallet-mobile/src/hooks/useApiStringsErrors.tsx deleted file mode 100644 index 1cd823dc9b..0000000000 --- a/apps/wallet-mobile/src/hooks/useApiStringsErrors.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import * as React from 'react' -import {useIntl} from 'react-intl' - -import {apiErrors} from '../kernel/i18n/global-messages' - -export const useApiStringsErrors = () => { - const intl = useIntl() - - return React.useRef({ - errorTitle: intl.formatMessage(apiErrors.title), - - badRequest: intl.formatMessage(apiErrors.badRequest), - conflict: intl.formatMessage(apiErrors.conflict), - forbidden: intl.formatMessage(apiErrors.forbidden), - gone: intl.formatMessage(apiErrors.gone), - invalidState: intl.formatMessage(apiErrors.invalidState), - network: intl.formatMessage(apiErrors.network), - notFound: intl.formatMessage(apiErrors.notFound), - responseMalformed: intl.formatMessage(apiErrors.responseMalformed), - serverSide: intl.formatMessage(apiErrors.serverSide), - tooEarly: intl.formatMessage(apiErrors.tooEarly), - tooManyRequests: intl.formatMessage(apiErrors.tooManyRequests), - unauthorized: intl.formatMessage(apiErrors.unauthorized), - unknown: intl.formatMessage(apiErrors.unknown), - } as const).current -} diff --git a/apps/wallet-mobile/src/kernel/constants.ts b/apps/wallet-mobile/src/kernel/constants.ts index b584a8155c..25cab59b6e 100644 --- a/apps/wallet-mobile/src/kernel/constants.ts +++ b/apps/wallet-mobile/src/kernel/constants.ts @@ -59,6 +59,7 @@ export const configCurrencies = freeze({ }) export const time = freeze({ + oneSecond: 1e3, oneMinute: 60 * 1e3, fiveMinutes: 5 * 60 * 1e3, halfHour: 30 * 60 * 1e3, diff --git a/apps/wallet-mobile/src/kernel/env.ts b/apps/wallet-mobile/src/kernel/env.ts index bd637dd438..5b404e5d11 100644 --- a/apps/wallet-mobile/src/kernel/env.ts +++ b/apps/wallet-mobile/src/kernel/env.ts @@ -18,3 +18,6 @@ export const banxaTestWallet = getString('BANXA_TEST_WALLET') export const dappExplorerEnabled = Boolean(BuildConfig['DAPP_EXPLORER_ENABLED']) export const disableLogbox = Boolean(BuildConfig['DISABLE_LOGBOX']) + +const possibleLoggerFilter = getString('LOGGER_FILTER') +export const loggerFilter = possibleLoggerFilter ? new RegExp(possibleLoggerFilter) : null diff --git a/apps/wallet-mobile/src/kernel/logger/hooks/useSetupLogger.tsx b/apps/wallet-mobile/src/kernel/logger/hooks/useSetupLogger.tsx index 556e4aeda2..de6c4e1a2d 100644 --- a/apps/wallet-mobile/src/kernel/logger/hooks/useSetupLogger.tsx +++ b/apps/wallet-mobile/src/kernel/logger/hooks/useSetupLogger.tsx @@ -9,7 +9,7 @@ import {Sentry} from '../adapters/sentry' import {sentryAdapter} from '../adapters/sentry-transporter' import {logger} from '../logger' -export const useSetupLogger = () => { +export const useSetupLogger = (filter: RegExp | null = null) => { const [done, setDone] = React.useState(false) React.useEffect(() => { @@ -18,7 +18,10 @@ export const useSetupLogger = () => { const isEnabled = await getCrashReportsEnabled() logger.level = loggerLevel - if (isDev) logger.addTransport(devAdapter().transporter) + if (isDev) { + logger.addTransport(devAdapter().transporter) + logger.filter = filter + } if (isEnabled) { logger.enable() @@ -44,7 +47,7 @@ export const useSetupLogger = () => { setDone(true) } initLogger() - }, []) + }, [filter]) return done } diff --git a/apps/wallet-mobile/src/kernel/logger/logger.ts b/apps/wallet-mobile/src/kernel/logger/logger.ts index 6433fd52df..59cf5fcefe 100644 --- a/apps/wallet-mobile/src/kernel/logger/logger.ts +++ b/apps/wallet-mobile/src/kernel/logger/logger.ts @@ -16,6 +16,7 @@ class Logger implements LoggerManager { #enabled = false #trail: Array = [] + filter: RegExp | null = null level = LoggerLevel.Info readonly #transporters: LoggerTransporter[] = [] @@ -80,6 +81,7 @@ class Logger implements LoggerManager { private transport({level, message, metadata}: Pick) { if (!this.#enabled) return if (loggerHierarchy[level] > loggerHierarchy[this.level]) return + if (this.filter && !this.filter.test(JSON.stringify({message, metadata}))) return const timestamp = Date.now() const entry = {level, message, metadata, timestamp} diff --git a/apps/wallet-mobile/src/kernel/navigation.tsx b/apps/wallet-mobile/src/kernel/navigation.tsx index 775019eae7..261ed5fa80 100644 --- a/apps/wallet-mobile/src/kernel/navigation.tsx +++ b/apps/wallet-mobile/src/kernel/navigation.tsx @@ -142,8 +142,9 @@ export type WalletInitRoutes = { 'setup-wallet-about-recovery-phase': undefined 'setup-wallet-recovery-phrase-mnemonic': undefined 'setup-wallet-verify-recovery-phrase-mnemonic': undefined + 'setup-wallet-preparing-wallet': undefined } -export type WalletInitRouteNavigation = StackNavigationProp +export type SetupWalletRouteNavigation = StackNavigationProp export type ReceiveRoutes = { 'receive-ada-main': undefined @@ -183,7 +184,7 @@ export type ClaimRoutes = { } export type SwapTokenRoutes = { - 'swap-start-swap': undefined + 'swap-start-swap': NavigatorScreenParams 'swap-confirm-tx': undefined 'swap-select-sell-token': undefined 'swap-select-buy-token': undefined @@ -191,7 +192,6 @@ export type SwapTokenRoutes = { 'swap-select-pool': undefined 'swap-submitted-tx': {txId: string} 'swap-failed-tx': undefined - 'manage-wallets': undefined } export type SwapTokenRouteseNavigation = StackNavigationProp @@ -214,7 +214,6 @@ export type ExchangeRoutes = { 'exchange-result': undefined 'exchange-select-buy-provider': undefined 'exchange-select-sell-provider': undefined - 'manage-wallets': undefined } export type ExchangeRoutesNavigation = StackNavigationProp diff --git a/apps/wallet-mobile/src/legacy/TxHistory/ActionsBanner.tsx b/apps/wallet-mobile/src/legacy/TxHistory/ActionsBanner.tsx index 11cb713bb5..9c2c877c17 100644 --- a/apps/wallet-mobile/src/legacy/TxHistory/ActionsBanner.tsx +++ b/apps/wallet-mobile/src/legacy/TxHistory/ActionsBanner.tsx @@ -263,7 +263,7 @@ const useNavigateTo = () => { send: () => navigation.navigate('send-start-tx'), receiveSingleAddress: () => navigation.navigate('receive-single'), receiveMultipleAddresses: () => navigation.navigate('receive-multiple'), - swap: () => navigation.navigate('swap-start-swap'), + swap: () => navigation.navigate('swap-start-swap', {screen: 'token-swap'}), exchange: () => navigation.navigate('exchange-create-order'), } } diff --git a/apps/wallet-mobile/translations/messages/src/features/SetupWallet/SetupWalletNavigator.json b/apps/wallet-mobile/translations/messages/src/features/SetupWallet/SetupWalletNavigator.json index 1b8cf454ec..fd6eeebba1 100644 --- a/apps/wallet-mobile/translations/messages/src/features/SetupWallet/SetupWalletNavigator.json +++ b/apps/wallet-mobile/translations/messages/src/features/SetupWallet/SetupWalletNavigator.json @@ -4,14 +4,14 @@ "defaultMessage": "!!!Add new wallet", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 144, + "line": 151, "column": 21, - "index": 5055 + "index": 5302 }, "end": { - "line": 147, + "line": 154, "column": 3, - "index": 5157 + "index": 5404 } }, { @@ -19,14 +19,14 @@ "defaultMessage": "!!!Create wallet", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 148, + "line": 155, "column": 21, - "index": 5180 + "index": 5427 }, "end": { - "line": 151, + "line": 158, "column": 3, - "index": 5296 + "index": 5543 } }, { @@ -34,14 +34,14 @@ "defaultMessage": "!!!Restore wallet", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 152, + "line": 159, "column": 22, - "index": 5320 + "index": 5567 }, "end": { - "line": 155, + "line": 162, "column": 3, - "index": 5439 + "index": 5686 } }, { @@ -49,14 +49,14 @@ "defaultMessage": "!!!Read-only Wallet", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 156, + "line": 163, "column": 23, - "index": 5464 + "index": 5711 }, "end": { - "line": 159, + "line": 166, "column": 3, - "index": 5578 + "index": 5825 } }, { @@ -64,14 +64,14 @@ "defaultMessage": "!!!Verify read-only wallet", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 160, + "line": 167, "column": 27, - "index": 5607 + "index": 5854 }, "end": { - "line": 163, + "line": 170, "column": 3, - "index": 5726 + "index": 5973 } }, { @@ -79,14 +79,14 @@ "defaultMessage": "!!!Recovery phrase", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 164, + "line": 171, "column": 21, - "index": 5749 + "index": 5996 }, "end": { - "line": 167, + "line": 174, "column": 3, - "index": 5867 + "index": 6114 } }, { @@ -94,14 +94,14 @@ "defaultMessage": "!!!Recovery phrase", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 168, + "line": 175, "column": 22, - "index": 5891 + "index": 6138 }, "end": { - "line": 171, + "line": 178, "column": 3, - "index": 6010 + "index": 6257 } }, { @@ -109,14 +109,14 @@ "defaultMessage": "!!!Verify restored wallet", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 172, + "line": 179, "column": 29, - "index": 6041 + "index": 6288 }, "end": { - "line": 175, + "line": 182, "column": 3, - "index": 6155 + "index": 6402 } }, { @@ -124,14 +124,14 @@ "defaultMessage": "!!!Wallet credentials", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 176, + "line": 183, "column": 26, - "index": 6183 + "index": 6430 }, "end": { - "line": 179, + "line": 186, "column": 3, - "index": 6310 + "index": 6557 } }, { @@ -139,14 +139,14 @@ "defaultMessage": "!!!Connect to Ledger Device", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 180, + "line": 187, "column": 21, - "index": 6333 + "index": 6580 }, "end": { - "line": 183, + "line": 190, "column": 3, - "index": 6460 + "index": 6707 } }, { @@ -154,14 +154,14 @@ "defaultMessage": "!!!Connect to Ledger Device", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 184, + "line": 191, "column": 19, - "index": 6481 + "index": 6728 }, "end": { - "line": 187, + "line": 194, "column": 3, - "index": 6606 + "index": 6853 } }, { @@ -169,14 +169,14 @@ "defaultMessage": "!!!Save wallet", "file": "src/features/SetupWallet/SetupWalletNavigator.tsx", "start": { - "line": 188, + "line": 195, "column": 18, - "index": 6626 + "index": 6873 }, "end": { - "line": 191, + "line": 198, "column": 3, - "index": 6737 + "index": 6984 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.json b/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.json index 6edb8733a3..ff9698e40e 100644 --- a/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.json +++ b/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.json @@ -6,12 +6,12 @@ "start": { "line": 67, "column": 13, - "index": 2403 + "index": 2405 }, "end": { "line": 70, "column": 3, - "index": 2549 + "index": 2551 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/ConnectNanoX/ConnectNanoXScreen.json b/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/ConnectNanoX/ConnectNanoXScreen.json index 38530c1ac2..2405a47714 100644 --- a/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/ConnectNanoX/ConnectNanoXScreen.json +++ b/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/ConnectNanoX/ConnectNanoXScreen.json @@ -6,12 +6,12 @@ "start": { "line": 82, "column": 13, - "index": 2905 + "index": 2907 }, "end": { "line": 85, "column": 3, - "index": 3077 + "index": 3079 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen.json b/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen.json index 2818b0c274..2ab51a14ec 100644 --- a/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen.json +++ b/apps/wallet-mobile/translations/messages/src/features/SetupWallet/legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen.json @@ -6,12 +6,12 @@ "start": { "line": 63, "column": 13, - "index": 2157 + "index": 2159 }, "end": { "line": 66, "column": 3, - "index": 2331 + "index": 2333 } }, { @@ -21,12 +21,12 @@ "start": { "line": 67, "column": 9, - "index": 2342 + "index": 2344 }, "end": { "line": 70, "column": 3, - "index": 2486 + "index": 2488 } }, { @@ -36,12 +36,12 @@ "start": { "line": 71, "column": 9, - "index": 2497 + "index": 2499 }, "end": { "line": 74, "column": 3, - "index": 2673 + "index": 2675 } }, { @@ -51,12 +51,12 @@ "start": { "line": 75, "column": 14, - "index": 2689 + "index": 2691 }, "end": { "line": 78, "column": 3, - "index": 2822 + "index": 2824 } } ] \ No newline at end of file diff --git a/packages/common/src/utils/arrays.test.ts b/packages/common/src/utils/arrays.test.ts index 1aa2497c9b..55ffdc0a5c 100644 --- a/packages/common/src/utils/arrays.test.ts +++ b/packages/common/src/utils/arrays.test.ts @@ -4,7 +4,7 @@ describe('Array Utils', () => { describe('difference', () => { it('should return the difference of two arrays', () => { const a = [1, 2, 3, 4, 5] - const b = [2, 4, 6] + const b = [2, 4, 6, 7] const result = difference(a, b) expect(result).toEqual([1, 3, 5]) }) diff --git a/packages/setup-wallet/src/translators/reactjs/provider/SetupWalletProvider.test.tsx b/packages/setup-wallet/src/translators/reactjs/provider/SetupWalletProvider.test.tsx index 24af58e3fa..94fda1016e 100644 --- a/packages/setup-wallet/src/translators/reactjs/provider/SetupWalletProvider.test.tsx +++ b/packages/setup-wallet/src/translators/reactjs/provider/SetupWalletProvider.test.tsx @@ -124,6 +124,16 @@ describe('SetupWalletContext :: hooks', () => { expect(result.current.showRestoreWalletInfoModal).toBe(true) }) + test('walletIdChanged', () => { + const {result} = renderHook(() => useSetupWallet(), {wrapper}) + + act(() => { + result.current.walletIdChanged('1') + }) + + expect(result.current.walletId).toBe('1') + }) + test('showCreateWalletInfoModalChanged', () => { const {result} = renderHook(() => useSetupWallet(), {wrapper}) diff --git a/packages/setup-wallet/src/translators/reactjs/provider/SetupWalletProvider.tsx b/packages/setup-wallet/src/translators/reactjs/provider/SetupWalletProvider.tsx index d99858dee4..3d72917009 100644 --- a/packages/setup-wallet/src/translators/reactjs/provider/SetupWalletProvider.tsx +++ b/packages/setup-wallet/src/translators/reactjs/provider/SetupWalletProvider.tsx @@ -74,6 +74,8 @@ export const SetupWalletProvider = ({ type: SetupWalletActionType.ShowCreateWalletInfoModalChanged, showCreateWalletInfoModal, }), + walletIdChanged: (walletId: SetupWalletState['walletId']) => + dispatch({type: SetupWalletActionType.WalletIdChanged, walletId}), }).current const context = React.useMemo( diff --git a/packages/setup-wallet/src/translators/reactjs/state/state.test.ts b/packages/setup-wallet/src/translators/reactjs/state/state.test.ts index a1727d5c24..6b500e66b3 100644 --- a/packages/setup-wallet/src/translators/reactjs/state/state.test.ts +++ b/packages/setup-wallet/src/translators/reactjs/state/state.test.ts @@ -59,6 +59,17 @@ describe('State Actions', () => { expect(state.networkId).toBe(action.networkId) }) + it('WalletIdChanged', () => { + const action: SetupWalletAction = { + type: SetupWalletActionType.WalletIdChanged, + walletId: '1', + } + + const state = setupWalletReducer(setupWalletDefaultState, action) + + expect(state.walletId).toBe(action.walletId) + }) + it('WalletImplementationIdChanged', () => { const action: SetupWalletAction = { type: SetupWalletActionType.WalletImplementationIdChanged, @@ -178,6 +189,7 @@ describe('State Actions', () => { useUSB: true, showCreateWalletInfoModal: true, showRestoreWalletInfoModal: true, + walletId: null, }, action, ) diff --git a/packages/setup-wallet/src/translators/reactjs/state/state.ts b/packages/setup-wallet/src/translators/reactjs/state/state.ts index a3ae8752c3..efe4082682 100644 --- a/packages/setup-wallet/src/translators/reactjs/state/state.ts +++ b/packages/setup-wallet/src/translators/reactjs/state/state.ts @@ -58,6 +58,10 @@ export const setupWalletReducer = ( draft.showRestoreWalletInfoModal = action.showRestoreWalletInfoModal return + case SetupWalletActionType.WalletIdChanged: + draft.walletId = action.walletId + return + case SetupWalletActionType.Reset: return setupWalletDefaultState @@ -82,6 +86,7 @@ export const setupWalletDefaultState: Readonly = freeze( useUSB: false, showRestoreWalletInfoModal: true, showCreateWalletInfoModal: true, + walletId: null, }, true, ) @@ -100,6 +105,7 @@ export type SetupWalletState = { useUSB: boolean showRestoreWalletInfoModal: boolean showCreateWalletInfoModal: boolean + walletId: string | null } export enum SetupWalletActionType { @@ -113,6 +119,7 @@ export enum SetupWalletActionType { HwDeviceInfoChanged = 'hwDeviceInfoChanged', SetUpTypeChanged = 'setUpTypeChanged', MnemonicTypeChanged = 'mnemonicTypeChanged', + WalletIdChanged = 'walletIdChanged', UseUSBChanged = 'useUSBChanged', Reset = 'reset', ShowRestoreWalletInfoModalChanged = 'showRestoreWalletInfoModalChanged', @@ -175,6 +182,10 @@ export type SetupWalletAction = type: SetupWalletActionType.ShowCreateWalletInfoModalChanged showCreateWalletInfoModal: SetupWalletState['showCreateWalletInfoModal'] } + | { + type: SetupWalletActionType.WalletIdChanged + walletId: SetupWalletState['walletId'] + } export type SetupWalletActions = { mnemonicChanged: (mnemonic: SetupWalletState['mnemonic']) => void @@ -192,6 +203,7 @@ export type SetupWalletActions = { setUpTypeChanged: (setUpType: SetupWalletState['setUpType']) => void mnemonicTypeChanged: (mnemonicType: SetupWalletState['mnemonicType']) => void useUSBChanged: (useUSB: SetupWalletState['useUSB']) => void + walletIdChanged: (walletId: SetupWalletState['walletId']) => void reset: () => void showRestoreWalletInfoModalChanged: ( showRestoreWalletInfoModal: boolean, @@ -217,6 +229,7 @@ export const setupWalletInitialContext: SetupWalletContext = freeze( reset: missingInit, showRestoreWalletInfoModalChanged: missingInit, showCreateWalletInfoModalChanged: missingInit, + walletIdChanged: missingInit, }, true, ) diff --git a/packages/theme/src/atoms/atoms.ts b/packages/theme/src/atoms/atoms.ts index 12f691aa07..0c239b345d 100644 --- a/packages/theme/src/atoms/atoms.ts +++ b/packages/theme/src/atoms/atoms.ts @@ -16,7 +16,7 @@ const fontFamily = { default: 'monospace', }), }, -} +} as const const size = { h1: { @@ -183,7 +183,7 @@ const typograpghy = { text_right: { textAlign: 'right', }, -} +} as const const padding = { p_0: {padding: tokens.space.none}, From 8b4bcb700128b59b138713978ffc8e2690c4fec0 Mon Sep 17 00:00:00 2001 From: banklesss <105349292+banklesss@users.noreply.github.com> Date: Thu, 30 May 2024 08:55:09 +0200 Subject: [PATCH 2/4] fix(common): privacy mode (#3273) Signed-off-by: banklesss <105349292+banklesss@users.noreply.github.com> --- apps/wallet-mobile/ios/Podfile.lock | 4 +- .../src/components/AmountItem/AmountItem.tsx | 6 +- .../components/HideableText/HideableText.tsx | 4 +- .../PairedBalance/PairedBalance.tsx | 6 +- .../TokenAmountItem/TokenAmountItem.tsx | 4 +- .../ApplicationSettingsScreen.tsx | 10 +-- .../ManageCollateralScreen.tsx | 4 +- .../Settings/PrivacyMode/PrivacyMode.tsx | 3 +- .../src/legacy/Dashboard/UserSummary.tsx | 8 +-- .../legacy/TxHistory/AssetList/AssetList.tsx | 4 +- .../src/legacy/TxHistory/BalanceBanner.tsx | 8 ++- .../src/legacy/TxHistory/LockedDeposit.tsx | 6 +- .../legacy/TxHistory/TxDetails/AssetList.tsx | 4 +- .../legacy/TxHistory/TxDetails/TxDetails.tsx | 4 +- .../TxHistoryList/TxHistoryListItem.tsx | 6 +- .../PairedBalance/PairedBalance.json | 4 +- .../ApplicationSettingsScreen.json | 72 +++++++++---------- .../src/legacy/Dashboard/UserSummary.json | 16 ++--- .../legacy/TxHistory/TxDetails/AssetList.json | 4 +- .../legacy/TxHistory/TxDetails/TxDetails.json | 64 ++++++++--------- .../TxHistoryList/TxHistoryListItem.json | 24 +++---- 21 files changed, 133 insertions(+), 132 deletions(-) diff --git a/apps/wallet-mobile/ios/Podfile.lock b/apps/wallet-mobile/ios/Podfile.lock index 9adeb1bc5c..8efec1c935 100644 --- a/apps/wallet-mobile/ios/Podfile.lock +++ b/apps/wallet-mobile/ios/Podfile.lock @@ -821,7 +821,7 @@ SPEC CHECKSUMS: amplitude-react-native: 1ea3d5e1f80ccc357dd178c55c29e51c89f1cd11 boost: 57d2868c099736d80fcd648bf211b4431e51a558 BVLinearGradient: e3aad03778a456d77928f594a649e96995f1c872 - DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953 + DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 EXApplication: d8f53a7eee90a870a75656280e8d4b85726ea903 EXBarCodeScanner: 8e23fae8d267dbef9f04817833a494200f1fce35 EXCamera: 0fbfa338a3776af2722d626a3437abe33f708aad @@ -838,7 +838,7 @@ SPEC CHECKSUMS: FBLazyVector: 12ea01e587c9594e7b144e1bfc86ac4d9ac28fde FBReactNativeSpec: faca7d16c37626ca5780a87adef703817722fe61 fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 - glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2 + glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88 libaom: 144606b1da4b5915a1054383c3a4459ccdb3c661 libavif: 84bbb62fb232c3018d6f1bab79beea87e35de7b7 diff --git a/apps/wallet-mobile/src/components/AmountItem/AmountItem.tsx b/apps/wallet-mobile/src/components/AmountItem/AmountItem.tsx index 260e3a473d..883a0d464a 100644 --- a/apps/wallet-mobile/src/components/AmountItem/AmountItem.tsx +++ b/apps/wallet-mobile/src/components/AmountItem/AmountItem.tsx @@ -16,7 +16,7 @@ export type AmountItemProps = { wallet: YoroiWallet amount: Balance.Amount style?: ViewProps['style'] - isPrivacyOff?: boolean + isPrivacyActive?: boolean status?: string inWallet?: boolean variant?: 'swap' @@ -25,7 +25,7 @@ export type AmountItemProps = { } export const AmountItem = ({ - isPrivacyOff, + isPrivacyActive, wallet, style, amount, @@ -84,7 +84,7 @@ export const AmountItem = ({ {priceImpactRisk === 'high' && } - {isPrivacyOff ? '**.*******' : formattedQuantity} + {isPrivacyActive ? '**.*******' : formattedQuantity} )} diff --git a/apps/wallet-mobile/src/components/HideableText/HideableText.tsx b/apps/wallet-mobile/src/components/HideableText/HideableText.tsx index 3749ca7f48..f3f716efe6 100644 --- a/apps/wallet-mobile/src/components/HideableText/HideableText.tsx +++ b/apps/wallet-mobile/src/components/HideableText/HideableText.tsx @@ -9,8 +9,8 @@ type Props = TextProps & { } export const HideableText = ({text, ...props}: Props) => { - const {isPrivacyOn} = usePrivacyMode() - const children = isPrivacyOn ? text : text?.replaceAll(/./g, '\u25CF') + const {isPrivacyActive} = usePrivacyMode() + const children = !isPrivacyActive ? text : text?.replaceAll(/./g, '\u25CF') return {children} } diff --git a/apps/wallet-mobile/src/components/PairedBalance/PairedBalance.tsx b/apps/wallet-mobile/src/components/PairedBalance/PairedBalance.tsx index 1626cf2ed1..e82e32db23 100644 --- a/apps/wallet-mobile/src/components/PairedBalance/PairedBalance.tsx +++ b/apps/wallet-mobile/src/components/PairedBalance/PairedBalance.tsx @@ -43,17 +43,17 @@ export const PairedBalance = React.forwardRef(({amount, te const Price = ({amount, textStyle, ignorePrivacy}: Props) => { const styles = useStyles() const wallet = useSelectedWallet() - const {isPrivacyOff, privacyPlaceholder} = usePrivacyMode() + const {isPrivacyActive, privacyPlaceholder} = usePrivacyMode() const {currency, config} = useCurrencyContext() const rate = useExchangeRate({wallet, to: currency}) const price = React.useMemo(() => { if (rate == null) return `... ${currency}` - return isPrivacyOff || ignorePrivacy + return !isPrivacyActive || ignorePrivacy === true ? `${amountBreakdown(amount).bn.times(rate).toFormat(config.decimals)} ${currency}` : `${privacyPlaceholder} ${currency}` - }, [amount, config.decimals, currency, ignorePrivacy, isPrivacyOff, privacyPlaceholder, rate]) + }, [amount, config.decimals, currency, ignorePrivacy, isPrivacyActive, privacyPlaceholder, rate]) return ( diff --git a/apps/wallet-mobile/src/features/Portfolio/common/TokenAmountItem/TokenAmountItem.tsx b/apps/wallet-mobile/src/features/Portfolio/common/TokenAmountItem/TokenAmountItem.tsx index 8823106ff8..59c15b3336 100644 --- a/apps/wallet-mobile/src/features/Portfolio/common/TokenAmountItem/TokenAmountItem.tsx +++ b/apps/wallet-mobile/src/features/Portfolio/common/TokenAmountItem/TokenAmountItem.tsx @@ -33,7 +33,7 @@ export const TokenAmountItem = ({ orderType, }: TokenAmountItemProps) => { const {styles, colors} = useStyles() - const {privacyPlaceholder, isPrivacyOff} = usePrivacyMode() + const {privacyPlaceholder, isPrivacyActive} = usePrivacyMode() const priceImpactRiskTheme = usePriceImpactRiskTheme(priceImpactRisk ?? 'none') const {info} = amount @@ -41,7 +41,7 @@ export const TokenAmountItem = ({ const detail = isPrimary ? info.description : info.fingerprint const name = infoExtractName(info) - const formattedQuantity = isPrivacyOff || ignorePrivacy ? amountFormatter()(amount) : privacyPlaceholder + const formattedQuantity = !isPrivacyActive && ignorePrivacy == true ? amountFormatter()(amount) : privacyPlaceholder const showSwapDetails = !isPrimary && variant === 'swap' const priceImpactRiskTextColor = orderType === 'market' ? priceImpactRiskTheme.text : colors.text diff --git a/apps/wallet-mobile/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.tsx b/apps/wallet-mobile/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.tsx index 39591e6c32..26a6bd4999 100644 --- a/apps/wallet-mobile/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.tsx +++ b/apps/wallet-mobile/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.tsx @@ -26,7 +26,7 @@ export const ApplicationSettingsScreen = () => { const {languageCode, supportedLanguages} = useLanguage() const language = supportedLanguages.find((lang) => lang.code === languageCode) ?? defaultLanguage - const {isTogglePrivacyModeLoading, isPrivacyOff} = usePrivacyMode() + const {isTogglePrivacyModeLoading, isPrivacyActive} = usePrivacyMode() const {currency} = useCurrencyContext() const {enabled: crashReportEnabled} = useCrashReports() @@ -119,7 +119,7 @@ export const ApplicationSettingsScreen = () => { label={strings.privacyMode} info={strings.privacyModeInfo} > - + { } // to avoid switch jumps -const PrivacyModeSwitch = ({isPrivacyOff}: {isPrivacyOff: boolean}) => { +const PrivacyModeSwitch = ({isPrivacyActive}: {isPrivacyActive: boolean}) => { const {setPrivacyModeOn, setPrivacyModeOff, isTogglePrivacyModeLoading} = usePrivacyMode() - const [isLocalPrivacyOff, setIsLocalPrivacyOff] = React.useState(isPrivacyOff) + const [isLocalPrivacyActive, setIsLocalPrivacyOff] = React.useState(isPrivacyActive) const onTogglePrivacyMode = () => { setIsLocalPrivacyOff((prevState) => { @@ -182,7 +182,7 @@ const PrivacyModeSwitch = ({isPrivacyOff}: {isPrivacyOff: boolean}) => { return ( diff --git a/apps/wallet-mobile/src/features/Settings/ManageCollateral/ManageCollateralScreen.tsx b/apps/wallet-mobile/src/features/Settings/ManageCollateral/ManageCollateralScreen.tsx index ef56fa645c..9cbd34ee1e 100644 --- a/apps/wallet-mobile/src/features/Settings/ManageCollateral/ManageCollateralScreen.tsx +++ b/apps/wallet-mobile/src/features/Settings/ManageCollateral/ManageCollateralScreen.tsx @@ -187,14 +187,14 @@ type ActionableAmountProps = { } const ActionableAmount = ({amount, onRemove, wallet, collateralId, disabled}: ActionableAmountProps) => { const {styles} = useStyles() - const {isPrivacyOff} = usePrivacyMode() + const {isPrivacyActive} = usePrivacyMode() const handleRemove = () => onRemove() return ( - + {collateralId !== '' && ( diff --git a/apps/wallet-mobile/src/features/Settings/PrivacyMode/PrivacyMode.tsx b/apps/wallet-mobile/src/features/Settings/PrivacyMode/PrivacyMode.tsx index c951ff1cba..bc20c3631c 100644 --- a/apps/wallet-mobile/src/features/Settings/PrivacyMode/PrivacyMode.tsx +++ b/apps/wallet-mobile/src/features/Settings/PrivacyMode/PrivacyMode.tsx @@ -62,8 +62,7 @@ export const usePrivacyMode = () => { const writePrivacyMode = useWritePrivacyMode() return { - isPrivacyOff: privacyMode === 'HIDDEN', - isPrivacyOn: privacyMode === 'SHOWN', + isPrivacyActive: privacyMode === 'HIDDEN', privacyMode, togglePrivacyMode, isTogglePrivacyModeLoading, diff --git a/apps/wallet-mobile/src/legacy/Dashboard/UserSummary.tsx b/apps/wallet-mobile/src/legacy/Dashboard/UserSummary.tsx index 63562fb638..7411ed89d5 100644 --- a/apps/wallet-mobile/src/legacy/Dashboard/UserSummary.tsx +++ b/apps/wallet-mobile/src/legacy/Dashboard/UserSummary.tsx @@ -25,7 +25,7 @@ export const UserSummary = ({totalAdaSum, totalRewards, totalDelegated, onWithdr const styles = useStyles() const strings = useStrings() const wallet = useSelectedWallet() - const {isPrivacyOn} = usePrivacyMode() + const {isPrivacyActive} = usePrivacyMode() return ( @@ -40,7 +40,7 @@ export const UserSummary = ({totalAdaSum, totalRewards, totalDelegated, onWithdr {strings.availableFunds}: - {isPrivacyOn + {!isPrivacyActive ? totalAdaSum != null ? formatAdaWithText(asQuantity(totalAdaSum), wallet.primaryToken) : '-' @@ -58,7 +58,7 @@ export const UserSummary = ({totalAdaSum, totalRewards, totalDelegated, onWithdr {strings.rewardsLabel}: - {isPrivacyOn + {!isPrivacyActive ? totalRewards != null ? formatAdaWithText(asQuantity(totalRewards), wallet.primaryToken) : '-' @@ -88,7 +88,7 @@ export const UserSummary = ({totalAdaSum, totalRewards, totalDelegated, onWithdr {strings.delegatedLabel}: - {isPrivacyOn + {!isPrivacyActive ? totalDelegated != null ? formatAdaWithText(asQuantity(totalDelegated), wallet.primaryToken) : '-' diff --git a/apps/wallet-mobile/src/legacy/TxHistory/AssetList/AssetList.tsx b/apps/wallet-mobile/src/legacy/TxHistory/AssetList/AssetList.tsx index 9cfb6c5628..7a2a077ecc 100644 --- a/apps/wallet-mobile/src/legacy/TxHistory/AssetList/AssetList.tsx +++ b/apps/wallet-mobile/src/legacy/TxHistory/AssetList/AssetList.tsx @@ -65,10 +65,10 @@ type ExplorableAssetItemProps = AmountItemProps & { } const ExplorableAssetItem = ({wallet, amount, onPress}: ExplorableAssetItemProps) => { const styles = useStyles() - const {isPrivacyOff} = usePrivacyMode() + const {isPrivacyActive} = usePrivacyMode() return ( - + ) } diff --git a/apps/wallet-mobile/src/legacy/TxHistory/BalanceBanner.tsx b/apps/wallet-mobile/src/legacy/TxHistory/BalanceBanner.tsx index b349aad464..3362677f1e 100644 --- a/apps/wallet-mobile/src/legacy/TxHistory/BalanceBanner.tsx +++ b/apps/wallet-mobile/src/legacy/TxHistory/BalanceBanner.tsx @@ -42,15 +42,17 @@ export const BalanceBanner = React.forwardRef((_, ref) => { type BalanceProps = {amount: Portfolio.Token.Amount; ignorePrivacy?: boolean} const Balance = ({amount, ignorePrivacy}: BalanceProps) => { - const {isPrivacyOff, privacyPlaceholder} = usePrivacyMode() + const {isPrivacyActive, privacyPlaceholder} = usePrivacyMode() const styles = useStyles() + console.log('ignorePrivacy', ignorePrivacy) + const balance = React.useMemo( () => - isPrivacyOff || ignorePrivacy + !isPrivacyActive || ignorePrivacy === true ? amountFormatter({template: '{{value}} {{ticker}}'})(amount) : amountFormatter({template: `${privacyPlaceholder} {{ticker}}`})(amount), - [amount, ignorePrivacy, isPrivacyOff, privacyPlaceholder], + [amount, ignorePrivacy, isPrivacyActive, privacyPlaceholder], ) return ( diff --git a/apps/wallet-mobile/src/legacy/TxHistory/LockedDeposit.tsx b/apps/wallet-mobile/src/legacy/TxHistory/LockedDeposit.tsx index 1bb8dfd4a1..36af3c428e 100644 --- a/apps/wallet-mobile/src/legacy/TxHistory/LockedDeposit.tsx +++ b/apps/wallet-mobile/src/legacy/TxHistory/LockedDeposit.tsx @@ -12,12 +12,12 @@ import globalMessages from '../../kernel/i18n/global-messages' export const LockedDeposit = ({ignorePrivacy = false}: {ignorePrivacy?: boolean}) => { const wallet = useSelectedWallet() - const {isPrivacyOff, privacyPlaceholder} = usePrivacyMode() + const {isPrivacyActive, privacyPlaceholder} = usePrivacyMode() const {lockedAsStorageCost} = usePortfolioPrimaryBreakdown({wallet}) const amount = React.useMemo( () => - isPrivacyOff || ignorePrivacy + !isPrivacyActive || !ignorePrivacy ? amountFormatter({template: '{{value}} {{ticker}}'})({ quantity: lockedAsStorageCost, info: wallet.portfolioPrimaryTokenInfo, @@ -26,7 +26,7 @@ export const LockedDeposit = ({ignorePrivacy = false}: {ignorePrivacy?: boolean} quantity: 0n, info: wallet.portfolioPrimaryTokenInfo, }), - [ignorePrivacy, isPrivacyOff, lockedAsStorageCost, privacyPlaceholder, wallet.portfolioPrimaryTokenInfo], + [ignorePrivacy, isPrivacyActive, lockedAsStorageCost, privacyPlaceholder, wallet.portfolioPrimaryTokenInfo], ) return diff --git a/apps/wallet-mobile/src/legacy/TxHistory/TxDetails/AssetList.tsx b/apps/wallet-mobile/src/legacy/TxHistory/TxDetails/AssetList.tsx index 06b853fef1..de0b952b5c 100644 --- a/apps/wallet-mobile/src/legacy/TxHistory/TxDetails/AssetList.tsx +++ b/apps/wallet-mobile/src/legacy/TxHistory/TxDetails/AssetList.tsx @@ -56,7 +56,7 @@ type AssetRowProps = { const AssetRow = ({styles, entry, backColor, onSelect}: AssetRowProps) => { const intl = useIntl() const wallet = useSelectedWallet() - const {isPrivacyOn, privacyPlaceholder} = usePrivacyMode() + const {isPrivacyActive, privacyPlaceholder} = usePrivacyMode() const tokenInfo = useTokenInfo({wallet, tokenId: entry.identifier}) const isPrimary = tokenInfo.id === wallet.primaryTokenInfo.id const primaryTicker = wallet.primaryTokenInfo.ticker @@ -75,7 +75,7 @@ const AssetRow = ({styles, entry, backColor, onSelect}: AssetRowProps) => { - {isPrivacyOn ? privacyPlaceholder : formatTokenAmount(asQuantity(entry.amount), tokenInfo)} + {isPrivacyActive ? privacyPlaceholder : formatTokenAmount(asQuantity(entry.amount), tokenInfo)} diff --git a/apps/wallet-mobile/src/legacy/TxHistory/TxDetails/TxDetails.tsx b/apps/wallet-mobile/src/legacy/TxHistory/TxDetails/TxDetails.tsx index baf7f3a56d..300e6de989 100644 --- a/apps/wallet-mobile/src/legacy/TxHistory/TxDetails/TxDetails.tsx +++ b/apps/wallet-mobile/src/legacy/TxHistory/TxDetails/TxDetails.tsx @@ -197,10 +197,10 @@ const Label = ({children}: {children: string}) => { const AdaAmount = ({amount}: {amount: BigNumber}) => { const wallet = useSelectedWallet() const {styles} = useStyles() - const {isPrivacyOn, privacyPlaceholder} = usePrivacyMode() + const {isPrivacyActive, privacyPlaceholder} = usePrivacyMode() const amountStyle = amount.gte(0) ? styles.positiveAmount : styles.negativeAmount - if (isPrivacyOn) { + if (isPrivacyActive) { return {privacyPlaceholder} } diff --git a/apps/wallet-mobile/src/legacy/TxHistory/TxHistoryList/TxHistoryListItem.tsx b/apps/wallet-mobile/src/legacy/TxHistory/TxHistoryList/TxHistoryListItem.tsx index d762fa2de1..4ac3a6afbb 100644 --- a/apps/wallet-mobile/src/legacy/TxHistory/TxHistoryList/TxHistoryListItem.tsx +++ b/apps/wallet-mobile/src/legacy/TxHistory/TxHistoryList/TxHistoryListItem.tsx @@ -115,7 +115,7 @@ const Middle = ({style, ...props}: ViewProps) => ( const Right = ({style, ...props}: ViewProps) => const Amount = ({wallet, transaction}: {wallet: YoroiWallet; transaction: TransactionInfo}) => { const {styles} = useStyles() - const {isPrivacyOff, privacyPlaceholder} = usePrivacyMode() + const {isPrivacyActive, privacyPlaceholder} = usePrivacyMode() const amountAsMT = MultiToken.fromArray(transaction.amount) const amount: BigNumber = amountAsMT.getDefault() const fee = transaction.fee ? transaction.fee[0] : null @@ -129,10 +129,10 @@ const Amount = ({wallet, transaction}: {wallet: YoroiWallet; transaction: Transa return ( - {isPrivacyOff && formatTokenInteger(asQuantity(amount), wallet.primaryToken)} + {!isPrivacyActive && formatTokenInteger(asQuantity(amount), wallet.primaryToken)} - {isPrivacyOff ? formatTokenFractional(asQuantity(amount), wallet.primaryToken) : privacyPlaceholder} + {!isPrivacyActive ? formatTokenFractional(asQuantity(amount), wallet.primaryToken) : privacyPlaceholder} diff --git a/apps/wallet-mobile/translations/messages/src/components/PairedBalance/PairedBalance.json b/apps/wallet-mobile/translations/messages/src/components/PairedBalance/PairedBalance.json index 63b4de02b0..6adb27a21f 100644 --- a/apps/wallet-mobile/translations/messages/src/components/PairedBalance/PairedBalance.json +++ b/apps/wallet-mobile/translations/messages/src/components/PairedBalance/PairedBalance.json @@ -6,12 +6,12 @@ "start": { "line": 74, "column": 22, - "index": 2559 + "index": 2578 }, "end": { "line": 77, "column": 3, - "index": 2691 + "index": 2710 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.json b/apps/wallet-mobile/translations/messages/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.json index 44b37624d2..366382b60e 100644 --- a/apps/wallet-mobile/translations/messages/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.json +++ b/apps/wallet-mobile/translations/messages/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.json @@ -6,12 +6,12 @@ "start": { "line": 252, "column": 11, - "index": 8896 + "index": 8920 }, "end": { "line": 255, "column": 3, - "index": 9006 + "index": 9030 } }, { @@ -21,12 +21,12 @@ "start": { "line": 256, "column": 21, - "index": 9029 + "index": 9053 }, "end": { "line": 259, "column": 3, - "index": 9162 + "index": 9186 } }, { @@ -36,12 +36,12 @@ "start": { "line": 260, "column": 18, - "index": 9182 + "index": 9206 }, "end": { "line": 263, "column": 3, - "index": 9294 + "index": 9318 } }, { @@ -51,12 +51,12 @@ "start": { "line": 264, "column": 15, - "index": 9311 + "index": 9335 }, "end": { "line": 267, "column": 3, - "index": 9417 + "index": 9441 } }, { @@ -66,12 +66,12 @@ "start": { "line": 268, "column": 22, - "index": 9441 + "index": 9465 }, "end": { "line": 271, "column": 3, - "index": 9562 + "index": 9586 } }, { @@ -81,12 +81,12 @@ "start": { "line": 272, "column": 9, - "index": 9573 + "index": 9597 }, "end": { "line": 275, "column": 3, - "index": 9673 + "index": 9697 } }, { @@ -96,12 +96,12 @@ "start": { "line": 276, "column": 18, - "index": 9693 + "index": 9717 }, "end": { "line": 279, "column": 3, - "index": 9820 + "index": 9844 } }, { @@ -111,12 +111,12 @@ "start": { "line": 280, "column": 13, - "index": 9835 + "index": 9859 }, "end": { "line": 283, "column": 3, - "index": 9944 + "index": 9968 } }, { @@ -126,12 +126,12 @@ "start": { "line": 284, "column": 15, - "index": 9961 + "index": 9985 }, "end": { "line": 287, "column": 3, - "index": 10074 + "index": 10098 } }, { @@ -141,12 +141,12 @@ "start": { "line": 288, "column": 19, - "index": 10095 + "index": 10119 }, "end": { "line": 291, "column": 3, - "index": 10256 + "index": 10280 } }, { @@ -156,12 +156,12 @@ "start": { "line": 292, "column": 20, - "index": 10278 + "index": 10302 }, "end": { "line": 295, "column": 3, - "index": 10412 + "index": 10436 } }, { @@ -171,12 +171,12 @@ "start": { "line": 296, "column": 24, - "index": 10438 + "index": 10462 }, "end": { "line": 299, "column": 3, - "index": 10621 + "index": 10645 } }, { @@ -186,12 +186,12 @@ "start": { "line": 300, "column": 18, - "index": 10641 + "index": 10665 }, "end": { "line": 303, "column": 3, - "index": 10772 + "index": 10796 } }, { @@ -201,12 +201,12 @@ "start": { "line": 304, "column": 22, - "index": 10796 + "index": 10820 }, "end": { "line": 307, "column": 3, - "index": 10977 + "index": 11001 } }, { @@ -216,12 +216,12 @@ "start": { "line": 308, "column": 13, - "index": 10992 + "index": 11016 }, "end": { "line": 311, "column": 3, - "index": 11100 + "index": 11124 } }, { @@ -231,12 +231,12 @@ "start": { "line": 312, "column": 17, - "index": 11119 + "index": 11143 }, "end": { "line": 315, "column": 3, - "index": 11236 + "index": 11260 } }, { @@ -246,12 +246,12 @@ "start": { "line": 316, "column": 17, - "index": 11255 + "index": 11279 }, "end": { "line": 319, "column": 3, - "index": 11378 + "index": 11402 } }, { @@ -261,12 +261,12 @@ "start": { "line": 320, "column": 21, - "index": 11401 + "index": 11425 }, "end": { "line": 324, "column": 3, - "index": 11619 + "index": 11643 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/UserSummary.json b/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/UserSummary.json index 027c78cc3f..2e953924a7 100644 --- a/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/UserSummary.json +++ b/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/UserSummary.json @@ -6,12 +6,12 @@ "start": { "line": 164, "column": 9, - "index": 4872 + "index": 4891 }, "end": { "line": 167, "column": 3, - "index": 4974 + "index": 4993 } }, { @@ -21,12 +21,12 @@ "start": { "line": 168, "column": 16, - "index": 4992 + "index": 5011 }, "end": { "line": 171, "column": 3, - "index": 5102 + "index": 5121 } }, { @@ -36,12 +36,12 @@ "start": { "line": 172, "column": 18, - "index": 5122 + "index": 5141 }, "end": { "line": 175, "column": 3, - "index": 5236 + "index": 5255 } }, { @@ -51,12 +51,12 @@ "start": { "line": 176, "column": 23, - "index": 5261 + "index": 5280 }, "end": { "line": 179, "column": 3, - "index": 5373 + "index": 5392 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxDetails/AssetList.json b/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxDetails/AssetList.json index d8cb27cdfd..0f04144121 100644 --- a/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxDetails/AssetList.json +++ b/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxDetails/AssetList.json @@ -6,12 +6,12 @@ "start": { "line": 96, "column": 20, - "index": 3465 + "index": 3473 }, "end": { "line": 99, "column": 3, - "index": 3558 + "index": 3566 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxDetails/TxDetails.json b/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxDetails/TxDetails.json index 7ff4f82a27..02b420efd2 100644 --- a/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxDetails/TxDetails.json +++ b/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxDetails/TxDetails.json @@ -6,12 +6,12 @@ "start": { "line": 350, "column": 8, - "index": 12289 + "index": 12297 }, "end": { "line": 353, "column": 3, - "index": 12384 + "index": 12392 } }, { @@ -21,12 +21,12 @@ "start": { "line": 354, "column": 12, - "index": 12398 + "index": 12406 }, "end": { "line": 357, "column": 3, - "index": 12501 + "index": 12509 } }, { @@ -36,12 +36,12 @@ "start": { "line": 358, "column": 8, - "index": 12511 + "index": 12519 }, "end": { "line": 361, "column": 3, - "index": 12619 + "index": 12627 } }, { @@ -51,12 +51,12 @@ "start": { "line": 362, "column": 9, - "index": 12630 + "index": 12638 }, "end": { "line": 365, "column": 3, - "index": 12739 + "index": 12747 } }, { @@ -66,12 +66,12 @@ "start": { "line": 369, "column": 24, - "index": 12803 + "index": 12811 }, "end": { "line": 372, "column": 3, - "index": 12904 + "index": 12912 } }, { @@ -81,12 +81,12 @@ "start": { "line": 373, "column": 23, - "index": 12929 + "index": 12937 }, "end": { "line": 376, "column": 3, - "index": 13030 + "index": 13038 } }, { @@ -96,12 +96,12 @@ "start": { "line": 377, "column": 24, - "index": 13056 + "index": 13064 }, "end": { "line": 380, "column": 3, - "index": 13159 + "index": 13167 } }, { @@ -111,12 +111,12 @@ "start": { "line": 381, "column": 7, - "index": 13168 + "index": 13176 }, "end": { "line": 384, "column": 3, - "index": 13251 + "index": 13259 } }, { @@ -126,12 +126,12 @@ "start": { "line": 385, "column": 17, - "index": 13270 + "index": 13278 }, "end": { "line": 388, "column": 3, - "index": 13372 + "index": 13380 } }, { @@ -141,12 +141,12 @@ "start": { "line": 389, "column": 15, - "index": 13389 + "index": 13397 }, "end": { "line": 392, "column": 3, - "index": 13487 + "index": 13495 } }, { @@ -156,12 +156,12 @@ "start": { "line": 393, "column": 8, - "index": 13497 + "index": 13505 }, "end": { "line": 396, "column": 3, - "index": 13580 + "index": 13588 } }, { @@ -171,12 +171,12 @@ "start": { "line": 397, "column": 17, - "index": 13599 + "index": 13607 }, "end": { "line": 400, "column": 3, - "index": 13701 + "index": 13709 } }, { @@ -186,12 +186,12 @@ "start": { "line": 401, "column": 20, - "index": 13723 + "index": 13731 }, "end": { "line": 404, "column": 3, - "index": 13841 + "index": 13849 } }, { @@ -201,12 +201,12 @@ "start": { "line": 405, "column": 17, - "index": 13860 + "index": 13868 }, "end": { "line": 408, "column": 3, - "index": 14009 + "index": 14017 } }, { @@ -216,12 +216,12 @@ "start": { "line": 409, "column": 16, - "index": 14027 + "index": 14035 }, "end": { "line": 412, "column": 3, - "index": 14176 + "index": 14184 } }, { @@ -231,12 +231,12 @@ "start": { "line": 413, "column": 18, - "index": 14196 + "index": 14204 }, "end": { "line": 416, "column": 3, - "index": 14277 + "index": 14285 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxHistoryList/TxHistoryListItem.json b/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxHistoryList/TxHistoryListItem.json index 21b5505156..54e4fdb70f 100644 --- a/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxHistoryList/TxHistoryListItem.json +++ b/apps/wallet-mobile/translations/messages/src/legacy/TxHistory/TxHistoryList/TxHistoryListItem.json @@ -6,12 +6,12 @@ "start": { "line": 183, "column": 7, - "index": 6329 + "index": 6340 }, "end": { "line": 186, "column": 3, - "index": 6418 + "index": 6429 } }, { @@ -21,12 +21,12 @@ "start": { "line": 187, "column": 23, - "index": 6443 + "index": 6454 }, "end": { "line": 190, "column": 3, - "index": 6553 + "index": 6564 } }, { @@ -36,12 +36,12 @@ "start": { "line": 191, "column": 27, - "index": 6582 + "index": 6593 }, "end": { "line": 194, "column": 3, - "index": 6700 + "index": 6711 } }, { @@ -51,12 +51,12 @@ "start": { "line": 195, "column": 23, - "index": 6725 + "index": 6736 }, "end": { "line": 198, "column": 3, - "index": 6838 + "index": 6849 } }, { @@ -66,12 +66,12 @@ "start": { "line": 199, "column": 24, - "index": 6864 + "index": 6875 }, "end": { "line": 202, "column": 3, - "index": 6977 + "index": 6988 } }, { @@ -82,12 +82,12 @@ "start": { "line": 203, "column": 10, - "index": 6989 + "index": 7000 }, "end": { "line": 207, "column": 3, - "index": 7141 + "index": 7152 } } ] \ No newline at end of file From 8ca8ed237286d18bfe3098c53d60f0dd6c040f55 Mon Sep 17 00:00:00 2001 From: banklesss <105349292+banklesss@users.noreply.github.com> Date: Thu, 30 May 2024 08:56:27 +0200 Subject: [PATCH 3/4] feature(links): add nmkr partner support (#3277) --- apps/wallet-mobile/package.json | 2 +- packages/exchange/package.json | 2 +- packages/exchange/src/adapters/api.ts | 8 ++++++++ packages/links/README.md | 7 +++---- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/wallet-mobile/package.json b/apps/wallet-mobile/package.json index 877a68d992..81a20b5fbe 100644 --- a/apps/wallet-mobile/package.json +++ b/apps/wallet-mobile/package.json @@ -124,7 +124,7 @@ "@types/pbkdf2": "^3.1.2", "@yoroi/api": "1.5.1", "@yoroi/common": "1.5.2", - "@yoroi/exchange": "2.0.1", + "@yoroi/exchange": "2.1.0", "@yoroi/explorers": "1.0.0", "@yoroi/links": "1.5.4", "@yoroi/portfolio": "1.0.0", diff --git a/packages/exchange/package.json b/packages/exchange/package.json index 27a06aa5bc..d807d5d6dc 100644 --- a/packages/exchange/package.json +++ b/packages/exchange/package.json @@ -1,6 +1,6 @@ { "name": "@yoroi/exchange", - "version": "2.0.1", + "version": "2.1.0", "description": "The Exchange package of Yoroi SDK", "keywords": [ "yoroi", diff --git a/packages/exchange/src/adapters/api.ts b/packages/exchange/src/adapters/api.ts index cc29c56db3..153e742897 100644 --- a/packages/exchange/src/adapters/api.ts +++ b/packages/exchange/src/adapters/api.ts @@ -80,6 +80,14 @@ export const providers: Readonly> = freeze( supportUrl: 'https://support.encryptus.com/', appId: '18d1545a-a59b-45cb-a180-157b110c77fe', }, + nmkr: { + id: 'nmkr', + name: 'NMKR', + logo: 'nmkr', + supportUrl: 'https://www.nmkr.io/support', + appId: 'fee6bfc1-6934-418a-aa78-5eea5cf1b576', + supportedOrders: {}, + }, }, true, ) diff --git a/packages/links/README.md b/packages/links/README.md index 12efe31ee8..87bc95a732 100644 --- a/packages/links/README.md +++ b/packages/links/README.md @@ -106,8 +106,7 @@ const cardanoLink = create({ const yoroiPaymentRequestWithAdaLink = transfer.request.adaWithLink({ link: cardanoLink.link, - business: 'exchange', - partnerId: 'encryptus', + appId: 'app-id', authorization: 'uuid-v4', redirectTo: 'https://my.amazing.web/?amountRequested=1&session=03bf4dd213d', }) @@ -142,8 +141,8 @@ Yoroi validates deeplinks and univeral links in a stricted way, missing params i This schema is designed for adding information about how Yoroi should behave, even though all are flagged as optional, it will change how Yoroi reacts to it, and for some funnels it might block the user, or trigger some red alerts about dangerous actions. **`PartnerInfoParams` is part of all links**. It includes the following fields: - `isSandbox`: A boolean indicating the environment, when `true` deeplinks only work on non-production builds. -- `isTestnet`: A boolean that restrics whether it should list only `mainnet` wallets or testnets wallets. -- `appId`: A string with a maximum length of 40 characters that identifies that app. +- `isTestnet`: A boolean that restrics whether it should list only `mainnet` wallets or testnets wallets. +- `appId`: A string with a maximum length of 40 characters that identifies that app. - `redirectTo`: Yoroi may present a link button or automatic redirect the user based on funnel. - `authorization`: All actions initiated within Yoroi will provide an authorization, that works along with the wallet used. - `message`: Yoroi may present this message for some actions, be descriptive and concise around the action needed from Yoroi, otherwise users might reject your request. From e2439ad14e49bfaf2e86373b556fc6e3c992d741 Mon Sep 17 00:00:00 2001 From: Rahul <62512215+rahulnr7@users.noreply.github.com> Date: Thu, 30 May 2024 12:27:07 +0530 Subject: [PATCH 4/4] e2e(revamp UI): tests for create and restore funnels (#3275) --- .../src/components/Button/Button.tsx | 10 ++- .../common/ButtonCard/ButtonCard.tsx | 4 +- .../CardAboutPhrase/CardAboutPhrase.tsx | 6 +- .../ChooseMnemonicTypeScreen.tsx | 2 + .../ChooseNetwork/ChooseNetworkScreen.tsx | 3 + .../ChooseSetupType/ChooseSetupTypeScreen.tsx | 3 + .../AboutRecoveryPhraseScreen.tsx | 1 + .../CreateWallet/RecoveryPhraseScreen.tsx | 15 +++- .../VerifyRecoveryPhraseScreen.tsx | 1 + .../CreateWallet/WalletDetailsScreen.tsx | 2 + .../MnemonicInput/MnemonicInput.tsx | 5 +- .../RestoreWalletDetailsScreen.tsx | 5 +- .../RestoreWallet/RestoreWalletScreen.tsx | 2 +- e2e/wallet-mobile/general/utils.ts | 2 - .../screens/chooseMnemonicType.screen.ts | 4 + .../screens/chooseNetworkType.screen.ts | 7 ++ .../screens/chooseSetupType.screen.ts | 6 ++ .../screens/createWalletSteps.screen.ts | 48 +++++++++++ .../screens/restoreWalletFlow.screen.ts | 34 +++++--- .../tests/_android/create-wallet.test.ts | 83 ++++++++++++------- .../tests/_android/restore-wallet.test.ts | 52 +++++++----- .../tests/_ios/create-wallet.test.ts | 83 ++++++++++++------- .../tests/_ios/restore-wallet.test.ts | 56 +++++++------ .../tests/_ios_check/swap-ADA-WMT.test.ts | 79 ------------------ 24 files changed, 304 insertions(+), 209 deletions(-) create mode 100644 e2e/wallet-mobile/screens/chooseMnemonicType.screen.ts create mode 100644 e2e/wallet-mobile/screens/chooseNetworkType.screen.ts create mode 100644 e2e/wallet-mobile/screens/chooseSetupType.screen.ts create mode 100644 e2e/wallet-mobile/screens/createWalletSteps.screen.ts delete mode 100644 e2e/wallet-mobile/tests/_ios_check/swap-ADA-WMT.test.ts diff --git a/apps/wallet-mobile/src/components/Button/Button.tsx b/apps/wallet-mobile/src/components/Button/Button.tsx index f104e372d2..f6cbe40a71 100644 --- a/apps/wallet-mobile/src/components/Button/Button.tsx +++ b/apps/wallet-mobile/src/components/Button/Button.tsx @@ -19,6 +19,7 @@ export type ButtonProps = TouchableOpacityProps & { textStyles?: TextStyle isCopying?: boolean copiedText?: string + testId?: string } export const Button = (props: ButtonProps) => { @@ -38,13 +39,20 @@ export const Button = (props: ButtonProps) => { textStyles, isCopying, copiedText, + testId, ...rest } = props const {styles} = useStyles() return ( - + {isCopying && ( {copiedText} diff --git a/apps/wallet-mobile/src/features/SetupWallet/common/ButtonCard/ButtonCard.tsx b/apps/wallet-mobile/src/features/SetupWallet/common/ButtonCard/ButtonCard.tsx index 06d1598253..97aa10ce60 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/common/ButtonCard/ButtonCard.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/common/ButtonCard/ButtonCard.tsx @@ -10,9 +10,10 @@ type ButtonCardProps = { subTitle?: string icon?: React.ReactNode onPress: () => void + testId?: string } -export const ButtonCard = ({title, subTitle, icon = null, onPress}: ButtonCardProps) => { +export const ButtonCard = ({title, subTitle, icon = null, onPress, testId}: ButtonCardProps) => { const {styles, colors} = useStyles() return ( @@ -20,6 +21,7 @@ export const ButtonCard = ({title, subTitle, icon = null, onPress}: ButtonCardPr activeOpacity={0.5} style={[styles.container, icon !== null && styles.justifySpaceBetween]} onPress={onPress} + testID={testId} > { const {styles, colors} = useStyles(includeSpacing, showBackgroundColor) @@ -38,7 +40,9 @@ export const CardAboutPhrase = ({ {title !== undefined && ( <> - {title} + + {title} + diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseMnemonicType/ChooseMnemonicTypeScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseMnemonicType/ChooseMnemonicTypeScreen.tsx index 0d8ed7d1f9..32871d0de8 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseMnemonicType/ChooseMnemonicTypeScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseMnemonicType/ChooseMnemonicTypeScreen.tsx @@ -51,6 +51,7 @@ export const ChooseMnemonicTypeScreen = () => { title={strings.choose15WordsMnemonicTitle} icon={} onPress={handle15Words} + testId="mnemonic-15-word" /> @@ -59,6 +60,7 @@ export const ChooseMnemonicTypeScreen = () => { title={strings.choose24WordsMnemonicTitle} icon={} onPress={handle24Words} + testId="mnemonic-24-word" /> diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseNetwork/ChooseNetworkScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseNetwork/ChooseNetworkScreen.tsx index d31356fae9..515dbce653 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseNetwork/ChooseNetworkScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseNetwork/ChooseNetworkScreen.tsx @@ -49,6 +49,7 @@ export const ChooseNetworkScreen = () => { title={strings.cardanoMainnet} subTitle={strings.cardanoMainnetDescription} onPress={handleMainnet} + testId="setup-network-select-mainnet-button" /> @@ -57,6 +58,7 @@ export const ChooseNetworkScreen = () => { title={strings.cardanoTestnet} subTitle={strings.cardanoTestnetDescription} onPress={handleTestnet} + testId="setup-network-select-testnet-button" /> @@ -65,6 +67,7 @@ export const ChooseNetworkScreen = () => { title={strings.cardanoSanchonet} subTitle={strings.cardanoSanchonetDescription} onPress={handleSanchonet} + testId="setup-network-select-sanchonet-button" /> diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseSetupType/ChooseSetupTypeScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseSetupType/ChooseSetupTypeScreen.tsx index cdfd15b7f9..40c85ad2bb 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseSetupType/ChooseSetupTypeScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/ChooseSetupType/ChooseSetupTypeScreen.tsx @@ -99,6 +99,7 @@ export const ChooseSetupTypeScreen = () => { title={strings.createWalletButtonCard} icon={} onPress={handleCreate} + testId="setup-create-new-wallet-button" /> @@ -107,6 +108,7 @@ export const ChooseSetupTypeScreen = () => { title={strings.restoreWalletButtonCard} icon={} onPress={handleRestore} + testId="setup-restore-wallet-button" /> @@ -115,6 +117,7 @@ export const ChooseSetupTypeScreen = () => { title={strings.connectWalletButtonCard} icon={} onPress={handleHw} + testId="setup-connect-HW-wallet-button" /> diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/AboutRecoveryPhraseScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/AboutRecoveryPhraseScreen.tsx index 7ea2c70abb..3b7fc78643 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/AboutRecoveryPhraseScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/AboutRecoveryPhraseScreen.tsx @@ -68,6 +68,7 @@ export const AboutRecoveryPhraseScreen = () => { title={strings.next} style={styles.button} onPress={() => navigation.navigate('setup-wallet-recovery-phrase-mnemonic')} + testID="setup-step1-next-button" /> diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/RecoveryPhraseScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/RecoveryPhraseScreen.tsx index 5af1e8bb54..5d82fe49b3 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/RecoveryPhraseScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/RecoveryPhraseScreen.tsx @@ -71,6 +71,7 @@ export const RecoveryPhraseScreen = () => { closeModal() showCreateWalletInfoModalChanged(false) }} + testId="setup-step2-continue-button" /> @@ -106,7 +107,7 @@ export const RecoveryPhraseScreen = () => { {strings.recoveryPhraseTitle(bold)} - + @@ -134,7 +135,12 @@ export const RecoveryPhraseScreen = () => { ))} - setIsBlur(!isBlur)}> + setIsBlur(!isBlur)} + testID="step2-show_hide-recovery-phrase-button" + > {isBlur ? : } @@ -153,6 +159,7 @@ export const RecoveryPhraseScreen = () => { mnemonicChanged(mnemonic) navigation.navigate('setup-wallet-verify-recovery-phrase-mnemonic') }} + testId="setup-step2-next-button" /> @@ -160,11 +167,11 @@ export const RecoveryPhraseScreen = () => { ) } -const Info = ({onPress}: {onPress: () => void}) => { +const Info = ({onPress, testId}: {onPress: () => void; testId?: string}) => { const {styles} = useStyles() return ( - + diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/VerifyRecoveryPhraseScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/VerifyRecoveryPhraseScreen.tsx index 5c4cfadbc4..f80ef936c3 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/VerifyRecoveryPhraseScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/VerifyRecoveryPhraseScreen.tsx @@ -122,6 +122,7 @@ export const VerifyRecoveryPhraseScreen = () => { publicKeyHexChanged(accountPubKeyHex) navigation.navigate('setup-wallet-details-form') }} + testId="setup-next-button" /> diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx index ea614e00f6..0f23c232ea 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx @@ -191,6 +191,7 @@ export const WalletDetailsScreen = () => { closeModal() showRestoreWalletInfoModalChanged(false) }} + testId="setup-modal-continue-button" /> @@ -350,6 +351,7 @@ export const WalletDetailsScreen = () => { style={styles.button} onPress={() => handleCreateWallet()} disabled={isLoading || Object.keys(passwordErrors).length > 0 || Object.keys(nameErrors).length > 0} + testID="walletFormContinueButton" /> diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/MnemonicInput/MnemonicInput.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/MnemonicInput/MnemonicInput.tsx index 6504faaeff..df92eddaf3 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/MnemonicInput/MnemonicInput.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/MnemonicInput/MnemonicInput.tsx @@ -89,6 +89,7 @@ export const MnemonicInput = ({ mnenonicRefs.forEach((ref) => ref.current?.selectWord('')) mnenonicRefs[0].current?.focus() }} + testId="clearAll-button" /> )} @@ -97,11 +98,11 @@ export const MnemonicInput = ({ ) } -const ClearAllButton = ({onPress}: {onPress: () => void}) => { +const ClearAllButton = ({onPress, testId}: {onPress: () => void; testId?: string}) => { const {styles} = useStyles() const strings = useStrings() return ( - + {strings.clearAll} diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx index f6d0758ebb..9ea8ab3d9d 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx @@ -288,7 +288,9 @@ export const RestoreWalletDetailsScreen = () => { - {plate.accountPlate.TextPart} + + {plate.accountPlate.TextPart} + @@ -310,6 +312,7 @@ export const RestoreWalletDetailsScreen = () => { addressMode, }) } + testId="setup-restore-step2-next-button" disabled={isLoading || Object.keys(passwordErrors).length > 0 || Object.keys(nameErrors).length > 0} /> diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx index 74492f1b48..797d03dbf3 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletScreen.tsx @@ -212,7 +212,7 @@ const NextButton = ({onPress}: {onPress: () => void}) => { return ( -