diff --git a/cw_bitcoin/lib/bitcoin_wallet.dart b/cw_bitcoin/lib/bitcoin_wallet.dart index 9cdb78f2d..ebbc806aa 100644 --- a/cw_bitcoin/lib/bitcoin_wallet.dart +++ b/cw_bitcoin/lib/bitcoin_wallet.dart @@ -1,3 +1,5 @@ +import 'package:breez_sdk/breez_sdk.dart'; +import 'package:breez_sdk/bridge_generated.dart'; import 'package:cw_bitcoin/bitcoin_mnemonic.dart'; import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/unspent_coins_info.dart'; @@ -37,31 +39,51 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { initialBalance: initialBalance, seedBytes: seedBytes, currency: CryptoCurrency.btc) { - walletAddresses = BitcoinWalletAddresses( - walletInfo, + walletAddresses = BitcoinWalletAddresses(walletInfo, electrumClient: electrumClient, initialAddresses: initialAddresses, initialRegularAddressIndex: initialRegularAddressIndex, initialChangeAddressIndex: initialChangeAddressIndex, mainHd: hd, - sideHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType) - .derivePath("m/0'/1"), + sideHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType).derivePath("m/0'/1"), networkType: networkType); + + // initialize breeze: + String inviteCode = ""; + String apiKey = ""; + NodeConfig breezNodeConfig = NodeConfig.greenlight( + config: GreenlightNodeConfig( + partnerCredentials: null, + inviteCode: inviteCode, + ), + ); + BreezSDK() + .defaultConfig( + envType: EnvironmentType.Production, + apiKey: apiKey, + nodeConfig: breezNodeConfig, + ) + .then((value) { + Config breezConfig = value; + // Customize the config object according to your needs + breezConfig = breezConfig.copyWith(workingDir: "/breez/${walletInfo.name}"); + BreezSDK().connect(config: breezConfig, seed: seedBytes); + }); + autorun((_) { this.walletAddresses.isEnabledAutoGenerateSubaddress = this.isEnabledAutoGenerateSubaddress; }); } - static Future create({ - required String mnemonic, - required String password, - required WalletInfo walletInfo, - required Box unspentCoinsInfo, - List? initialAddresses, - ElectrumBalance? initialBalance, - int initialRegularAddressIndex = 0, - int initialChangeAddressIndex = 0 - }) async { + static Future create( + {required String mnemonic, + required String password, + required WalletInfo walletInfo, + required Box unspentCoinsInfo, + List? initialAddresses, + ElectrumBalance? initialBalance, + int initialRegularAddressIndex = 0, + int initialChangeAddressIndex = 0}) async { return BitcoinWallet( mnemonic: mnemonic, password: password, @@ -92,4 +114,4 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { initialRegularAddressIndex: snp.regularAddressIndex, initialChangeAddressIndex: snp.changeAddressIndex); } -} \ No newline at end of file +} diff --git a/cw_bitcoin/lib/bitcoin_wallet_service.dart b/cw_bitcoin/lib/bitcoin_wallet_service.dart index 3a97e0682..dbd7cb1d5 100644 --- a/cw_bitcoin/lib/bitcoin_wallet_service.dart +++ b/cw_bitcoin/lib/bitcoin_wallet_service.dart @@ -11,6 +11,7 @@ import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:hive/hive.dart'; import 'package:collection/collection.dart'; +import 'package:breez_sdk/breez_sdk.dart'; class BitcoinWalletService extends WalletService< BitcoinNewWalletCredentials, @@ -44,6 +45,10 @@ class BitcoinWalletService extends WalletService< Future openWallet(String name, String password) async { final walletInfo = walletInfoSource.values.firstWhereOrNull( (info) => info.id == WalletBase.idFor(name, getType()))!; + + // Initialize SDK logs listener + BreezSDK().initialize(); + final wallet = await BitcoinWalletBase.open( password: password, name: name, walletInfo: walletInfo, unspentCoinsInfo: unspentCoinsInfoSource); diff --git a/cw_bitcoin/pubspec.yaml b/cw_bitcoin/pubspec.yaml index a50ff68ad..6901db722 100644 --- a/cw_bitcoin/pubspec.yaml +++ b/cw_bitcoin/pubspec.yaml @@ -27,6 +27,9 @@ dependencies: git: url: https://github.com/cake-tech/bitbox-flutter.git ref: master + breez_sdk: + git: + url: https://github.com/breez/breez-sdk-flutter.git rxdart: ^0.27.5 unorm_dart: ^0.2.0 cryptography: ^2.0.5 @@ -37,7 +40,7 @@ dev_dependencies: build_runner: ^2.1.11 build_resolvers: ^2.0.9 mobx_codegen: ^2.0.7 - hive_generator: ^1.1.3 + hive_generator: ^2.0.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/cw_bitcoin_cash/pubspec.yaml b/cw_bitcoin_cash/pubspec.yaml index 49a5efb15..44e5eecbb 100644 --- a/cw_bitcoin_cash/pubspec.yaml +++ b/cw_bitcoin_cash/pubspec.yaml @@ -38,7 +38,7 @@ dev_dependencies: sdk: flutter build_runner: ^2.1.11 mobx_codegen: ^2.0.7 - hive_generator: ^1.1.3 + hive_generator: ^2.0.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/cw_evm/pubspec.yaml b/cw_evm/pubspec.yaml index c202cc72a..3b8e69369 100644 --- a/cw_evm/pubspec.yaml +++ b/cw_evm/pubspec.yaml @@ -29,7 +29,7 @@ dev_dependencies: sdk: flutter build_runner: ^2.1.11 mobx_codegen: ^2.0.7 - hive_generator: ^1.1.3 + hive_generator: ^2.0.1 flutter_lints: ^2.0.0 flutter: diff --git a/cw_haven/pubspec.yaml b/cw_haven/pubspec.yaml index c215ab779..bf0ebfa19 100644 --- a/cw_haven/pubspec.yaml +++ b/cw_haven/pubspec.yaml @@ -27,7 +27,7 @@ dev_dependencies: build_runner: ^2.1.11 mobx_codegen: ^2.0.7 build_resolvers: ^2.0.9 - hive_generator: ^1.1.3 + hive_generator: ^2.0.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/cw_monero/pubspec.yaml b/cw_monero/pubspec.yaml index a6fe7f967..201653617 100644 --- a/cw_monero/pubspec.yaml +++ b/cw_monero/pubspec.yaml @@ -29,7 +29,7 @@ dev_dependencies: build_runner: ^2.1.11 build_resolvers: ^2.0.9 mobx_codegen: ^2.0.7 - hive_generator: ^1.1.3 + hive_generator: ^2.0.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/cw_nano/pubspec.yaml b/cw_nano/pubspec.yaml index a4b8732fd..de7fcadbe 100644 --- a/cw_nano/pubspec.yaml +++ b/cw_nano/pubspec.yaml @@ -34,7 +34,7 @@ dev_dependencies: sdk: flutter build_runner: ^2.1.11 mobx_codegen: ^2.0.7 - hive_generator: ^1.1.3 + hive_generator: ^2.0.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/lib/main.dart b/lib/main.dart index 306b109a0..213ce0cc4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -41,6 +41,8 @@ import 'package:uni_links/uni_links.dart'; import 'package:cw_core/unspent_coins_info.dart'; import 'package:cake_wallet/monero/monero.dart'; import 'package:cw_core/cake_hive.dart'; +import 'package:breez_sdk/breez_sdk.dart'; +import 'package:breez_sdk/bridge_generated.dart'; final navigatorKey = GlobalKey(); final rootKey = GlobalKey(); @@ -64,6 +66,11 @@ Future main() async { await initializeAppConfigs(); + // breez: + // BreezDateUtils.setupLocales(); + // BreezLogger(); + + runApp(App()); }, (error, stackTrace) async { ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stackTrace)); diff --git a/lib/src/screens/dashboard/pages/address_page.dart b/lib/src/screens/dashboard/pages/address_page.dart index b4460edc9..01e960273 100644 --- a/lib/src/screens/dashboard/pages/address_page.dart +++ b/lib/src/screens/dashboard/pages/address_page.dart @@ -1,3 +1,5 @@ +import 'package:breez_sdk/breez_sdk.dart'; +import 'package:breez_sdk/bridge_generated.dart'; import 'package:cake_wallet/src/screens/new_wallet/widgets/select_button.dart'; import 'package:cake_wallet/themes/extensions/keyboard_theme.dart'; import 'package:cake_wallet/di.dart'; @@ -69,7 +71,7 @@ class AddressPage extends BasePage { size: 16, ); final _closeButton = - currentTheme.type == ThemeType.dark ? closeButtonImageDarkTheme : closeButtonImage; + currentTheme.type == ThemeType.dark ? closeButtonImageDarkTheme : closeButtonImage; bool isMobileView = responsiveLayoutUtil.shouldRenderMobileUI; @@ -158,16 +160,52 @@ class AddressPage extends BasePage { isLight: dashboardViewModel.settingsStore.currentTheme.type == ThemeType.light))), SizedBox(height: 16), + IconButton( + padding: EdgeInsets.zero, + constraints: BoxConstraints(), + highlightColor: Colors.transparent, + splashColor: Colors.transparent, + iconSize: 25, + onPressed: () async { + // ReceivePaymentRequest req = const ReceivePaymentRequest( + // amountMsat: 3000000, + // description: "Invoice for 3000 sats", + // ); + // ReceivePaymentResponse receivePaymentResponse = + // await BreezSDK().receivePayment(req: req); + + // print(receivePaymentResponse.lnInvoice); + + ServiceHealthCheckResponse healthCheck = await BreezSDK().serviceHealthCheck(); + print("Current service status is: ${healthCheck.status}"); + + ReceiveOnchainRequest req = const ReceiveOnchainRequest(); + SwapInfo swapInfo = await BreezSDK().receiveOnchain(req: req); + +// Send your funds to the below bitcoin address + String address = swapInfo.bitcoinAddress; + print(address); + print("Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}"); + print("Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}"); + }, + icon: Icon( + Icons.lightbulb_outline_rounded, + size: 48, + color: pageIconColor(context), + ), + ), + SizedBox( + height: 40, + ), Observer(builder: (_) { if (addressListViewModel.hasAddressList) { return SelectButton( text: addressListViewModel.buttonTitle, onTap: () async => dashboardViewModel.isAutoGenerateSubaddressesEnabled && - (WalletType.monero == addressListViewModel.wallet.type || - WalletType.haven == addressListViewModel.wallet.type) + (WalletType.monero == addressListViewModel.wallet.type || + WalletType.haven == addressListViewModel.wallet.type) ? await showPopUp( - context: context, - builder: (_) => getIt.get()) + context: context, builder: (_) => getIt.get()) : Navigator.of(context).pushNamed(Routes.receive), textColor: Theme.of(context).extension()!.textColor, color: Theme.of(context).extension()!.syncedBackgroundColor,