From bc07f9d69b9357085d3bdea505c007e1fda3525a Mon Sep 17 00:00:00 2001 From: M Date: Wed, 19 Jan 2022 17:27:53 +0200 Subject: [PATCH] Fixes for validation of bitcoin seed mnemonic text. --- .../screens/restore/wallet_restore_page.dart | 33 +++++++++++++------ lib/view_model/wallet_restore_view_model.dart | 8 ++--- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/src/screens/restore/wallet_restore_page.dart b/lib/src/screens/restore/wallet_restore_page.dart index d1ccadaa3..1dbb1b8b7 100644 --- a/lib/src/screens/restore/wallet_restore_page.dart +++ b/lib/src/screens/restore/wallet_restore_page.dart @@ -1,5 +1,6 @@ import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; +import 'package:cw_core/wallet_type.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:keyboard_actions/keyboard_actions.dart'; @@ -46,15 +47,19 @@ class WalletRestorePage extends BasePage { } }, onSeedChange: (String seed) { - final hasHeight = walletRestoreFromSeedFormKey - .currentState - .blockchainHeightKey - .currentState - .restoreHeightController - .text - .isNotEmpty; - if (hasHeight) { - walletRestoreViewModel.isButtonEnabled = _isValidSeed(); + if (walletRestoreViewModel.hasBlockchainHeightLanguageSelector) { + final hasHeight = walletRestoreFromSeedFormKey + .currentState + .blockchainHeightKey + .currentState + .restoreHeightController + .text + .isNotEmpty; + if (hasHeight) { + walletRestoreViewModel.isButtonEnabled = _isValidSeed(); + } + } else { + walletRestoreViewModel.isButtonEnabled = _isValidSeed(); } }, onLanguageChange: (_) { @@ -209,8 +214,16 @@ class WalletRestorePage extends BasePage { .currentState .text .split(' '); + + if (walletRestoreViewModel.type == WalletType.monero && + seedWords.length != WalletRestoreViewModelBase.moneroSeedMnemonicLength) { + return false; + } - if (seedWords.length != walletRestoreViewModel.seedMnemonicLength) { + if ((walletRestoreViewModel.type == WalletType.bitcoin || + walletRestoreViewModel.type == WalletType.litecoin) && + (seedWords.length != WalletRestoreViewModelBase.electrumSeedMnemonicLength && + seedWords.length != WalletRestoreViewModelBase.electrumShortSeedMnemonicLength)) { return false; } diff --git a/lib/view_model/wallet_restore_view_model.dart b/lib/view_model/wallet_restore_view_model.dart index e1ebdbce4..818b72eb1 100644 --- a/lib/view_model/wallet_restore_view_model.dart +++ b/lib/view_model/wallet_restore_view_model.dart @@ -38,6 +38,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { static const moneroSeedMnemonicLength = 25; static const electrumSeedMnemonicLength = 24; + static const electrumShortSeedMnemonicLength = 12; final List availableModes; final bool hasSeedLanguageSelector; @@ -49,12 +50,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { @observable bool isButtonEnabled; - - int get seedMnemonicLength => - type == WalletType.monero - ? moneroSeedMnemonicLength - : electrumSeedMnemonicLength; - + @override WalletCredentials getCredentials(dynamic options) { final password = generateWalletPassword(type);