Changed way for validation of seed phrase. Added multi words to text field on restore from seed screen.
M committed
Jan 17, 2020 at 15:26 UTC
92c2cfcbabb96c49e9c15683c2ad8ec5836f4abf
15 files changed
+102
-67
lib/generated/i18n.dart
+21
@@ -289,6 +289,7 @@ class S implements WidgetsLocalizations {
289
String get paste => "Paste";
290
String get restore_from_seed_placeholder => "Please enter or paste your seed here";
291
String get add_new_word => "Add new word";
292
+ String get incorrect_seed => 'The text entered is not valid.';
293
}
294
295
class $de extends S {
@@ -833,6 +834,8 @@ class $de extends S {
834
String get restore_from_seed_placeholder => "Bitte geben Sie hier Ihren Code ein";
835
@override
836
String get add_new_word => "Neues Wort hinzufügen";
837
+ @override
838
+ String get incorrect_seed => 'Der eingegebene Text ist ungültig.';
839
}
840
841
class $hi extends S {
@@ -1377,6 +1380,8 @@ class $hi extends S {
1380
String get restore_from_seed_placeholder => "कृपया अपना कोड वाक्यांश यहां दर्ज करें या पेस्ट करें";
1381
@override
1382
String get add_new_word => "नया शब्द जोड़ें";
1383
+ @override
1384
+ String get incorrect_seed => 'दर्ज किया गया पाठ मान्य नहीं है।';
1385
}
1386
1387
class $ru extends S {
@@ -1921,6 +1926,8 @@ class $ru extends S {
1926
String get restore_from_seed_placeholder => "Введите или вставте код фразу вашего кошелька";
1927
@override
1928
String get add_new_word => "Добавить новое слово";
1929
+ @override
1930
+ String get incorrect_seed => 'Введенный текст некорректный.';
1931
}
1932
1933
class $ko extends S {
@@ -2465,6 +2472,8 @@ class $ko extends S {
2472
String get restore_from_seed_placeholder => "여기에 코드 문구를 입력하거나 붙여 넣으십시오.";
2473
@override
2474
String get add_new_word => "새로운 단어 추가";
2475
+ @override
2476
+ String get incorrect_seed => '입력하신 텍스트가 유효하지 않습니다.';
2477
}
2478
2479
class $pt extends S {
@@ -3009,6 +3018,8 @@ class $pt extends S {
3018
String get restore_from_seed_placeholder => "Digite ou cole sua frase de código aqui";
3019
@override
3020
String get add_new_word => "Adicionar nova palavra";
3021
+ @override
3022
+ String get incorrect_seed => 'O texto digitado não é válido.';
3023
}
3024
3025
class $ja extends S {
@@ -3553,6 +3564,8 @@ class $ja extends S {
3564
String get restore_from_seed_placeholder => "ここにコードフレーズを入力または貼り付けてください";
3565
@override
3566
String get add_new_word => "新しい単語を追加";
3567
+ @override
3568
+ String get incorrect_seed => '入力されたテキストは無効です。';
3569
}
3570
3571
class $en extends S {
@@ -4101,6 +4114,8 @@ class $pl extends S {
4114
String get restore_from_seed_placeholder => "Wpisz lub wklej tutaj swoją frazę kodową";
4115
@override
4116
String get add_new_word => "Dodaj nowe słowo";
4117
+ @override
4118
+ String get incorrect_seed => 'Wprowadzony tekst jest nieprawidłowy.';
4119
}
4120
4121
class $es extends S {
@@ -4645,6 +4660,8 @@ class $es extends S {
4660
String get restore_from_seed_placeholder => "Ingrese o pegue su frase de código aquí";
4661
@override
4662
String get add_new_word => "Agregar palabra nueva";
4663
+ @override
4664
+ String get incorrect_seed => 'El texto ingresado no es válido.';
4665
}
4666
4667
class $nl extends S {
@@ -5189,6 +5206,8 @@ class $nl extends S {
5206
String get restore_from_seed_placeholder => "Voer hier uw codefrase in of plak deze";
5207
@override
5208
String get add_new_word => "Nieuw woord toevoegen";
5209
+ @override
5210
+ String get incorrect_seed => 'De ingevoerde tekst is niet geldig.';
5211
}
5212
5213
class $zh extends S {
@@ -5733,6 +5752,8 @@ class $zh extends S {
5752
String get restore_from_seed_placeholder => "请在此处输入或粘贴您的代码短语";
5753
@override
5754
String get add_new_word => "添加新词";
5755
+ @override
5756
+ String get incorrect_seed => '输入的文字无效。';
5757
}
5758
5759
class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
lib/src/screens/restore/restore_wallet_from_seed_page.dart
-23
@@ -48,17 +48,12 @@ class RestoreFromSeedForm extends StatefulWidget {
48
49
class _RestoreFromSeedFormState extends State<RestoreFromSeedForm> {
50
final _seedKey = GlobalKey<SeedWidgetState>();
51
- bool _reactionSet = false;
52
-
51
void clear() => _seedKey.currentState.clear();
52
53
@override
54
Widget build(BuildContext context) {
55
final walletRestorationStore = Provider.of<WalletRestorationStore>(context);
56
59
- WidgetsBinding.instance.addPostFrameCallback(
60
- (_) => _setReactions(context, walletRestorationStore));
61
-
57
return GestureDetector(
58
onTap: () =>
59
SystemChannels.textInput.invokeMethod<void>('TextInput.hide'),
@@ -74,22 +69,4 @@ class _RestoreFromSeedFormState extends State<RestoreFromSeedForm> {
69
),
70
);
71
}
77
-
78
- void _setReactions(BuildContext context, WalletRestorationStore store) {
79
- if (_reactionSet) {
80
- return;
81
- }
82
-
83
- reaction((_) => store.errorMessage, (String errorMessage) {
84
- if (errorMessage == null || errorMessage.isEmpty) {
85
- _seedKey.currentState.validated();
86
- } else {
87
- _seedKey.currentState.invalidate();
88
- }
89
-
90
- _seedKey.currentState.setErrorMessage(errorMessage);
91
- });
92
-
93
- _reactionSet = true;
94
- }
72
}
lib/src/widgets/primary_button.dart
+10
-5
@@ -8,10 +8,11 @@ class PrimaryButton extends StatelessWidget {
8
@required this.text,
9
@required this.color,
10
@required this.borderColor,
11
-
12
- this.isDisabled = false});
11
+ this.isDisabled = false,
12
+ this.onDisabledPressed});
13
14
final VoidCallback onPressed;
15
+ final VoidCallback onDisabledPressed;
16
final Color color;
17
final Color borderColor;
18
final String text;
@@ -23,15 +24,19 @@ class PrimaryButton extends StatelessWidget {
24
minWidth: double.infinity,
25
height: 56.0,
26
child: FlatButton(
26
- onPressed: isDisabled ? null : onPressed,
27
- color: isDisabled ? Colors.grey : color,
27
+ onPressed: isDisabled
28
+ ? (onDisabledPressed != null ? onDisabledPressed : null)
29
+ : onPressed,
30
+ color: isDisabled ? Colors.transparent : color,
31
shape: RoundedRectangleBorder(
32
side: BorderSide(color: borderColor),
33
borderRadius: BorderRadius.circular(10.0)),
34
child: Text(text,
35
style: TextStyle(
36
fontSize: 16.0,
34
- color: isDisabled ? Palette.darkGrey : Theme.of(context).primaryTextTheme.button.color)),
37
+ color: isDisabled
38
+ ? Palette.darkGrey
39
+ : Theme.of(context).primaryTextTheme.button.color)),
40
));
41
}
42
}
lib/src/widgets/seed_widget.dart
+49
-28
@@ -27,8 +27,9 @@ class SeedWidgetState extends State<SeedWidget> {
27
bool isValid;
28
String errorMessage;
29
30
- MnemoticItem currentMnemotic;
30
+ List<MnemoticItem> currentMnemotics;
31
bool isCurrentMnemoticValid;
32
+ String _errorMessage;
33
34
@override
35
void initState() {
@@ -49,14 +50,6 @@ class SeedWidgetState extends State<SeedWidget> {
50
}
51
}
52
52
- void deleteMnemotic(MnemoticItem item) {
53
- setState(() => items.remove(item));
54
-
55
- if (widget.onMnemoticChange != null) {
56
- widget.onMnemoticChange(items);
57
- }
58
- }
59
-
53
void mnemoticFromText(String text) {
54
final splitted = text.split(' ');
55
@@ -78,7 +71,7 @@ class SeedWidgetState extends State<SeedWidget> {
71
void selectMnemotic(MnemoticItem item) {
72
setState(() {
73
selectedItem = item;
81
- currentMnemotic = item;
74
+ currentMnemotics = [item];
75
76
_seedController
77
..text = item.text
@@ -106,18 +99,6 @@ class SeedWidgetState extends State<SeedWidget> {
99
}
100
}
101
109
- void onFieldSubmitted(String text) {
110
- if (text.isEmpty || text == null) {
111
- return;
112
- }
113
-
114
- if (selectedItem != null) {
115
- editTextOfSelectedMnemotic(text);
116
- } else {
117
- addMnemotic(text);
118
- }
119
- }
120
-
102
void clear() {
103
setState(() {
104
items = [];
@@ -149,31 +130,68 @@ class SeedWidgetState extends State<SeedWidget> {
130
131
void changeCurrentMnemotic(String text) {
132
setState(() {
133
+ final trimmedText = text.trim();
134
+ final splitted = trimmedText.split(' ');
135
+ _errorMessage = null;
136
+
137
if (text == null) {
153
- currentMnemotic = null;
138
+ currentMnemotics = [];
139
isCurrentMnemoticValid = false;
140
return;
141
}
142
158
- currentMnemotic = MnemoticItem(text: text, dic: EnglishMnemonics.words);
159
- isCurrentMnemoticValid = currentMnemotic.isCorrect();
143
+ currentMnemotics = splitted
144
+ .map((text) => MnemoticItem(text: text, dic: EnglishMnemonics.words))
145
+ .toList();
146
+
147
+ bool isValid = true;
148
+
149
+ for (final word in currentMnemotics) {
150
+ print('word ${word.text}');
151
+ isValid = word.isCorrect();
152
+
153
+ if (!isValid) {
154
+ break;
155
+ }
156
+ }
157
+
158
+ isCurrentMnemoticValid = isValid;
159
});
160
}
161
162
void saveCurrentMnemoticToItems() {
163
setState(() {
164
if (selectedItem != null) {
166
- selectedItem.changeText(currentMnemotic.text);
165
+ selectedItem.changeText(currentMnemotics.first.text.trim());
166
selectedItem = null;
167
} else {
169
- items.add(currentMnemotic);
168
+ items.addAll(currentMnemotics);
169
}
170
172
- currentMnemotic = null;
171
+ currentMnemotics = [];
172
_seedController.text = '';
173
});
174
}
175
176
+ void showErrorIfExist() {
177
+ setState(() => _errorMessage =
178
+ !isCurrentMnemoticValid ? S.current.incorrect_seed : null);
179
+ }
180
+
181
+ bool isSeedValid() {
182
+ bool isValid;
183
+
184
+ for (final item in items) {
185
+ isValid = item.isCorrect();
186
+
187
+ if (!isValid) {
188
+ break;
189
+ }
190
+ }
191
+
192
+ return isValid;
193
+ }
194
+
195
@override
196
Widget build(BuildContext context) {
197
return Container(
@@ -258,6 +276,7 @@ class SeedWidgetState extends State<SeedWidget> {
276
hintStyle:
277
TextStyle(color: Theme.of(context).hintColor),
278
hintText: S.of(context).restore_from_seed_placeholder,
279
+ errorText: _errorMessage,
280
focusedBorder: UnderlineInputBorder(
281
borderSide: BorderSide(
282
color: Palette.cakeGreen, width: 2.0)),
@@ -273,6 +292,7 @@ class SeedWidgetState extends State<SeedWidget> {
292
child: (selectedItem == null && items.length == maxLength)
293
? PrimaryButton(
294
text: S.of(context).restore_next,
295
+ isDisabled: !isSeedValid(),
296
onPressed: () => widget.onFinish != null
297
? widget.onFinish()
298
: null,
@@ -291,6 +311,7 @@ class SeedWidgetState extends State<SeedWidget> {
311
onPressed: () => isCurrentMnemoticValid
312
? saveCurrentMnemoticToItems()
313
: null,
314
+ onDisabledPressed: () => showErrorIfExist(),
315
isDisabled: !isCurrentMnemoticValid,
316
color: PaletteDark.darkThemeBlueButton,
317
borderColor: Palette.brightBlue))
res/values/strings_de.arb
+2
-1
@@ -335,5 +335,6 @@
335
336
"paste" : "Einfügen",
337
"restore_from_seed_placeholder" : "Bitte geben Sie hier Ihren Code ein",
338
- "add_new_word" : "Neues Wort hinzufügen"
338
+ "add_new_word" : "Neues Wort hinzufügen",
339
+ "incorrect_seed" : "Der eingegebene Text ist ungültig."
340
}
\ No newline at end of file
res/values/strings_en.arb
+2
-1
@@ -335,5 +335,6 @@
335
336
"paste" : ""paste"",
337
"restore_from_seed_placeholder" : "Please enter or "paste" your seed here",
338
- "add_new_word" : "Add new word"
338
+ "add_new_word" : "Add new word",
339
+ "incorrect_seed" : "The text entered is not valid."
340
}
\ No newline at end of file
res/values/strings_es.arb
+2
-1
@@ -335,5 +335,6 @@
335
336
"paste" : "Pegar",
337
"restore_from_seed_placeholder" : "Ingrese o pegue su frase de código aquí",
338
- "add_new_word" : "Agregar palabra nueva"
338
+ "add_new_word" : "Agregar palabra nueva",
339
+ "incorrect_seed" : "El texto ingresado no es válido."
340
}
\ No newline at end of file
res/values/strings_hi.arb
+2
-1
@@ -335,5 +335,6 @@
335
336
"paste" : "पेस्ट करें",
337
"restore_from_seed_placeholder" : "कृपया अपना कोड वाक्यांश यहां दर्ज करें या पेस्ट करें",
338
- "add_new_word" : "नया शब्द जोड़ें"
338
+ "add_new_word" : "नया शब्द जोड़ें",
339
+ "incorrect_seed" : "दर्ज किया गया पाठ मान्य नहीं है।"
340
}
\ No newline at end of file
res/values/strings_ja.arb
+2
-1
@@ -336,5 +336,6 @@
336
"paste" : "ペースト",
337
"restore_from_seed_placeholder" : "ここにコードフレーズを入力または貼り付けてください",
338
"add_new_word" : "新しい単語を追加",
339
- "add_new_word" : "새로운 단어 추가"
339
+ "add_new_word" : "새로운 단어 추가",
340
+ "incorrect_seed" : "入力されたテキストは無効です。"
341
}
\ No newline at end of file
res/values/strings_ko.arb
+2
-1
@@ -334,5 +334,6 @@
334
"change_language_to" : "언어를로 변경 ${language}?",
335
336
"paste" : "풀",
337
- "restore_from_seed_placeholder" : "여기에 코드 문구를 입력하거나 붙여 넣으십시오."
337
+ "restore_from_seed_placeholder" : "여기에 코드 문구를 입력하거나 붙여 넣으십시오.",
338
+ "incorrect_seed" : "입력하신 텍스트가 유효하지 않습니다."
339
}
\ No newline at end of file
res/values/strings_nl.arb
+2
-1
@@ -335,5 +335,6 @@
335
336
"paste" : "Plakken",
337
"restore_from_seed_placeholder" : "Voer hier uw codefrase in of plak deze",
338
- "add_new_word" : "Nieuw woord toevoegen"
338
+ "add_new_word" : "Nieuw woord toevoegen",
339
+ "incorrect_seed" : "De ingevoerde tekst is niet geldig."
340
}
\ No newline at end of file
res/values/strings_pl.arb
+2
-1
@@ -335,5 +335,6 @@
335
336
"paste" : "Pasta",
337
"restore_from_seed_placeholder" : "Wpisz lub wklej tutaj swoją frazę kodową",
338
- "add_new_word" : "Dodaj nowe słowo"
338
+ "add_new_word" : "Dodaj nowe słowo",
339
+ "incorrect_seed" : "Wprowadzony tekst jest nieprawidłowy."
340
}
\ No newline at end of file
res/values/strings_pt.arb
+2
-1
@@ -335,5 +335,6 @@
335
336
"paste" : "Colar",
337
"restore_from_seed_placeholder" : "Digite ou cole sua frase de código aqui",
338
- "add_new_word" : "Adicionar nova palavra"
338
+ "add_new_word" : "Adicionar nova palavra",
339
+ "incorrect_seed" : "O texto digitado não é válido."
340
}
res/values/strings_ru.arb
+2
-1
@@ -335,5 +335,6 @@
335
336
"paste" : "Вставить",
337
"restore_from_seed_placeholder" : "Введите или вставте код фразу вашего кошелька",
338
- "add_new_word" : "Добавить новое слово"
338
+ "add_new_word" : "Добавить новое слово",
339
+ "incorrect_seed" : "Введенный текст некорректный."
340
}
\ No newline at end of file
res/values/strings_zh.arb
+2
-1
@@ -335,5 +335,6 @@
335
336
"paste" : "糊",
337
"restore_from_seed_placeholder" : "请在此处输入或粘贴您的代码短语",
338
- "add_new_word" : "添加新词"
338
+ "add_new_word" : "添加新词",
339
+ "incorrect_seed" : "输入的文字无效。"
340
}
\ No newline at end of file