Skip to content

Commit

Permalink
Handle importing more invalid seed phrases
Browse files Browse the repository at this point in the history
  • Loading branch information
whymarrh committed Jun 26, 2019
1 parent 017a7e1 commit b5763fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ export default class ImportWithSeedPhrase extends PureComponent {
}

parseSeedPhrase = (seedPhrase) => {
if (!seedPhrase) {
return ''
}

const trimmed = seedPhrase.trim()
if (!trimmed) {
return ''
}

return trimmed.match(/\w+/g).join(' ')
const words = trimmed.match(/\w+/g)
if (!words) {
return ''
}

return words.join(' ')
}

componentWillMount () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,26 @@ describe('ImportWithSeedPhrase Component', () => {

assert.deepEqual(parseSeedPhrase(' '), '')
})

it('should return an empty string when given a string with only symbols', () => {
const root = shallowRender({
onSubmit: sinon.spy(),
})

const {parseSeedPhrase} = root.instance()

assert.deepEqual(parseSeedPhrase('$'), '')
})

it('should return an empty string for both null and undefined', () => {
const root = shallowRender({
onSubmit: sinon.spy(),
})

const {parseSeedPhrase} = root.instance()

assert.deepEqual(parseSeedPhrase(undefined), '')
assert.deepEqual(parseSeedPhrase(null), '')
})
})
})

0 comments on commit b5763fa

Please sign in to comment.