Unverified Commit 7f4703f0 authored by Hanwen Cheng's avatar Hanwen Cheng Committed by GitHub
Browse files

fix: add whitespace after tapping the suggestion text (#531)



* add whitespace after tapping the suggestion text

* fix mistake in split function

* Update src/components/AccountSeed.js
Co-Authored-By: default avatarJoseph Mark <sjeohp@gmail.com>

* fix lint error
Co-authored-by: default avatarJoseph Mark <sjeohp@gmail.com>
parent 0fa52782
Pipeline #75224 passed with stages
in 15 minutes and 19 seconds
......@@ -112,8 +112,12 @@ export default class AccountSeed extends Component {
<TouchableItem
key={i}
onPress={e => {
const phrase = left.concat(suggestion, right).join(' ');
let phrase = left
.concat(suggestion, right)
.join(' ')
.trimEnd();
const is24words = phrase.split(' ').length === 24;
if (!is24words) phrase += ' ';
this.props.onChangeText(phrase);
}}
>
......
......@@ -62,7 +62,7 @@ function IdentityNew({ accounts, navigation }) {
const onSeedTextInput = inputSeedPhrase => {
setSeedPhrase(inputSeedPhrase);
const addressGeneration = () =>
brainWalletAddress(inputSeedPhrase)
brainWalletAddress(inputSeedPhrase.trimEnd())
.then(({ bip39 }) => {
setIsSeedValid(validateSeed(inputSeedPhrase, bip39));
})
......@@ -74,7 +74,11 @@ function IdentityNew({ accounts, navigation }) {
const onRecoverIdentity = async () => {
const pin = await setPin(navigation);
try {
await accounts.saveNewIdentity(seedPhrase, pin);
if (isSeedValid.bip39) {
await accounts.saveNewIdentity(seedPhrase.trimEnd(), pin);
} else {
await accounts.saveNewIdentity(seedPhrase, pin);
}
setSeedPhrase('');
navigateToNewIdentityNetwork(navigation);
} catch (e) {
......
......@@ -72,17 +72,19 @@ export function validateSeed(seed, validBip39Seed) {
if (!seed || seed.length === 0) {
return {
accountRecoveryAllowed: false,
bip39: false,
reason: 'A seed phrase is required.',
valid: false
};
}
const words = seed.split(' ');
const words = validBip39Seed ? seed.trimEnd().split(' ') : seed.split(' ');
for (let word of words) {
if (word === '') {
return {
accountRecoveryAllowed: true,
bip39: false,
reason: 'Extra whitespace found.',
valid: false
};
......@@ -92,6 +94,7 @@ export function validateSeed(seed, validBip39Seed) {
if (!validBip39Seed) {
return {
accountRecoveryAllowed: true,
bip39: false,
reason:
'This recovery phrase is not a valid BIP39 seed, will be treated as a legacy Parity brain wallet.',
valid: false
......@@ -99,6 +102,7 @@ export function validateSeed(seed, validBip39Seed) {
}
return {
bip39: true,
reason: null,
valid: true
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment