Fixes for validation of bitcoin seed mnemonic text.

This commit is contained in:
M 2022-01-19 17:27:53 +02:00
parent bd2e2ce258
commit bc07f9d69b
2 changed files with 25 additions and 16 deletions

View file

@ -1,5 +1,6 @@
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.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/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:keyboard_actions/keyboard_actions.dart'; import 'package:keyboard_actions/keyboard_actions.dart';
@ -46,15 +47,19 @@ class WalletRestorePage extends BasePage {
} }
}, },
onSeedChange: (String seed) { onSeedChange: (String seed) {
final hasHeight = walletRestoreFromSeedFormKey if (walletRestoreViewModel.hasBlockchainHeightLanguageSelector) {
.currentState final hasHeight = walletRestoreFromSeedFormKey
.blockchainHeightKey .currentState
.currentState .blockchainHeightKey
.restoreHeightController .currentState
.text .restoreHeightController
.isNotEmpty; .text
if (hasHeight) { .isNotEmpty;
walletRestoreViewModel.isButtonEnabled = _isValidSeed(); if (hasHeight) {
walletRestoreViewModel.isButtonEnabled = _isValidSeed();
}
} else {
walletRestoreViewModel.isButtonEnabled = _isValidSeed();
} }
}, },
onLanguageChange: (_) { onLanguageChange: (_) {
@ -209,8 +214,16 @@ class WalletRestorePage extends BasePage {
.currentState .currentState
.text .text
.split(' '); .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; return false;
} }

View file

@ -38,6 +38,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
static const moneroSeedMnemonicLength = 25; static const moneroSeedMnemonicLength = 25;
static const electrumSeedMnemonicLength = 24; static const electrumSeedMnemonicLength = 24;
static const electrumShortSeedMnemonicLength = 12;
final List<WalletRestoreMode> availableModes; final List<WalletRestoreMode> availableModes;
final bool hasSeedLanguageSelector; final bool hasSeedLanguageSelector;
@ -49,12 +50,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
@observable @observable
bool isButtonEnabled; bool isButtonEnabled;
int get seedMnemonicLength =>
type == WalletType.monero
? moneroSeedMnemonicLength
: electrumSeedMnemonicLength;
@override @override
WalletCredentials getCredentials(dynamic options) { WalletCredentials getCredentials(dynamic options) {
final password = generateWalletPassword(type); final password = generateWalletPassword(type);