createWalletByImportedMnemonic method
Implementation
Future<Wallet> createWalletByImportedMnemonic({
required String mnemonic,
required String walletName,
String passphrase = '',
}) async {
final isAlreadyExist = (await walletRepository.readAll())
.firstWhereOrNull((element) => element.name == walletName) !=
null;
if (isAlreadyExist) {
throw Exception("This wallet Name is already exist");
}
final blockchainsData =
await blockchainService.createBlockchainsDataFromTheMnemonic(
mnemonic: mnemonic, passphrase: passphrase);
final id = int.tryParse(
(await walletRepository.readAll()).lastOrNull?.id ?? '-1')! +
1;
final wallet = Wallet(
id: id.toString(),
name: walletName,
mnemonic: mnemonic,
passphrase: passphrase,
blockchainsData: blockchainsData,
);
walletsStream.value.add(wallet);
walletsStream.add(walletsStream.value);
walletRepository.saveAll(walletsStream.value);
return wallet;
}