mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-18 08:45:05 +00:00
Changed way for validation of seed phrase. Added multi words to text field on restore from seed screen.
This commit is contained in:
parent
6154c6dfa5
commit
92c2cfcbab
15 changed files with 102 additions and 67 deletions
|
@ -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<S> {
|
||||
|
|
|
@ -48,17 +48,12 @@ class RestoreFromSeedForm extends StatefulWidget {
|
|||
|
||||
class _RestoreFromSeedFormState extends State<RestoreFromSeedForm> {
|
||||
final _seedKey = GlobalKey<SeedWidgetState>();
|
||||
bool _reactionSet = false;
|
||||
|
||||
void clear() => _seedKey.currentState.clear();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final walletRestorationStore = Provider.of<WalletRestorationStore>(context);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => _setReactions(context, walletRestorationStore));
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () =>
|
||||
SystemChannels.textInput.invokeMethod<void>('TextInput.hide'),
|
||||
|
@ -74,22 +69,4 @@ class _RestoreFromSeedFormState extends State<RestoreFromSeedForm> {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,9 @@ class SeedWidgetState extends State<SeedWidget> {
|
|||
bool isValid;
|
||||
String errorMessage;
|
||||
|
||||
MnemoticItem currentMnemotic;
|
||||
List<MnemoticItem> currentMnemotics;
|
||||
bool isCurrentMnemoticValid;
|
||||
String _errorMessage;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -49,14 +50,6 @@ class SeedWidgetState extends State<SeedWidget> {
|
|||
}
|
||||
}
|
||||
|
||||
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<SeedWidget> {
|
|||
void selectMnemotic(MnemoticItem item) {
|
||||
setState(() {
|
||||
selectedItem = item;
|
||||
currentMnemotic = item;
|
||||
currentMnemotics = [item];
|
||||
|
||||
_seedController
|
||||
..text = item.text
|
||||
|
@ -106,18 +99,6 @@ class SeedWidgetState extends State<SeedWidget> {
|
|||
}
|
||||
}
|
||||
|
||||
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<SeedWidget> {
|
|||
|
||||
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<SeedWidget> {
|
|||
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<SeedWidget> {
|
|||
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<SeedWidget> {
|
|||
onPressed: () => isCurrentMnemoticValid
|
||||
? saveCurrentMnemoticToItems()
|
||||
: null,
|
||||
onDisabledPressed: () => showErrorIfExist(),
|
||||
isDisabled: !isCurrentMnemoticValid,
|
||||
color: PaletteDark.darkThemeBlueButton,
|
||||
borderColor: Palette.brightBlue))
|
||||
|
|
|
@ -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."
|
||||
}
|
|
@ -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."
|
||||
}
|
|
@ -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."
|
||||
}
|
|
@ -335,5 +335,6 @@
|
|||
|
||||
"paste" : "पेस्ट करें",
|
||||
"restore_from_seed_placeholder" : "कृपया अपना कोड वाक्यांश यहां दर्ज करें या पेस्ट करें",
|
||||
"add_new_word" : "नया शब्द जोड़ें"
|
||||
"add_new_word" : "नया शब्द जोड़ें",
|
||||
"incorrect_seed" : "दर्ज किया गया पाठ मान्य नहीं है।"
|
||||
}
|
|
@ -336,5 +336,6 @@
|
|||
"paste" : "ペースト",
|
||||
"restore_from_seed_placeholder" : "ここにコードフレーズを入力または貼り付けてください",
|
||||
"add_new_word" : "新しい単語を追加",
|
||||
"add_new_word" : "새로운 단어 추가"
|
||||
"add_new_word" : "새로운 단어 추가",
|
||||
"incorrect_seed" : "入力されたテキストは無効です。"
|
||||
}
|
|
@ -334,5 +334,6 @@
|
|||
"change_language_to" : "언어를로 변경 ${language}?",
|
||||
|
||||
"paste" : "풀",
|
||||
"restore_from_seed_placeholder" : "여기에 코드 문구를 입력하거나 붙여 넣으십시오."
|
||||
"restore_from_seed_placeholder" : "여기에 코드 문구를 입력하거나 붙여 넣으십시오.",
|
||||
"incorrect_seed" : "입력하신 텍스트가 유효하지 않습니다."
|
||||
}
|
|
@ -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."
|
||||
}
|
|
@ -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."
|
||||
}
|
|
@ -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."
|
||||
}
|
||||
|
|
|
@ -335,5 +335,6 @@
|
|||
|
||||
"paste" : "Вставить",
|
||||
"restore_from_seed_placeholder" : "Введите или вставте код фразу вашего кошелька",
|
||||
"add_new_word" : "Добавить новое слово"
|
||||
"add_new_word" : "Добавить новое слово",
|
||||
"incorrect_seed" : "Введенный текст некорректный."
|
||||
}
|
|
@ -335,5 +335,6 @@
|
|||
|
||||
"paste" : "糊",
|
||||
"restore_from_seed_placeholder" : "请在此处输入或粘贴您的代码短语",
|
||||
"add_new_word" : "添加新词"
|
||||
"add_new_word" : "添加新词",
|
||||
"incorrect_seed" : "输入的文字无效。"
|
||||
}
|
Loading…
Reference in a new issue