Skip to content

Commit

Permalink
refactor(wallet-mobile): Moved address mode to meta (#3096)
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain authored Feb 28, 2024
1 parent 42da67c commit 2d4b11a
Show file tree
Hide file tree
Showing 70 changed files with 800 additions and 904 deletions.
6 changes: 3 additions & 3 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -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
python 3.11.3
6 changes: 3 additions & 3 deletions apps/wallet-mobile/.tool-versions
Original file line number Diff line number Diff line change
@@ -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
python 3.11.3
2 changes: 2 additions & 0 deletions apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 6 additions & 2 deletions apps/wallet-mobile/src/InitApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
9 changes: 6 additions & 3 deletions apps/wallet-mobile/src/TxHistory/ActionsBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ 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'
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}) => {
const {styles, colors} = useStyles()
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()
Expand Down Expand Up @@ -71,6 +73,7 @@ export const ActionsBanner = ({disabled = false}: {disabled: boolean}) => {

const handleOnPressReceive = () => {
if (isSingle) {
selectedAddressChanged(nextReceiveAddress)
navigateTo.receiveSingleAddress()
} else {
navigateTo.receiveMultipleAddresses()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -46,6 +52,7 @@ export const MnemonicCheckScreen = () => {
})
},
})
const disabled = !isPhraseComplete || !isPhraseValid || isLoading || isSuccess

return (
<SafeAreaView edges={['left', 'right', 'bottom']} style={styles.safeAreaView}>
Expand All @@ -70,8 +77,8 @@ export const MnemonicCheckScreen = () => {
<View style={styles.buttons}>
<Button
block
onPress={() => createWallet({name, mnemonicPhrase: mnemonic, password, networkId, walletImplementationId})}
disabled={!isPhraseComplete || !isPhraseValid || isLoading || isSuccess}
onPress={handleOnCreateWallet}
disabled={disabled}
title={strings.confirmButton}
style={styles.confirmButton}
testID="mnemonicCheckScreen::confirm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {storiesOf} from '@storybook/react-native'
import React from 'react'

import {WalletInitRoutes} from '../../navigation'
import {WalletManagerProvider} from '../../WalletManager'
import {WalletManager, walletManager} from '../../wallet-manager/walletManager'
import {WalletManagerProvider} from '../../wallet-manager/WalletManagerContext'
import {NETWORK_ID, WALLET_IMPLEMENTATION_ID} from '../../yoroi-wallets/cardano/constants/testnet/constants'
import {NetworkError} from '../../yoroi-wallets/cardano/errors'
import {WalletManager, walletManager} from '../../yoroi-wallets/walletManager'
import {SaveNanoXScreen} from './SaveNanoXScreen'

const params: RouteProp<WalletInitRoutes, 'save-nano-x'>['params'] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import {showErrorDialog} from '../../dialogs'
import {errorMessages} from '../../i18n/global-messages'
import {useMetrics} from '../../metrics/metricsManager'
import {useWalletNavigation, WalletInitRoutes} from '../../navigation'
import {AddressMode} from '../../wallet-manager/types'
import {NetworkError} from '../../yoroi-wallets/cardano/errors'
import {useCreateBip44Wallet} from '../../yoroi-wallets/hooks'
import {WalletNameForm} from '../WalletNameForm'

// when hw, later will be part of the onboarding
const addressMode: AddressMode = 'multiple'
export const SaveNanoXScreen = () => {
const strings = useStrings()
const {resetToWalletSelection} = useWalletNavigation()
Expand Down Expand Up @@ -44,6 +47,7 @@ export const SaveNanoXScreen = () => {
implementationId: walletImplementationId,
hwDeviceInfo,
readOnly: false,
addressMode,
})
}
defaultWalletName={strings.ledgerWalletNameSuggestion}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {action} from '@storybook/addon-actions'
import {storiesOf} from '@storybook/react-native'
import React from 'react'

import {WalletManagerProvider} from '../../WalletManager'
import {WalletManager, walletManager} from '../../wallet-manager/walletManager'
import {WalletManagerProvider} from '../../wallet-manager/WalletManagerContext'
import {NetworkError} from '../../yoroi-wallets/cardano/errors'
import {WalletManager, walletManager} from '../../yoroi-wallets/walletManager'
import {SaveReadOnlyWalletScreen} from './SaveReadOnlyWalletScreen'

storiesOf('SaveReadOnlyWalletScreen', module)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import {useMetrics} from '../../metrics/metricsManager'
import {useWalletNavigation, WalletInitRoutes} from '../../navigation'
import {theme} from '../../theme'
import {isEmptyString} from '../../utils/utils'
import {AddressMode} from '../../wallet-manager/types'
import {NetworkError} from '../../yoroi-wallets/cardano/errors'
import {NUMBERS} from '../../yoroi-wallets/cardano/numbers'
import {useCreateBip44Wallet, usePlate} from '../../yoroi-wallets/hooks'
import {NetworkId} from '../../yoroi-wallets/types'
import {WalletAddress} from '../WalletAddress'
import {WalletNameForm} from '../WalletNameForm'

// when ro, later will be part of the onboarding
const addressMode: AddressMode = 'multiple'
export const SaveReadOnlyWalletScreen = () => {
const intl = useIntl()
const strings = useStrings()
Expand Down Expand Up @@ -55,6 +58,7 @@ export const SaveReadOnlyWalletScreen = () => {
implementationId: walletImplementationId,
bip44AccountPublic: publicKeyHex,
readOnly: true,
addressMode,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {action} from '@storybook/addon-actions'
import {storiesOf} from '@storybook/react-native'
import React from 'react'

import {WalletManagerProvider} from '../../WalletManager'
import {WalletManager, walletManager} from '../../wallet-manager/walletManager'
import {WalletManagerProvider} from '../../wallet-manager/WalletManagerContext'
import {NetworkError} from '../../yoroi-wallets/cardano/errors'
import {WalletManager, walletManager} from '../../yoroi-wallets/walletManager'
import {WalletCredentialsScreen} from './WalletCredentialsScreen'

storiesOf('WalletCredentialsScreen', module)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ 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'
import {WalletForm} from '../WalletForm'

// when restoring, later will be part of the onboarding
const addressMode: AddressMode = 'multiple'
export const WalletCredentialsScreen = () => {
const {resetToWalletSelection} = useWalletNavigation()
const {track} = useMetrics()
Expand Down Expand Up @@ -41,7 +44,7 @@ export const WalletCredentialsScreen = () => {
isLoading || isSuccess
? NOOP
: ({name, password}) =>
createWallet({name, password, mnemonicPhrase: phrase, networkId, walletImplementationId})
createWallet({name, password, mnemonicPhrase: phrase, networkId, walletImplementationId, addressMode})
}
/>

Expand Down
2 changes: 1 addition & 1 deletion apps/wallet-mobile/src/WalletInit/WalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {debugWalletInfo, features} from '../features'
import globalMessages from '../i18n/global-messages'
import {COLORS} from '../theme'
import {isEmptyString} from '../utils/utils'
import {useWalletManager} from '../WalletManager'
import {useWalletManager} from '../wallet-manager/WalletManagerContext'
import {useWalletNames} from '../yoroi-wallets/hooks'
import {
getWalletNameError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ActivityIndicator, Image, ImageSourcePropType, ScrollView, StyleSheet, V
import {Button, KeyboardAvoidingView, ProgressStep, TextInput} from '../../components'
import globalMessages from '../../i18n/global-messages'
import {spacing} from '../../theme'
import {useWalletManager} from '../../WalletManager'
import {useWalletManager} from '../../wallet-manager/WalletManagerContext'
import {useWalletNames} from '../../yoroi-wallets/hooks'
import {getWalletNameError, validateWalletName} from '../../yoroi-wallets/utils/validators'

Expand Down
1 change: 0 additions & 1 deletion apps/wallet-mobile/src/WalletManager/index.ts

This file was deleted.

14 changes: 8 additions & 6 deletions apps/wallet-mobile/src/YoroiApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {InitApp} from './InitApp'
import {CONFIG} from './legacy/config'
import {setLogLevel} from './legacy/logging'
import {makeMetricsManager, MetricsProvider} from './metrics/metricsManager'
import {useMigrations} from './migrations/useMigrations'
import {SelectedWalletMetaProvider, SelectedWalletProvider} from './SelectedWallet/Context'
import {WalletManagerProvider} from './WalletManager'
import {useMigrations} from './yoroi-wallets/migrations'
import {walletManager} from './wallet-manager/walletManager'
import {WalletManagerProvider} from './wallet-manager/WalletManagerContext'
import {rootStorage} from './yoroi-wallets/storage/rootStorage'
import {walletManager} from './yoroi-wallets/walletManager'

enableScreens(true)
enableFreeze(true)
Expand All @@ -43,8 +43,10 @@ const metricsManager = makeMetricsManager()

export const YoroiApp = () => {
const migrated = useMigrations(rootStorage)
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
return migrated ? (

if (!migrated) return null

return (
<AsyncStorageProvider storage={rootStorage}>
<MetricsProvider metricsManager={metricsManager}>
<WalletManagerProvider walletManager={walletManager}>
Expand Down Expand Up @@ -74,5 +76,5 @@ export const YoroiApp = () => {
</WalletManagerProvider>
</MetricsProvider>
</AsyncStorageProvider>
) : null
)
}
Loading

0 comments on commit 2d4b11a

Please sign in to comment.