From 65686719eec27a1546571d0a5ef7c320fc52cbeb Mon Sep 17 00:00:00 2001 From: fosse Date: Fri, 9 Feb 2024 13:37:30 -0500 Subject: [PATCH] save --- cw_core/lib/currency_for_wallet_type.dart | 2 + cw_lightning/lib/lightning_wallet.dart | 42 +++++++++---------- lib/store/settings_store.dart | 2 + .../node_list/node_list_view_model.dart | 3 ++ lib/view_model/send/send_view_model.dart | 2 + .../wallet_address_list_view_model.dart | 5 +++ lib/view_model/wallet_keys_view_model.dart | 2 + lib/view_model/wallet_new_vm.dart | 3 ++ model_generator.sh | 1 + 9 files changed, 41 insertions(+), 21 deletions(-) diff --git a/cw_core/lib/currency_for_wallet_type.dart b/cw_core/lib/currency_for_wallet_type.dart index ce0219f1f..bcc34fd6f 100644 --- a/cw_core/lib/currency_for_wallet_type.dart +++ b/cw_core/lib/currency_for_wallet_type.dart @@ -5,6 +5,8 @@ CryptoCurrency currencyForWalletType(WalletType type) { switch (type) { case WalletType.bitcoin: return CryptoCurrency.btc; + case WalletType.lightning: + return CryptoCurrency.btc; case WalletType.monero: return CryptoCurrency.xmr; case WalletType.litecoin: diff --git a/cw_lightning/lib/lightning_wallet.dart b/cw_lightning/lib/lightning_wallet.dart index a9d71a85a..a2180cb0b 100644 --- a/cw_lightning/lib/lightning_wallet.dart +++ b/cw_lightning/lib/lightning_wallet.dart @@ -101,29 +101,29 @@ abstract class LightningWalletBase extends ElectrumWallet with Store { } Future setupBreeze(Uint8List seedBytes) async { - // Initialize SDK logs listener - final sdk = BreezSDK(); - sdk.initialize(); + // // Initialize SDK logs listener + // final sdk = BreezSDK(); + // sdk.initialize(); - NodeConfig breezNodeConfig = NodeConfig.greenlight( - config: GreenlightNodeConfig( - partnerCredentials: null, - inviteCode: secrets.breezInviteCode, - ), - ); - Config breezConfig = await sdk.defaultConfig( - envType: EnvironmentType.Production, - apiKey: secrets.breezApiKey, - nodeConfig: breezNodeConfig, - ); + // NodeConfig breezNodeConfig = NodeConfig.greenlight( + // config: GreenlightNodeConfig( + // partnerCredentials: null, + // inviteCode: secrets.breezInviteCode, + // ), + // ); + // Config breezConfig = await sdk.defaultConfig( + // envType: EnvironmentType.Production, + // apiKey: secrets.breezApiKey, + // nodeConfig: breezNodeConfig, + // ); - // Customize the config object according to your needs - String workingDir = (await getApplicationDocumentsDirectory()).path; - workingDir = "$workingDir/wallets/bitcoin/${walletInfo.name}/breez/"; - new Directory(workingDir).createSync(recursive: true); - breezConfig = breezConfig.copyWith(workingDir: workingDir); - await sdk.connect(config: breezConfig, seed: seedBytes); + // // Customize the config object according to your needs + // String workingDir = (await getApplicationDocumentsDirectory()).path; + // workingDir = "$workingDir/wallets/lightning/${walletInfo.name}/breez/"; + // new Directory(workingDir).createSync(recursive: true); + // breezConfig = breezConfig.copyWith(workingDir: workingDir); + // await sdk.connect(config: breezConfig, seed: seedBytes); - print("initialized: ${(await sdk.isInitialized())}"); + // print("initialized: ${(await sdk.isInitialized())}"); } } diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index 253adf3ea..e1add830e 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -873,6 +873,7 @@ abstract class SettingsStoreBase with Store { if (bitcoinElectrumServer != null) { nodes[WalletType.bitcoin] = bitcoinElectrumServer; + nodes[WalletType.lightning] = bitcoinElectrumServer; } if (litecoinElectrumServer != null) { @@ -1205,6 +1206,7 @@ abstract class SettingsStoreBase with Store { if (bitcoinElectrumServer != null) { nodes[WalletType.bitcoin] = bitcoinElectrumServer; + nodes[WalletType.lightning] = bitcoinElectrumServer; } if (litecoinElectrumServer != null) { diff --git a/lib/view_model/node_list/node_list_view_model.dart b/lib/view_model/node_list/node_list_view_model.dart index 0cd4d7491..29ab1ed37 100644 --- a/lib/view_model/node_list/node_list_view_model.dart +++ b/lib/view_model/node_list/node_list_view_model.dart @@ -54,6 +54,9 @@ abstract class NodeListViewModelBase with Store { case WalletType.bitcoin: node = getBitcoinDefaultElectrumServer(nodes: _nodeSource)!; break; + case WalletType.lightning: + node = getBitcoinDefaultElectrumServer(nodes: _nodeSource)!; + break; case WalletType.monero: node = getMoneroDefaultNode(nodes: _nodeSource); break; diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index 885e2efe0..254e52c0d 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -377,6 +377,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor case WalletType.polygon: return polygon!.createPolygonTransactionCredentials(outputs, priority: priority!, currency: selectedCryptoCurrency); + case WalletType.lightning: + throw Exception("TODO: CW-563 Implement lightning tx send!"); default: throw Exception('Unexpected wallet type: ${wallet.type}'); } diff --git a/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart b/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart index 9270d1d44..377e4173b 100644 --- a/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart +++ b/lib/view_model/wallet_address_list/wallet_address_list_view_model.dart @@ -237,6 +237,11 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo return BitcoinURI(amount: amount, address: address.address); } + if (wallet.type == WalletType.lightning) { + // TODO: CW-563 + return BitcoinURI(amount: amount, address: address.address); + } + if (wallet.type == WalletType.litecoin) { return LitecoinURI(amount: amount, address: address.address); } diff --git a/lib/view_model/wallet_keys_view_model.dart b/lib/view_model/wallet_keys_view_model.dart index f931fec19..2671f1623 100644 --- a/lib/view_model/wallet_keys_view_model.dart +++ b/lib/view_model/wallet_keys_view_model.dart @@ -165,6 +165,8 @@ abstract class WalletKeysViewModelBase with Store { return 'banano-wallet'; case WalletType.polygon: return 'polygon-wallet'; + case WalletType.lightning: + return 'lightning-wallet'; default: throw Exception('Unexpected wallet type: ${_appStore.wallet!.toString()}'); } diff --git a/lib/view_model/wallet_new_vm.dart b/lib/view_model/wallet_new_vm.dart index d4a0c4c00..4e3befc62 100644 --- a/lib/view_model/wallet_new_vm.dart +++ b/lib/view_model/wallet_new_vm.dart @@ -1,5 +1,6 @@ import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart'; +import 'package:cake_wallet/lightning/lightning.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/monero/monero.dart'; @@ -61,6 +62,8 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store { name: name, language: options!.first as String, isPolyseed: options.last as bool); case WalletType.bitcoin: return bitcoin!.createBitcoinNewWalletCredentials(name: name); + case WalletType.lightning: + return lightning!.createLightningNewWalletCredentials(name: name); case WalletType.litecoin: return bitcoin!.createBitcoinNewWalletCredentials(name: name); case WalletType.haven: diff --git a/model_generator.sh b/model_generator.sh index e7231f19a..1da57fb3b 100755 --- a/model_generator.sh +++ b/model_generator.sh @@ -5,4 +5,5 @@ cd cw_bitcoin && flutter pub get && flutter packages pub run build_runner build cd cw_haven && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs && cd .. cd cw_nano && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs && cd .. cd cw_bitcoin_cash && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs && cd .. +cd cw_lightning && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs && cd .. flutter packages pub run build_runner build --delete-conflicting-outputs \ No newline at end of file