diff --git a/cw_bitcoin/lib/bitcoin_wallet_service.dart b/cw_bitcoin/lib/bitcoin_wallet_service.dart index bfadaf2a3..8885fff21 100644 --- a/cw_bitcoin/lib/bitcoin_wallet_service.dart +++ b/cw_bitcoin/lib/bitcoin_wallet_service.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:cw_bitcoin/bitcoin_mnemonic.dart'; import 'package:cw_bitcoin/bitcoin_mnemonic_is_incorrect_exception.dart'; import 'package:cw_bitcoin/bitcoin_wallet_creation_credentials.dart'; +import 'package:cw_core/node.dart'; import 'package:cw_core/unspent_coins_info.dart'; import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_service.dart'; @@ -12,10 +13,8 @@ import 'package:cw_core/wallet_type.dart'; import 'package:hive/hive.dart'; import 'package:collection/collection.dart'; -class BitcoinWalletService extends WalletService< - BitcoinNewWalletCredentials, - BitcoinRestoreWalletFromSeedCredentials, - BitcoinRestoreWalletFromWIFCredentials> { +class BitcoinWalletService extends WalletService { BitcoinWalletService(this.walletInfoSource, this.unspentCoinsInfoSource); final Box walletInfoSource; @@ -42,10 +41,12 @@ class BitcoinWalletService extends WalletService< @override Future openWallet(String name, String password) async { - final walletInfo = walletInfoSource.values.firstWhereOrNull( - (info) => info.id == WalletBase.idFor(name, getType()))!; + final walletInfo = walletInfoSource.values + .firstWhereOrNull((info) => info.id == WalletBase.idFor(name, getType()))!; final wallet = await BitcoinWalletBase.open( - password: password, name: name, walletInfo: walletInfo, + password: password, + name: name, + walletInfo: walletInfo, unspentCoinsInfo: unspentCoinsInfoSource); await wallet.init(); return wallet; @@ -53,17 +54,16 @@ class BitcoinWalletService extends WalletService< @override Future remove(String wallet) async { - File(await pathForWalletDir(name: wallet, type: getType())) - .delete(recursive: true); - final walletInfo = walletInfoSource.values.firstWhereOrNull( - (info) => info.id == WalletBase.idFor(wallet, getType()))!; + File(await pathForWalletDir(name: wallet, type: getType())).delete(recursive: true); + final walletInfo = walletInfoSource.values + .firstWhereOrNull((info) => info.id == WalletBase.idFor(wallet, getType()))!; await walletInfoSource.delete(walletInfo.key); } @override Future rename(String currentName, String password, String newName) async { - final currentWalletInfo = walletInfoSource.values.firstWhereOrNull( - (info) => info.id == WalletBase.idFor(currentName, getType()))!; + final currentWalletInfo = walletInfoSource.values + .firstWhereOrNull((info) => info.id == WalletBase.idFor(currentName, getType()))!; final currentWallet = await BitcoinWalletBase.open( password: password, name: currentName, @@ -80,13 +80,11 @@ class BitcoinWalletService extends WalletService< } @override - Future restoreFromKeys( - BitcoinRestoreWalletFromWIFCredentials credentials) async => + Future restoreFromKeys(BitcoinRestoreWalletFromWIFCredentials credentials) async => throw UnimplementedError(); @override - Future restoreFromSeed( - BitcoinRestoreWalletFromSeedCredentials credentials) async { + Future restoreFromSeed(BitcoinRestoreWalletFromSeedCredentials credentials) async { if (!validateMnemonic(credentials.mnemonic)) { throw BitcoinMnemonicIsIncorrectException(); } @@ -100,4 +98,13 @@ class BitcoinWalletService extends WalletService< await wallet.init(); return wallet; } + + static Future> compareDerivationMethods( + {required mnemonic, required Node node}) async { + return [DerivationType.bip39, DerivationType.StandardBIP44Legacy]; + } + + static Future getInfoFromSeed() { + throw UnimplementedError(); + } } diff --git a/cw_core/lib/wallet_info.dart b/cw_core/lib/wallet_info.dart index 5662c41e3..3daf42b3e 100644 --- a/cw_core/lib/wallet_info.dart +++ b/cw_core/lib/wallet_info.dart @@ -15,6 +15,8 @@ enum DerivationType { nano, @HiveField(3) bip39, + @HiveField(4) + StandardBIP44Legacy } @HiveType(typeId: WalletInfo.typeId) diff --git a/lib/view_model/wallet_restore_choose_derivation_view_model.dart b/lib/view_model/wallet_restore_choose_derivation_view_model.dart index 7783ea2cb..d62cc6e8a 100644 --- a/lib/view_model/wallet_restore_choose_derivation_view_model.dart +++ b/lib/view_model/wallet_restore_choose_derivation_view_model.dart @@ -37,6 +37,29 @@ abstract class WalletRestoreChooseDerivationViewModelBase with Store { var appStore = getIt.get(); var node = appStore.settingsStore.getCurrentNode(walletType); switch (walletType) { + case WalletType.bitcoin: + String? mnemonic = credentials['seed'] as String?; + // var bip39Info = await BitcoinWalletService.getInfoFromSeedOrMnemonic(DerivationType.bip39, + // mnemonic: mnemonic, seedKey: seedKey, node: node); + // var standardInfo = await NanoWalletService.getInfoFromSeedOrMnemonic( + // DerivationType.nano, + // mnemonic: mnemonic, + // seedKey: seedKey, + // node: node, + // ); + + // if (bip39Info["balance"] != null) { + // list.add(Derivation( + // NanoUtil.getRawAsUsableString(bip39Info["balance"] as String, NanoUtil.rawPerNano), + // bip39Info["address"] as String, + // DerivationType.bip39, + // int.tryParse( + // bip39Info["confirmation_height"] as String? ?? "", + // ) ?? + // 0, + // )); + // } + break; case WalletType.nano: String? mnemonic = credentials['seed'] as String?; String? seedKey = credentials['seedKey'] as String?; diff --git a/lib/view_model/wallet_restore_view_model.dart b/lib/view_model/wallet_restore_view_model.dart index e306c8140..3983a033b 100644 --- a/lib/view_model/wallet_restore_view_model.dart +++ b/lib/view_model/wallet_restore_view_model.dart @@ -2,6 +2,7 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart'; import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/nano/nano.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; +import 'package:cw_bitcoin/bitcoin_wallet_service.dart'; import 'package:cw_nano/nano_wallet.dart'; import 'package:cw_nano/nano_wallet_service.dart'; import 'package:hive/hive.dart'; @@ -143,9 +144,8 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { var node = appStore.settingsStore.getCurrentNode(walletType); switch (type) { - // case WalletType.bitcoin: - // return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials( - // name: name, mnemonic: seed, password: password); + case WalletType.bitcoin: + return BitcoinWalletService.compareDerivationMethods(mnemonic: mnemonic, node: node); // case WalletType.litecoin: // return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials( // name: name, mnemonic: seed, password: password);