diff --git a/lib/generated/i18n.dart b/lib/generated/i18n.dart index 2ab5b9c92..dcc36edb6 100644 --- a/lib/generated/i18n.dart +++ b/lib/generated/i18n.dart @@ -289,6 +289,7 @@ class S implements WidgetsLocalizations { String get paste => "Paste"; String get restore_from_seed_placeholder => "Please enter or paste your seed here"; String get add_new_word => "Add new word"; + String get incorrect_seed => 'The text entered is not valid.'; } class $de extends S { @@ -833,6 +834,8 @@ class $de extends S { String get restore_from_seed_placeholder => "Bitte geben Sie hier Ihren Code ein"; @override String get add_new_word => "Neues Wort hinzufügen"; + @override + String get incorrect_seed => 'Der eingegebene Text ist ungültig.'; } class $hi extends S { @@ -1377,6 +1380,8 @@ class $hi extends S { String get restore_from_seed_placeholder => "कृपया अपना कोड वाक्यांश यहां दर्ज करें या पेस्ट करें"; @override String get add_new_word => "नया शब्द जोड़ें"; + @override + String get incorrect_seed => 'दर्ज किया गया पाठ मान्य नहीं है।'; } class $ru extends S { @@ -1921,6 +1926,8 @@ class $ru extends S { String get restore_from_seed_placeholder => "Введите или вставте код фразу вашего кошелька"; @override String get add_new_word => "Добавить новое слово"; + @override + String get incorrect_seed => 'Введенный текст некорректный.'; } class $ko extends S { @@ -2465,6 +2472,8 @@ class $ko extends S { String get restore_from_seed_placeholder => "여기에 코드 문구를 입력하거나 붙여 넣으십시오."; @override String get add_new_word => "새로운 단어 추가"; + @override + String get incorrect_seed => '입력하신 텍스트가 유효하지 않습니다.'; } class $pt extends S { @@ -3009,6 +3018,8 @@ class $pt extends S { String get restore_from_seed_placeholder => "Digite ou cole sua frase de código aqui"; @override String get add_new_word => "Adicionar nova palavra"; + @override + String get incorrect_seed => 'O texto digitado não é válido.'; } class $ja extends S { @@ -3553,6 +3564,8 @@ class $ja extends S { String get restore_from_seed_placeholder => "ここにコードフレーズを入力または貼り付けてください"; @override String get add_new_word => "新しい単語を追加"; + @override + String get incorrect_seed => '入力されたテキストは無効です。'; } class $en extends S { @@ -4101,6 +4114,8 @@ class $pl extends S { String get restore_from_seed_placeholder => "Wpisz lub wklej tutaj swoją frazę kodową"; @override String get add_new_word => "Dodaj nowe słowo"; + @override + String get incorrect_seed => 'Wprowadzony tekst jest nieprawidłowy.'; } class $es extends S { @@ -4645,6 +4660,8 @@ class $es extends S { String get restore_from_seed_placeholder => "Ingrese o pegue su frase de código aquí"; @override String get add_new_word => "Agregar palabra nueva"; + @override + String get incorrect_seed => 'El texto ingresado no es válido.'; } class $nl extends S { @@ -5189,6 +5206,8 @@ class $nl extends S { String get restore_from_seed_placeholder => "Voer hier uw codefrase in of plak deze"; @override String get add_new_word => "Nieuw woord toevoegen"; + @override + String get incorrect_seed => 'De ingevoerde tekst is niet geldig.'; } class $zh extends S { @@ -5733,6 +5752,8 @@ class $zh extends S { String get restore_from_seed_placeholder => "请在此处输入或粘贴您的代码短语"; @override String get add_new_word => "添加新词"; + @override + String get incorrect_seed => '输入的文字无效。'; } class GeneratedLocalizationsDelegate extends LocalizationsDelegate { diff --git a/lib/src/screens/restore/restore_wallet_from_seed_page.dart b/lib/src/screens/restore/restore_wallet_from_seed_page.dart index 1c9998d2d..124327018 100644 --- a/lib/src/screens/restore/restore_wallet_from_seed_page.dart +++ b/lib/src/screens/restore/restore_wallet_from_seed_page.dart @@ -48,17 +48,12 @@ class RestoreFromSeedForm extends StatefulWidget { class _RestoreFromSeedFormState extends State { final _seedKey = GlobalKey(); - bool _reactionSet = false; - void clear() => _seedKey.currentState.clear(); @override Widget build(BuildContext context) { final walletRestorationStore = Provider.of(context); - WidgetsBinding.instance.addPostFrameCallback( - (_) => _setReactions(context, walletRestorationStore)); - return GestureDetector( onTap: () => SystemChannels.textInput.invokeMethod('TextInput.hide'), @@ -74,22 +69,4 @@ class _RestoreFromSeedFormState extends State { ), ); } - - void _setReactions(BuildContext context, WalletRestorationStore store) { - if (_reactionSet) { - return; - } - - reaction((_) => store.errorMessage, (String errorMessage) { - if (errorMessage == null || errorMessage.isEmpty) { - _seedKey.currentState.validated(); - } else { - _seedKey.currentState.invalidate(); - } - - _seedKey.currentState.setErrorMessage(errorMessage); - }); - - _reactionSet = true; - } } diff --git a/lib/src/widgets/primary_button.dart b/lib/src/widgets/primary_button.dart index 6ef8f1af8..d87838830 100644 --- a/lib/src/widgets/primary_button.dart +++ b/lib/src/widgets/primary_button.dart @@ -8,10 +8,11 @@ class PrimaryButton extends StatelessWidget { @required this.text, @required this.color, @required this.borderColor, - - this.isDisabled = false}); + this.isDisabled = false, + this.onDisabledPressed}); final VoidCallback onPressed; + final VoidCallback onDisabledPressed; final Color color; final Color borderColor; final String text; @@ -23,15 +24,19 @@ class PrimaryButton extends StatelessWidget { minWidth: double.infinity, height: 56.0, child: FlatButton( - onPressed: isDisabled ? null : onPressed, - color: isDisabled ? Colors.grey : color, + onPressed: isDisabled + ? (onDisabledPressed != null ? onDisabledPressed : null) + : onPressed, + color: isDisabled ? Colors.transparent : color, shape: RoundedRectangleBorder( side: BorderSide(color: borderColor), borderRadius: BorderRadius.circular(10.0)), child: Text(text, style: TextStyle( fontSize: 16.0, - color: isDisabled ? Palette.darkGrey : Theme.of(context).primaryTextTheme.button.color)), + color: isDisabled + ? Palette.darkGrey + : Theme.of(context).primaryTextTheme.button.color)), )); } } diff --git a/lib/src/widgets/seed_widget.dart b/lib/src/widgets/seed_widget.dart index 209d7e070..aa6bf57b0 100644 --- a/lib/src/widgets/seed_widget.dart +++ b/lib/src/widgets/seed_widget.dart @@ -27,8 +27,9 @@ class SeedWidgetState extends State { bool isValid; String errorMessage; - MnemoticItem currentMnemotic; + List currentMnemotics; bool isCurrentMnemoticValid; + String _errorMessage; @override void initState() { @@ -49,14 +50,6 @@ class SeedWidgetState extends State { } } - void deleteMnemotic(MnemoticItem item) { - setState(() => items.remove(item)); - - if (widget.onMnemoticChange != null) { - widget.onMnemoticChange(items); - } - } - void mnemoticFromText(String text) { final splitted = text.split(' '); @@ -78,7 +71,7 @@ class SeedWidgetState extends State { void selectMnemotic(MnemoticItem item) { setState(() { selectedItem = item; - currentMnemotic = item; + currentMnemotics = [item]; _seedController ..text = item.text @@ -106,18 +99,6 @@ class SeedWidgetState extends State { } } - void onFieldSubmitted(String text) { - if (text.isEmpty || text == null) { - return; - } - - if (selectedItem != null) { - editTextOfSelectedMnemotic(text); - } else { - addMnemotic(text); - } - } - void clear() { setState(() { items = []; @@ -149,31 +130,68 @@ class SeedWidgetState extends State { void changeCurrentMnemotic(String text) { setState(() { + final trimmedText = text.trim(); + final splitted = trimmedText.split(' '); + _errorMessage = null; + if (text == null) { - currentMnemotic = null; + currentMnemotics = []; isCurrentMnemoticValid = false; return; } - currentMnemotic = MnemoticItem(text: text, dic: EnglishMnemonics.words); - isCurrentMnemoticValid = currentMnemotic.isCorrect(); + currentMnemotics = splitted + .map((text) => MnemoticItem(text: text, dic: EnglishMnemonics.words)) + .toList(); + + bool isValid = true; + + for (final word in currentMnemotics) { + print('word ${word.text}'); + isValid = word.isCorrect(); + + if (!isValid) { + break; + } + } + + isCurrentMnemoticValid = isValid; }); } void saveCurrentMnemoticToItems() { setState(() { if (selectedItem != null) { - selectedItem.changeText(currentMnemotic.text); + selectedItem.changeText(currentMnemotics.first.text.trim()); selectedItem = null; } else { - items.add(currentMnemotic); + items.addAll(currentMnemotics); } - currentMnemotic = null; + currentMnemotics = []; _seedController.text = ''; }); } + void showErrorIfExist() { + setState(() => _errorMessage = + !isCurrentMnemoticValid ? S.current.incorrect_seed : null); + } + + bool isSeedValid() { + bool isValid; + + for (final item in items) { + isValid = item.isCorrect(); + + if (!isValid) { + break; + } + } + + return isValid; + } + @override Widget build(BuildContext context) { return Container( @@ -258,6 +276,7 @@ class SeedWidgetState extends State { hintStyle: TextStyle(color: Theme.of(context).hintColor), hintText: S.of(context).restore_from_seed_placeholder, + errorText: _errorMessage, focusedBorder: UnderlineInputBorder( borderSide: BorderSide( color: Palette.cakeGreen, width: 2.0)), @@ -273,6 +292,7 @@ class SeedWidgetState extends State { child: (selectedItem == null && items.length == maxLength) ? PrimaryButton( text: S.of(context).restore_next, + isDisabled: !isSeedValid(), onPressed: () => widget.onFinish != null ? widget.onFinish() : null, @@ -291,6 +311,7 @@ class SeedWidgetState extends State { onPressed: () => isCurrentMnemoticValid ? saveCurrentMnemoticToItems() : null, + onDisabledPressed: () => showErrorIfExist(), isDisabled: !isCurrentMnemoticValid, color: PaletteDark.darkThemeBlueButton, borderColor: Palette.brightBlue)) diff --git a/res/values/strings_de.arb b/res/values/strings_de.arb index 0e086a258..eeb48b405 100644 --- a/res/values/strings_de.arb +++ b/res/values/strings_de.arb @@ -335,5 +335,6 @@ "paste" : "Einfügen", "restore_from_seed_placeholder" : "Bitte geben Sie hier Ihren Code ein", - "add_new_word" : "Neues Wort hinzufügen" + "add_new_word" : "Neues Wort hinzufügen", + "incorrect_seed" : "Der eingegebene Text ist ungültig." } \ No newline at end of file diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb index a6bbc8266..32360c898 100644 --- a/res/values/strings_en.arb +++ b/res/values/strings_en.arb @@ -335,5 +335,6 @@ "paste" : ""paste"", "restore_from_seed_placeholder" : "Please enter or "paste" your seed here", - "add_new_word" : "Add new word" + "add_new_word" : "Add new word", + "incorrect_seed" : "The text entered is not valid." } \ No newline at end of file diff --git a/res/values/strings_es.arb b/res/values/strings_es.arb index 052ab1bbe..fa46ee111 100644 --- a/res/values/strings_es.arb +++ b/res/values/strings_es.arb @@ -335,5 +335,6 @@ "paste" : "Pegar", "restore_from_seed_placeholder" : "Ingrese o pegue su frase de código aquí", - "add_new_word" : "Agregar palabra nueva" + "add_new_word" : "Agregar palabra nueva", + "incorrect_seed" : "El texto ingresado no es válido." } \ No newline at end of file diff --git a/res/values/strings_hi.arb b/res/values/strings_hi.arb index b22ade21d..b6343da7d 100644 --- a/res/values/strings_hi.arb +++ b/res/values/strings_hi.arb @@ -335,5 +335,6 @@ "paste" : "पेस्ट करें", "restore_from_seed_placeholder" : "कृपया अपना कोड वाक्यांश यहां दर्ज करें या पेस्ट करें", - "add_new_word" : "नया शब्द जोड़ें" + "add_new_word" : "नया शब्द जोड़ें", + "incorrect_seed" : "दर्ज किया गया पाठ मान्य नहीं है।" } \ No newline at end of file diff --git a/res/values/strings_ja.arb b/res/values/strings_ja.arb index e92f2ac01..2f003be0d 100644 --- a/res/values/strings_ja.arb +++ b/res/values/strings_ja.arb @@ -336,5 +336,6 @@ "paste" : "ペースト", "restore_from_seed_placeholder" : "ここにコードフレーズを入力または貼り付けてください", "add_new_word" : "新しい単語を追加", - "add_new_word" : "새로운 단어 추가" + "add_new_word" : "새로운 단어 추가", + "incorrect_seed" : "入力されたテキストは無効です。" } \ No newline at end of file diff --git a/res/values/strings_ko.arb b/res/values/strings_ko.arb index 32946ba45..898b5f986 100644 --- a/res/values/strings_ko.arb +++ b/res/values/strings_ko.arb @@ -334,5 +334,6 @@ "change_language_to" : "언어를로 변경 ${language}?", "paste" : "풀", - "restore_from_seed_placeholder" : "여기에 코드 문구를 입력하거나 붙여 넣으십시오." + "restore_from_seed_placeholder" : "여기에 코드 문구를 입력하거나 붙여 넣으십시오.", + "incorrect_seed" : "입력하신 텍스트가 유효하지 않습니다." } \ No newline at end of file diff --git a/res/values/strings_nl.arb b/res/values/strings_nl.arb index 34b199512..986ebfa8e 100644 --- a/res/values/strings_nl.arb +++ b/res/values/strings_nl.arb @@ -335,5 +335,6 @@ "paste" : "Plakken", "restore_from_seed_placeholder" : "Voer hier uw codefrase in of plak deze", - "add_new_word" : "Nieuw woord toevoegen" + "add_new_word" : "Nieuw woord toevoegen", + "incorrect_seed" : "De ingevoerde tekst is niet geldig." } \ No newline at end of file diff --git a/res/values/strings_pl.arb b/res/values/strings_pl.arb index 82b08979c..bcfcffe1b 100644 --- a/res/values/strings_pl.arb +++ b/res/values/strings_pl.arb @@ -335,5 +335,6 @@ "paste" : "Pasta", "restore_from_seed_placeholder" : "Wpisz lub wklej tutaj swoją frazę kodową", - "add_new_word" : "Dodaj nowe słowo" + "add_new_word" : "Dodaj nowe słowo", + "incorrect_seed" : "Wprowadzony tekst jest nieprawidłowy." } \ No newline at end of file diff --git a/res/values/strings_pt.arb b/res/values/strings_pt.arb index 67037ce0f..8a6d6d4c8 100644 --- a/res/values/strings_pt.arb +++ b/res/values/strings_pt.arb @@ -335,5 +335,6 @@ "paste" : "Colar", "restore_from_seed_placeholder" : "Digite ou cole sua frase de código aqui", - "add_new_word" : "Adicionar nova palavra" + "add_new_word" : "Adicionar nova palavra", + "incorrect_seed" : "O texto digitado não é válido." } diff --git a/res/values/strings_ru.arb b/res/values/strings_ru.arb index 351256c1d..5ca7c9bcb 100644 --- a/res/values/strings_ru.arb +++ b/res/values/strings_ru.arb @@ -335,5 +335,6 @@ "paste" : "Вставить", "restore_from_seed_placeholder" : "Введите или вставте код фразу вашего кошелька", - "add_new_word" : "Добавить новое слово" + "add_new_word" : "Добавить новое слово", + "incorrect_seed" : "Введенный текст некорректный." } \ No newline at end of file diff --git a/res/values/strings_zh.arb b/res/values/strings_zh.arb index cfef8358d..69c5e886f 100644 --- a/res/values/strings_zh.arb +++ b/res/values/strings_zh.arb @@ -335,5 +335,6 @@ "paste" : "糊", "restore_from_seed_placeholder" : "请在此处输入或粘贴您的代码短语", - "add_new_word" : "添加新词" + "add_new_word" : "添加新词", + "incorrect_seed" : "输入的文字无效。" } \ No newline at end of file