diff --git a/.tool-versions b/.tool-versions index d698c578f7..0f29bd47c8 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,5 +1,5 @@ -nodejs 16.19.0 +nodejs 18.0.0 rust 1.69.0 -java adoptopenjdk-11.0.18+10 +java adoptopenjdk-17.0.10+7 ruby 3.2.2 -python 3.11.3 \ No newline at end of file +python 3.11.3 diff --git a/apps/wallet-mobile/.tool-versions b/apps/wallet-mobile/.tool-versions index d698c578f7..0f29bd47c8 100644 --- a/apps/wallet-mobile/.tool-versions +++ b/apps/wallet-mobile/.tool-versions @@ -1,5 +1,5 @@ -nodejs 16.19.0 +nodejs 18.0.0 rust 1.69.0 -java adoptopenjdk-11.0.18+10 +java adoptopenjdk-17.0.10+7 ruby 3.2.2 -python 3.11.3 \ No newline at end of file +python 3.11.3 diff --git a/apps/wallet-mobile/package.json b/apps/wallet-mobile/package.json index c90a3f21cd..30c03cd976 100644 --- a/apps/wallet-mobile/package.json +++ b/apps/wallet-mobile/package.json @@ -148,6 +148,7 @@ "expo-camera": "^13.2.1", "expo-device": "^5.4.0", "expo-status-bar": "~1.4.4", + "immer": "^10.0.2", "jsc-android": "241213.1.0", "lodash": "^4.17.21", "react": "18.2.0", @@ -262,6 +263,7 @@ "eslint-plugin-simple-import-sort": "^7.0.0", "extract-react-intl-messages": "^0.14.0", "i18n-unused": "^0.8.0", + "jest": "^29.7.0", "lint-staged": "^13.2.2", "metro-react-native-babel-preset": "0.73.9", "mockdate": "^3.0.5", diff --git a/apps/wallet-mobile/src/Dashboard/WithdrawStakingRewards/ConfirmTx/ConfirmTxWithHW.tsx b/apps/wallet-mobile/src/Dashboard/WithdrawStakingRewards/ConfirmTx/ConfirmTxWithHW.tsx index e3d0380005..5e765035db 100644 --- a/apps/wallet-mobile/src/Dashboard/WithdrawStakingRewards/ConfirmTx/ConfirmTxWithHW.tsx +++ b/apps/wallet-mobile/src/Dashboard/WithdrawStakingRewards/ConfirmTx/ConfirmTxWithHW.tsx @@ -4,11 +4,11 @@ import {useIntl} from 'react-intl' import {Boundary, TwoActionView} from '../../../components' import {LedgerConnect, LedgerTransportSwitch} from '../../../HW' import {confirmationMessages, txLabels} from '../../../i18n/global-messages' +import {walletManager} from '../../../wallet-manager/walletManager' import {YoroiWallet} from '../../../yoroi-wallets/cardano/types' import {useSignWithHwAndSubmitTx} from '../../../yoroi-wallets/hooks' import {DeviceId, DeviceObj, withBLE, withUSB} from '../../../yoroi-wallets/hw' import {YoroiUnsignedTx} from '../../../yoroi-wallets/types' -import {walletManager} from '../../../yoroi-wallets/walletManager' import {TransferSummary} from '../TransferSummary' type Props = { diff --git a/apps/wallet-mobile/src/InitApp.tsx b/apps/wallet-mobile/src/InitApp.tsx index c1e9c85a46..ec96ac11a0 100644 --- a/apps/wallet-mobile/src/InitApp.tsx +++ b/apps/wallet-mobile/src/InitApp.tsx @@ -8,8 +8,9 @@ import uuid from 'uuid' import {AppNavigator} from './AppNavigator' import {useInitScreenShare} from './features/Settings/ScreenShare' import {CONFIG, isProduction} from './legacy/config' +import {storageVersionMaker} from './migrations/storageVersion' +import {walletManager} from './wallet-manager/walletManager' import {useCrashReportsEnabled} from './yoroi-wallets/hooks' -import {walletManager} from './yoroi-wallets/walletManager' if (Platform.OS === 'android') { if (UIManager.setLayoutAnimationEnabledExperimental != null) { @@ -51,11 +52,14 @@ const initInstallationId = async (storage: App.Storage) => { const newInstallationId = uuid.v4() await storage.setItem('appSettings/installationId', newInstallationId, () => newInstallationId) // LEGACY: installationId is not serialized + + // new installation set the storage version to the current version + await storageVersionMaker(storage).newInstallation() } export const initApp = async (storage: App.Storage) => { await initInstallationId(storage) - await walletManager.initialize() + await walletManager.removeDeletedWallets() } const useInitSentry = (options: {enabled: boolean}) => { diff --git a/apps/wallet-mobile/src/SelectedWallet/Context/SelectedWalletMetaContext.tsx b/apps/wallet-mobile/src/SelectedWallet/Context/SelectedWalletMetaContext.tsx index 7b46253da7..a669a5030c 100644 --- a/apps/wallet-mobile/src/SelectedWallet/Context/SelectedWalletMetaContext.tsx +++ b/apps/wallet-mobile/src/SelectedWallet/Context/SelectedWalletMetaContext.tsx @@ -1,6 +1,6 @@ import * as React from 'react' -import {WalletMeta} from '../../yoroi-wallets/walletManager' +import {WalletMeta} from '../../wallet-manager/types' type SelectedWalletMeta = WalletMeta type SetSelectedWalletMeta = (selectedWalletMeta?: SelectedWalletMeta) => void diff --git a/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletListItem.tsx b/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletListItem.tsx index 3a1edc50d6..f0a40d85a1 100644 --- a/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletListItem.tsx +++ b/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletListItem.tsx @@ -3,8 +3,8 @@ import {StyleSheet, Text, TouchableOpacity, View} from 'react-native' import {Icon} from '../../components' import {brand, COLORS} from '../../theme' +import {WalletMeta} from '../../wallet-manager/types' import {isByron, isHaskellShelley, isJormun} from '../../yoroi-wallets/cardano/utils' -import {WalletMeta} from '../../yoroi-wallets/walletManager' type Props = { wallet: WalletMeta diff --git a/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletSelectionScreen.stories.tsx b/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletSelectionScreen.stories.tsx index 7c528730e9..71a7e43361 100644 --- a/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletSelectionScreen.stories.tsx +++ b/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletSelectionScreen.stories.tsx @@ -2,10 +2,11 @@ import {action} from '@storybook/addon-actions' import {storiesOf} from '@storybook/react-native' import React from 'react' -import {WalletManagerProvider} from '../../WalletManager' +import {WalletMeta} from '../../wallet-manager/types' +import {mockWalletManager, WalletManager} from '../../wallet-manager/walletManager' +import {WalletManagerProvider} from '../../wallet-manager/WalletManagerContext' import {InvalidState, NetworkError} from '../../yoroi-wallets/cardano/errors' import {mocks} from '../../yoroi-wallets/mocks' -import {mockWalletManager, WalletManager, WalletMeta} from '../../yoroi-wallets/walletManager' import {WalletSelectionScreen} from './WalletSelectionScreen' storiesOf('WalletSelectionScreen', module) diff --git a/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletSelectionScreen.tsx b/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletSelectionScreen.tsx index 04aef826e0..aaee42f48b 100644 --- a/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletSelectionScreen.tsx +++ b/apps/wallet-mobile/src/SelectedWallet/WalletSelection/WalletSelectionScreen.tsx @@ -14,14 +14,14 @@ import {isNightly} from '../../legacy/config' import {useMetrics} from '../../metrics/metricsManager' import {useWalletNavigation} from '../../navigation' import {COLORS} from '../../theme' -import {useWalletManager} from '../../WalletManager' +import {WalletMeta} from '../../wallet-manager/types' +import {useWalletManager} from '../../wallet-manager/WalletManagerContext' 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' import {InvalidState, NetworkError} from '../../yoroi-wallets/cardano/errors' import {isJormungandr} from '../../yoroi-wallets/cardano/networks' import {useOpenWallet, useWalletMetas} from '../../yoroi-wallets/hooks' -import {WalletMeta} from '../../yoroi-wallets/walletManager' import {useSetSelectedWallet, useSetSelectedWalletMeta} from '../Context' import {WalletListItem} from './WalletListItem' diff --git a/apps/wallet-mobile/src/TxHistory/ActionsBanner.tsx b/apps/wallet-mobile/src/TxHistory/ActionsBanner.tsx index 0e82102e6c..1ef7247fbc 100644 --- a/apps/wallet-mobile/src/TxHistory/ActionsBanner.tsx +++ b/apps/wallet-mobile/src/TxHistory/ActionsBanner.tsx @@ -9,7 +9,7 @@ import Animated, {FadeInDown, FadeOutDown, Layout} from 'react-native-reanimated import {useCopy} from '../../src/legacy/useCopy' import {Icon, Spacer, Text} from '../components' -import {useAddressDerivationManager} from '../features/Receive/common/useAddressDerivationManager' +import {useReceive} from '../features/Receive/common/ReceiveProvider' import {useReceiveAddressesStatus} from '../features/Receive/common/useReceiveAddressesStatus' import {messages as receiveMessages} from '../features/Receive/common/useStrings' import {useSwapForm} from '../features/Swap/common/SwapFormProvider' @@ -17,6 +17,7 @@ import {actionMessages} from '../i18n/global-messages' import {useMetrics} from '../metrics/metricsManager' import {TxHistoryRouteNavigation} from '../navigation' import {useSelectedWallet} from '../SelectedWallet' +import {useAddressModeManager} from '../wallet-manager/useAddressModeManager' import {useTokenInfo} from '../yoroi-wallets/hooks' export const ActionsBanner = ({disabled = false}: {disabled: boolean}) => { @@ -24,8 +25,9 @@ export const ActionsBanner = ({disabled = false}: {disabled: boolean}) => { const strings = useStrings() const navigateTo = useNavigateTo() - const {isSingle, addressDerivation} = useAddressDerivationManager() - const {next: nextReceiveAddress} = useReceiveAddressesStatus(addressDerivation) + const {isSingle, addressMode} = useAddressModeManager() + const {next: nextReceiveAddress} = useReceiveAddressesStatus(addressMode) + const {selectedAddressChanged} = useReceive() const [isCopying, copy] = useCopy() const {reset: resetSendState} = useTransfer() @@ -71,6 +73,7 @@ export const ActionsBanner = ({disabled = false}: {disabled: boolean}) => { const handleOnPressReceive = () => { if (isSingle) { + selectedAddressChanged(nextReceiveAddress) navigateTo.receiveSingleAddress() } else { navigateTo.receiveMultipleAddresses() diff --git a/apps/wallet-mobile/src/WalletInit/MnemonicCheck/MnemonicCheckScreen.stories.tsx b/apps/wallet-mobile/src/WalletInit/MnemonicCheck/MnemonicCheckScreen.stories.tsx index 579ed03e0e..a0a6c33130 100644 --- a/apps/wallet-mobile/src/WalletInit/MnemonicCheck/MnemonicCheckScreen.stories.tsx +++ b/apps/wallet-mobile/src/WalletInit/MnemonicCheck/MnemonicCheckScreen.stories.tsx @@ -4,10 +4,10 @@ import {storiesOf} from '@storybook/react-native' import React from 'react' import {debugWalletInfo} from '../../features' -import {WalletManagerProvider} from '../../WalletManager' +import {WalletManager, walletManager} from '../../wallet-manager/walletManager' +import {WalletManagerProvider} from '../../wallet-manager/WalletManagerContext' import {NETWORK_ID} from '../../yoroi-wallets/cardano/constants/testnet/constants' import {NetworkError} from '../../yoroi-wallets/cardano/errors' -import {WalletManager, walletManager} from '../../yoroi-wallets/walletManager' import {MnemonicCheckScreen} from './MnemonicCheckScreen' storiesOf('MnemonicCheckScreen', module) diff --git a/apps/wallet-mobile/src/WalletInit/MnemonicCheck/MnemonicCheckScreen.tsx b/apps/wallet-mobile/src/WalletInit/MnemonicCheck/MnemonicCheckScreen.tsx index 565f75dca7..7b3e9a52af 100644 --- a/apps/wallet-mobile/src/WalletInit/MnemonicCheck/MnemonicCheckScreen.tsx +++ b/apps/wallet-mobile/src/WalletInit/MnemonicCheck/MnemonicCheckScreen.tsx @@ -10,9 +10,12 @@ import {errorMessages} from '../../i18n/global-messages' import {useMetrics} from '../../metrics/metricsManager' import {useWalletNavigation, WalletInitRoutes} from '../../navigation' import {COLORS} from '../../theme' +import {AddressMode} from '../../wallet-manager/types' import {NetworkError} from '../../yoroi-wallets/cardano/errors' import {useCreateWallet} from '../../yoroi-wallets/hooks' +// when creating, later will be part of the onboarding +const addressMode: AddressMode = 'single' export const MnemonicCheckScreen = () => { const strings = useStrings() const {resetToWalletSelection} = useWalletNavigation() @@ -33,6 +36,9 @@ export const MnemonicCheckScreen = () => { const isPhraseValid = userEntries.map((entry) => entry.word).join(' ') === mnemonic const intl = useIntl() + const handleOnCreateWallet = () => { + createWallet({name, mnemonicPhrase: mnemonic, password, networkId, walletImplementationId, addressMode}) + } const {createWallet, isLoading, isSuccess} = useCreateWallet({ onSuccess: () => { track.createWalletDetailsSettled() @@ -46,6 +52,7 @@ export const MnemonicCheckScreen = () => { }) }, }) + const disabled = !isPhraseComplete || !isPhraseValid || isLoading || isSuccess return ( @@ -70,8 +77,8 @@ export const MnemonicCheckScreen = () => {