From e6893913f3607339a00d42e05fd90f1dcb866db8 Mon Sep 17 00:00:00 2001 From: Hanwen Cheng Date: Fri, 22 Nov 2019 17:34:17 +0100 Subject: [PATCH 1/5] enable valid indication for bip39 account --- src/screens/AccountRecover.js | 11 +++++----- src/screens/IdentityNew.js | 38 +++++++++++++++++++++++++++++++---- src/util/account.js | 4 ++-- src/util/alertUtils.js | 9 +-------- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/screens/AccountRecover.js b/src/screens/AccountRecover.js index c945a3a30f..01264d2fb8 100644 --- a/src/screens/AccountRecover.js +++ b/src/screens/AccountRecover.js @@ -38,10 +38,7 @@ import { emptyAccount, validateSeed } from '../util/account'; import { debounce } from '../util/debounce'; import { brainWalletAddress, substrateAddress } from '../util/native'; import { constructSURI } from '../util/suri'; -import { - alertErrorWithMessage, - alertInvalidSeedRecovery -} from '../util/alertUtils'; +import { alertErrorWithMessage, alertRisks } from '../util/alertUtils'; export default class AccountRecover extends React.PureComponent { render() { @@ -173,7 +170,11 @@ class AccountRecoverView extends React.PureComponent { if (!validation.valid) { if (validation.accountRecoveryAllowed) { - return alertInvalidSeedRecovery(`${validation.reason}`, navigation); + return alertRisks(`${validation.reason}`, () => + navigation.navigate('AccountPin', { + isNew: true + }) + ); } else { return alertErrorWithMessage(`${validation.reason}`, 'Back'); } diff --git a/src/screens/IdentityNew.js b/src/screens/IdentityNew.js index 079ccd5347..9a55802879 100644 --- a/src/screens/IdentityNew.js +++ b/src/screens/IdentityNew.js @@ -32,14 +32,21 @@ import { navigateToNewIdentityNetwork, setPin } from '../util/navigationHelpers'; -import { alertIdentityCreationError } from '../util/alertUtils'; +import { + alertErrorWithMessage, + alertIdentityCreationError, + alertRisks +} from '../util/alertUtils'; import testIDs from '../../e2e/testIDs'; import ScreenHeading from '../components/ScreenHeading'; import KeyboardScrollView from '../components/KeyboardScrollView'; +import { brainWalletAddress } from '../util/native'; +import { debounce } from '../util/debounce'; function IdentityNew({ accounts, navigation }) { const isRecoverDefaultValue = navigation.getParam('isRecover', false); const [isRecover, setIsRecover] = useState(isRecoverDefaultValue); + const [isSeedValid, setIsSeedValid] = useState(false); const [seedPhrase, setSeedPhrase] = useState(''); useEffect(() => { @@ -52,6 +59,18 @@ function IdentityNew({ accounts, navigation }) { accounts.updateNewIdentity({ name }); }; + const onSeedTextInput = inputSeedPhrase => { + setSeedPhrase(inputSeedPhrase); + const addressGeneration = () => + brainWalletAddress(inputSeedPhrase) + .then(({ bip39 }) => { + setIsSeedValid(validateSeed(inputSeedPhrase, bip39)); + }) + .catch(() => setIsSeedValid(inputSeedPhrase, false)); + const debouncedAddressGeneration = debounce(addressGeneration, 200); + debouncedAddressGeneration(); + }; + const onRecoverIdentity = async () => { const pin = await setPin(navigation); try { @@ -63,6 +82,17 @@ function IdentityNew({ accounts, navigation }) { } }; + const onRecoverConfirm = () => { + if (!isSeedValid.valid) { + if (isSeedValid.accountRecoveryAllowed) { + return alertRisks(`${isSeedValid.reason}`, onRecoverIdentity); + } else { + return alertErrorWithMessage(`${isSeedValid.reason}`, 'Back'); + } + } + return onRecoverIdentity(); + }; + const onCreateNewIdentity = () => { setSeedPhrase(''); navigation.navigate('IdentityBackup', { @@ -74,8 +104,8 @@ function IdentityNew({ accounts, navigation }) { <> @@ -90,7 +120,7 @@ function IdentityNew({ accounts, navigation }) {