File tree 3 files changed +30
-5
lines changed
components/Views/ImportFromSeed
3 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import TermsAndConditions from '../TermsAndConditions';
30
30
import zxcvbn from 'zxcvbn' ;
31
31
import Icon from 'react-native-vector-icons/FontAwesome' ;
32
32
import Device from '../../../util/Device' ;
33
+ import { failedSeedPhraseRequirements } from '../../../util/validators' ;
33
34
import { OutlinedTextField } from 'react-native-material-textfield' ;
34
35
import {
35
36
BIOMETRY_CHOICE ,
@@ -168,11 +169,6 @@ const styles = StyleSheet.create({
168
169
169
170
const PASSCODE_NOT_SET_ERROR = 'Error: Passcode not set.' ;
170
171
171
- const failedSeedPhraseRequirements = seed => {
172
- const wordCount = seed . split ( / \s / u) . length ;
173
- return wordCount % 3 !== 0 || wordCount > 24 || wordCount < 12 ;
174
- } ;
175
-
176
172
/**
177
173
* View where users can set restore their account
178
174
* using a seed phrase
Original file line number Diff line number Diff line change
1
+ // eslint-disable-next-line import/prefer-default-export
2
+ export const failedSeedPhraseRequirements = seed => {
3
+ const wordCount = seed . split ( / \s / u) . length ;
4
+ return wordCount % 3 !== 0 || wordCount > 24 || wordCount < 12 ;
5
+ } ;
Original file line number Diff line number Diff line change
1
+ import { failedSeedPhraseRequirements } from './validators' ;
2
+
3
+ const VALID_24 =
4
+ 'verb middle giant soon wage common wide tool gentle garlic issue nut retreat until album recall expire bronze bundle live accident expect dry cook' ;
5
+ const VALID_12 = VALID_24 . split ( ' ' )
6
+ . splice ( 0 , 12 )
7
+ . join ( ' ' ) ;
8
+
9
+ describe ( 'failedSeedPhraseRequirements' , ( ) => {
10
+ it ( 'Should pass for 12 word mnemonic' , ( ) => {
11
+ expect ( failedSeedPhraseRequirements ( VALID_12 ) ) . toEqual ( false ) ;
12
+ } ) ;
13
+ it ( 'Should pass for 24 word mnemonic' , ( ) => {
14
+ expect ( failedSeedPhraseRequirements ( VALID_24 ) ) . toEqual ( false ) ;
15
+ } ) ;
16
+ it ( 'Should fail for 12 + 1 word mnemonic' , ( ) => {
17
+ const plus_one = VALID_12 + ' lol' ;
18
+ expect ( failedSeedPhraseRequirements ( plus_one ) ) . toEqual ( true ) ;
19
+ } ) ;
20
+ it ( 'Should fail for 24 + 1 word mnemonic' , ( ) => {
21
+ const plus_one = VALID_24 + ' lol' ;
22
+ expect ( failedSeedPhraseRequirements ( plus_one ) ) . toEqual ( true ) ;
23
+ } ) ;
24
+ } ) ;
You can’t perform that action at this time.
0 commit comments