cake_wallet/lib/core/seed_validator.dart
Konstantin Ullrich 7dd15914d0
Some checks failed
Cache Dependencies / test (push) Has been cancelled
Normalize text to fix french (#1504)
* Normalize text to fix french

* Normalize text to fix french

* Fix French?

* Fix French?

* Fix French?

* Polyseed v0.0.5
2024-06-24 19:38:32 +03:00

61 lines
2.2 KiB
Dart

import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/entities/mnemonic_item.dart';
import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/haven/haven.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/nano/nano.dart';
import 'package:cake_wallet/polygon/polygon.dart';
import 'package:cake_wallet/solana/solana.dart';
import 'package:cake_wallet/tron/tron.dart';
import 'package:cake_wallet/utils/language_list.dart';
import 'package:cw_core/wallet_type.dart';
class SeedValidator extends Validator<MnemonicItem> {
SeedValidator({required this.type, required this.language})
: _words = getWordList(type: type, language: language),
super(errorMessage: 'Wrong seed mnemonic');
final WalletType type;
final String language;
final List<String> _words;
static List<String> getWordList({required WalletType type, required String language}) {
switch (type) {
case WalletType.bitcoin:
return getBitcoinWordList(language);
case WalletType.litecoin:
return getBitcoinWordList(language);
case WalletType.monero:
return monero!.getMoneroWordList(language);
case WalletType.haven:
return haven!.getMoneroWordList(language);
case WalletType.ethereum:
return ethereum!.getEthereumWordList(language);
case WalletType.bitcoinCash:
return getBitcoinWordList(language);
case WalletType.nano:
case WalletType.banano:
return nano!.getNanoWordList(language);
case WalletType.polygon:
return polygon!.getPolygonWordList(language);
case WalletType.solana:
return solana!.getSolanaWordList(language);
case WalletType.tron:
return tron!.getTronWordList(language);
default:
return [];
}
}
static bool needsNormalization(String language) =>
["POLYSEED_French", "POLYSEED_Spanish"].contains(language);
static List<String> getBitcoinWordList(String language) {
assert(language.toLowerCase() == LanguageList.english.toLowerCase());
return bitcoin!.getWordList();
}
@override
bool isValid(MnemonicItem? value) => _words.contains(value?.text);
}