Skip to content

Commit

Permalink
Merge pull request #1786 from Emurgo/fix-select-new-wallet
Browse files Browse the repository at this point in the history
Merge pull request #1781 from Emurgo/select-restored-wallet
  • Loading branch information
stackchain committed Nov 20, 2021
2 parents b44f4a1 + 17f242b commit 44524ff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
17 changes: 9 additions & 8 deletions legacy/components/WalletInit/ConnectNanoX/SaveNanoXScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import React from 'react'
import {useDispatch} from 'react-redux'

// $FlowExpectedError
import {useSetSelectedWallet, useSetSelectedWalletMeta} from '../../../../src/SelectedWallet/SelectedWalletContext'
import {useSetSelectedWalletMeta} from '../../../../src/SelectedWallet/SelectedWalletContext'
import {createWalletWithBip44Account} from '../../../actions'
import {saveHW} from '../../../actions/hwWallet'
import image from '../../../assets/img/ledger_2.png'
import {CONFIG} from '../../../config/config'
import type {NetworkId, WalletImplementationId} from '../../../config/types'
import type {HWDeviceInfo} from '../../../crypto/shelley/ledgerUtils'
import type {WalletInterface} from '../../../crypto/WalletInterface'
import {ROOT_ROUTES, WALLET_ROOT_ROUTES} from '../../../RoutesList'
import type {WalletMeta} from '../../../state'
import assert from '../../../utils/assert'
Expand All @@ -28,13 +29,12 @@ const SaveNanoXScreen = () => {
const route = useRoute()
const dispatch = useDispatch()
const setSelectedWalletMeta = useSetSelectedWalletMeta()
const setSelectedWallet = useSetSelectedWallet()

const onSubmit = async ({name}) => {
const {networkId, walletImplementationId, hwDeviceInfo}: Params = (route.params: any)
assert.assert(hwDeviceInfo != null, 'SaveNanoXScreen::onPress hwDeviceInfo')

const wallet = await dispatch(
const wallet: WalletInterface = await dispatch(
createWalletWithBip44Account(
name,
hwDeviceInfo.bip44AccountPublic,
Expand All @@ -45,16 +45,17 @@ const SaveNanoXScreen = () => {
),
)
const walletMeta: WalletMeta = {
id: wallet.id,
name,
networkId,
walletImplementationId,

id: wallet.id,
networkId: wallet.networkId,
walletImplementationId: wallet.walletImplementationId,
isHW: wallet.isHW,
checksum: wallet.checksum,
isEasyConfirmationEnabled: false,
isEasyConfirmationEnabled: wallet.isEasyConfirmationEnabled,
provider: wallet.provider,
}
setSelectedWalletMeta(walletMeta)
setSelectedWallet(wallet)
dispatch(saveHW(hwDeviceInfo))
navigation.navigate(ROOT_ROUTES.WALLET, {
screen: WALLET_ROOT_ROUTES.MAIN_WALLET_ROUTES,
Expand Down
23 changes: 21 additions & 2 deletions legacy/components/WalletInit/CreateWallet/MnemonicCheckScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import {ScrollView, TouchableOpacity, View} from 'react-native'
import {SafeAreaView} from 'react-native-safe-area-context'
import {useDispatch} from 'react-redux'

// $FlowExpectedError
import {useSetSelectedWalletMeta} from '../../../../src/SelectedWallet/SelectedWalletContext'
import {createWallet} from '../../../actions'
import type {NetworkId, WalletImplementationId, YoroiProvider} from '../../../config/types'
import type {WalletInterface} from '../../../crypto/WalletInterface'
import {useParams} from '../../../navigation'
import {ROOT_ROUTES, WALLET_ROOT_ROUTES} from '../../../RoutesList'
import type {WalletMeta} from '../../../state'
import assert from '../../../utils/assert'
import {ignoreConcurrentAsyncHandler} from '../../../utils/utils'
import {Button, Spacer, StatusBar, Text} from '../../UiKit'
import styles from './styles/MnemonicCheckScreen.style'

export type Params = {
mnemonic: string,
password: string,
Expand Down Expand Up @@ -44,11 +47,27 @@ const MnemonicCheckScreen = () => {
const isPhraseComplete = userEntries.length === mnemonicEntries.length
const isPhraseValid = userEntries.map((entry) => entry.word).join(' ') === mnemonic

const setSelectedWalletMeta = useSetSelectedWalletMeta()
const dispatch = useDispatch()
const handleWalletConfirmation = async () => {
assertions({mnemonic, password, name, networkId, walletImplementationId})

await dispatch(createWallet(name, mnemonic, password, networkId, walletImplementationId, provider))
const wallet: WalletInterface = await dispatch(
createWallet(name, mnemonic, password, networkId, walletImplementationId, provider),
)

const walletMeta: WalletMeta = {
name,

id: wallet.id,
networkId: wallet.networkId,
walletImplementationId: wallet.walletImplementationId,
isHW: wallet.isHW,
checksum: wallet.checksum,
isEasyConfirmationEnabled: wallet.isEasyConfirmationEnabled,
provider: wallet.provider,
}
setSelectedWalletMeta(walletMeta)

navigation.navigate(ROOT_ROUTES.WALLET, {
screen: WALLET_ROOT_ROUTES.MAIN_WALLET_ROUTES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {ActivityIndicator} from 'react-native'
import {useDispatch} from 'react-redux'

// $FlowExpectedError
import {useSetSelectedWallet, useSetSelectedWalletMeta} from '../../../../src/SelectedWallet/SelectedWalletContext'
import {useSetSelectedWalletMeta} from '../../../../src/SelectedWallet/SelectedWalletContext'
import {createWallet, updateVersion} from '../../../actions'
import type {WalletInterface} from '../../../crypto/WalletInterface'
import {ROOT_ROUTES, WALLET_ROOT_ROUTES} from '../../../RoutesList'
import type {WalletMeta} from '../../../state'
import assert from '../../../utils/assert'
Expand All @@ -20,7 +21,6 @@ const WalletCredentialsScreen = () => {
const [waiting, setWaiting] = React.useState(false)
const dispatch = useDispatch()
const setSelectedWalletMeta = useSetSelectedWalletMeta()
const setSelectedWallet = useSetSelectedWallet()

// eslint-disable-next-line react-hooks/exhaustive-deps
const navigateToWallet = React.useCallback(
Expand All @@ -33,21 +33,21 @@ const WalletCredentialsScreen = () => {
assert.assert(networkId != null, 'networkId')
assert.assert(!!walletImplementationId, 'walletImplementationId')
try {
const wallet = await dispatch(
const wallet: WalletInterface = await dispatch(
createWallet(name, phrase, password, networkId, walletImplementationId, provider),
)
const walletMeta: WalletMeta = {
id: wallet.id,
name,
networkId,
walletImplementationId,

id: wallet.id,
networkId: wallet.networkId,
walletImplementationId: wallet.walletImplementationId,
isHW: wallet.isHW,
checksum: wallet.checksum,
isEasyConfirmationEnabled: false,
provider,
isEasyConfirmationEnabled: wallet.isEasyConfirmationEnabled,
provider: wallet.provider,
}
setSelectedWalletMeta(walletMeta)
setSelectedWallet(wallet)
await dispatch(updateVersion())
} finally {
setWaiting(false)
Expand Down

0 comments on commit 44524ff

Please sign in to comment.