diff --git a/cw_lightning/lib/lightning_wallet.dart b/cw_lightning/lib/lightning_wallet.dart index a2180cb0b..cb61db204 100644 --- a/cw_lightning/lib/lightning_wallet.dart +++ b/cw_lightning/lib/lightning_wallet.dart @@ -53,7 +53,11 @@ abstract class LightningWalletBase extends ElectrumWallet with Store { networkType: networkType); // initialize breeze: - setupBreeze(seedBytes); + try { + setupBreez(seedBytes); + } catch (e) { + print("Error initializing Breez: $e"); + } autorun((_) { this.walletAddresses.isEnabledAutoGenerateSubaddress = this.isEnabledAutoGenerateSubaddress; @@ -100,30 +104,30 @@ abstract class LightningWalletBase extends ElectrumWallet with Store { initialChangeAddressIndex: snp.changeAddressIndex); } - Future setupBreeze(Uint8List seedBytes) async { - // // Initialize SDK logs listener - // final sdk = BreezSDK(); - // sdk.initialize(); + Future setupBreez(Uint8List seedBytes) async { + // 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, - // ); - - // // 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); + NodeConfig breezNodeConfig = NodeConfig.greenlight( + config: GreenlightNodeConfig( + partnerCredentials: null, + inviteCode: secrets.breezInviteCode, + ), + ); + Config breezConfig = await sdk.defaultConfig( + envType: EnvironmentType.Production, + apiKey: secrets.breezApiKey, + nodeConfig: breezNodeConfig, + ); - // print("initialized: ${(await sdk.isInitialized())}"); + // 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())}"); } } diff --git a/cw_lightning/lib/lightning_wallet_service.dart b/cw_lightning/lib/lightning_wallet_service.dart index 2951ef291..9a46413dc 100644 --- a/cw_lightning/lib/lightning_wallet_service.dart +++ b/cw_lightning/lib/lightning_wallet_service.dart @@ -12,10 +12,8 @@ import 'package:cw_lightning/lightning_wallet.dart'; import 'package:hive/hive.dart'; import 'package:collection/collection.dart'; -class LightningWalletService extends WalletService< - BitcoinNewWalletCredentials, - BitcoinRestoreWalletFromSeedCredentials, - BitcoinRestoreWalletFromWIFCredentials> { +class LightningWalletService extends WalletService { LightningWalletService(this.walletInfoSource, this.unspentCoinsInfoSource); final Box walletInfoSource; @@ -42,29 +40,41 @@ class LightningWalletService extends WalletService< @override Future openWallet(String name, String password) async { - final walletInfo = walletInfoSource.values.firstWhereOrNull( - (info) => info.id == WalletBase.idFor(name, getType()))!; - - final wallet = await LightningWalletBase.open( - password: password, name: name, walletInfo: walletInfo, - unspentCoinsInfo: unspentCoinsInfoSource); - await wallet.init(); - return wallet; + final walletInfo = walletInfoSource.values + .firstWhereOrNull((info) => info.id == WalletBase.idFor(name, getType()))!; + try { + final wallet = await LightningWalletBase.open( + password: password, + name: name, + walletInfo: walletInfo, + unspentCoinsInfo: unspentCoinsInfoSource); + await wallet.init(); + saveBackup(name); + return wallet; + } catch (_) { + await restoreWalletFilesFromBackup(name); + final wallet = await LightningWalletBase.open( + password: password, + name: name, + walletInfo: walletInfo, + unspentCoinsInfo: unspentCoinsInfoSource); + await wallet.init(); + return wallet; + } } @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 LightningWalletBase.open( password: password, name: currentName, @@ -72,6 +82,7 @@ class LightningWalletService extends WalletService< unspentCoinsInfo: unspentCoinsInfoSource); await currentWallet.renameWalletFiles(newName); + await saveBackup(newName); final newWalletInfo = currentWalletInfo; newWalletInfo.id = WalletBase.idFor(newName, getType()); @@ -81,13 +92,11 @@ class LightningWalletService 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(); } @@ -101,4 +110,4 @@ class LightningWalletService extends WalletService< await wallet.init(); return wallet; } -} \ No newline at end of file +} diff --git a/lib/core/seed_validator.dart b/lib/core/seed_validator.dart index 8f65159e1..c77bfc08a 100644 --- a/lib/core/seed_validator.dart +++ b/lib/core/seed_validator.dart @@ -21,7 +21,7 @@ class SeedValidator extends Validator { static List getWordList({required WalletType type, required String language}) { switch (type) { case WalletType.bitcoin: - return getBitcoinWordList(language); + case WalletType.lightning: case WalletType.litecoin: return getBitcoinWordList(language); case WalletType.monero: diff --git a/lib/entities/main_actions.dart b/lib/entities/main_actions.dart index c1dd71cc9..88e070625 100644 --- a/lib/entities/main_actions.dart +++ b/lib/entities/main_actions.dart @@ -3,6 +3,7 @@ import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/src/widgets/alert_with_one_action.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; +import 'package:cw_core/wallet_type.dart'; import 'package:flutter/material.dart'; class MainActions { @@ -11,8 +12,7 @@ class MainActions { final bool Function(DashboardViewModel viewModel)? isEnabled; final bool Function(DashboardViewModel viewModel)? canShow; - final Future Function( - BuildContext context, DashboardViewModel viewModel) onTap; + final Future Function(BuildContext context, DashboardViewModel viewModel) onTap; MainActions._({ required this.name, @@ -55,6 +55,10 @@ class MainActions { name: (context) => S.of(context).receive, image: 'assets/images/received.png', onTap: (BuildContext context, DashboardViewModel viewModel) async { + if (viewModel.wallet.type == WalletType.lightning) { + Navigator.pushNamed(context, Routes.lightningReceive); + return; + } Navigator.pushNamed(context, Routes.addressPage); }, ); @@ -75,6 +79,10 @@ class MainActions { name: (context) => S.of(context).send, image: 'assets/images/upload.png', onTap: (BuildContext context, DashboardViewModel viewModel) async { + if (viewModel.wallet.type == WalletType.lightning) { + Navigator.pushNamed(context, Routes.lightningSend); + return; + } Navigator.pushNamed(context, Routes.send); }, ); @@ -114,4 +122,4 @@ class MainActions { }, ); } -} \ No newline at end of file +} diff --git a/lib/reactions/on_current_wallet_change.dart b/lib/reactions/on_current_wallet_change.dart index ade9927ff..1ae1e4fd0 100644 --- a/lib/reactions/on_current_wallet_change.dart +++ b/lib/reactions/on_current_wallet_change.dart @@ -68,8 +68,11 @@ void startCurrentWalletChangeReaction( .get() .setInt(PreferencesKey.currentWalletType, serializeToInt(wallet.type)); - if (wallet.type == WalletType.monero || wallet.type == WalletType.bitcoin || - wallet.type == WalletType.litecoin || wallet.type == WalletType.bitcoinCash ) { + if (wallet.type == WalletType.monero || + wallet.type == WalletType.bitcoin || + wallet.type == WalletType.litecoin || + wallet.type == WalletType.bitcoinCash || + wallet.type == WalletType.lightning) { _setAutoGenerateSubaddressStatus(wallet, settingsStore); } diff --git a/lib/router.dart b/lib/router.dart index b7b7c9a8e..5fdb48f99 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -634,6 +634,18 @@ Route createRoute(RouteSettings settings) { case Routes.torPage: return MaterialPageRoute(builder: (_) => getIt.get()); + case Routes.lightningSend: + return CupertinoPageRoute( + fullscreenDialog: true, builder: (_) => getIt.get()); + + case Routes.lightningReceive: + return CupertinoPageRoute( + fullscreenDialog: true, builder: (_) => getIt.get()); + + case Routes.lightningSettings: + return CupertinoPageRoute( + fullscreenDialog: true, builder: (_) => getIt.get()); + default: return MaterialPageRoute( builder: (_) => Scaffold( diff --git a/lib/routes.dart b/lib/routes.dart index 7ad5c70bc..01b8f2f82 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -106,4 +106,7 @@ class Routes { static const nftDetailsPage = '/nft_details_page'; static const importNFTPage = '/import_nft_page'; static const torPage = '/tor_page'; + static const lightningSend = '/lightning_send'; + static const lightningReceive = '/lightning_receive'; + static const lightningSettings = '/lightning_settings'; } diff --git a/lib/src/screens/dashboard/widgets/menu_widget.dart b/lib/src/screens/dashboard/widgets/menu_widget.dart index ed9b823ad..f9a95cbe5 100644 --- a/lib/src/screens/dashboard/widgets/menu_widget.dart +++ b/lib/src/screens/dashboard/widgets/menu_widget.dart @@ -27,6 +27,7 @@ class MenuWidgetState extends State { this.fromBottomEdge = 25, this.moneroIcon = Image.asset('assets/images/monero_menu.png'), this.bitcoinIcon = Image.asset('assets/images/bitcoin_menu.png'), + this.lightningIcon = Image.asset('assets/images/bitcoin_menu.png'), this.litecoinIcon = Image.asset('assets/images/litecoin_menu.png'), this.havenIcon = Image.asset('assets/images/haven_menu.png'), this.ethereumIcon = Image.asset('assets/images/eth_icon.png'), @@ -49,6 +50,7 @@ class MenuWidgetState extends State { Image moneroIcon; Image bitcoinIcon; + Image lightningIcon; Image litecoinIcon; Image havenIcon; Image ethereumIcon; @@ -98,6 +100,8 @@ class MenuWidgetState extends State { color: Theme.of(context).extension()!.iconColor); bitcoinIcon = Image.asset('assets/images/bitcoin_menu.png', color: Theme.of(context).extension()!.iconColor); + lightningIcon = Image.asset('assets/images/bitcoin_menu.png', + color: Theme.of(context).extension()!.iconColor); return Row( mainAxisSize: MainAxisSize.max, @@ -210,6 +214,8 @@ class MenuWidgetState extends State { return moneroIcon; case WalletType.bitcoin: return bitcoinIcon; + case WalletType.lightning: + return lightningIcon; case WalletType.litecoin: return litecoinIcon; case WalletType.haven: diff --git a/lib/src/screens/receive/lightning_receive_page.dart b/lib/src/screens/receive/lightning_receive_page.dart new file mode 100644 index 000000000..a80f6f88c --- /dev/null +++ b/lib/src/screens/receive/lightning_receive_page.dart @@ -0,0 +1,244 @@ +import 'package:cake_wallet/src/screens/nano_accounts/nano_account_list_page.dart'; +import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; +import 'package:cake_wallet/themes/extensions/balance_page_theme.dart'; +import 'package:cake_wallet/themes/extensions/keyboard_theme.dart'; +import 'package:cake_wallet/themes/extensions/receive_page_theme.dart'; +import 'package:cake_wallet/src/widgets/gradient_background.dart'; +import 'package:cake_wallet/src/widgets/section_divider.dart'; +import 'package:cake_wallet/themes/theme_base.dart'; +import 'package:cake_wallet/utils/share_util.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; +import 'package:cw_core/wallet_type.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_mobx/flutter_mobx.dart'; +import 'package:cake_wallet/routes.dart'; +import 'package:cake_wallet/generated/i18n.dart'; +import 'package:cake_wallet/di.dart'; +import 'package:cake_wallet/src/screens/base_page.dart'; +import 'package:cake_wallet/src/screens/monero_accounts/monero_account_list_page.dart'; +import 'package:cake_wallet/src/screens/receive/widgets/header_tile.dart'; +import 'package:cake_wallet/src/screens/receive/widgets/address_cell.dart'; +import 'package:cake_wallet/view_model/wallet_address_list/wallet_account_list_header.dart'; +import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_header.dart'; +import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_item.dart'; +import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart'; +import 'package:cake_wallet/src/screens/receive/widgets/qr_widget.dart'; +import 'package:keyboard_actions/keyboard_actions.dart'; + +class LightningReceivePage extends BasePage { + LightningReceivePage({required this.addressListViewModel}) + : _cryptoAmountFocus = FocusNode(), + _amountController = TextEditingController(), + _formKey = GlobalKey() { + _amountController.addListener(() { + if (_formKey.currentState!.validate()) { + addressListViewModel.changeAmount(_amountController.text); + } + }); + } + + final WalletAddressListViewModel addressListViewModel; + final TextEditingController _amountController; + final GlobalKey _formKey; + static const _heroTag = 'receive_page'; + + @override + String get title => S.current.receive; + + @override + bool get gradientBackground => true; + + @override + bool get resizeToAvoidBottomInset => true; + + final FocusNode _cryptoAmountFocus; + + @override + Widget middle(BuildContext context) { + return Text( + title, + style: TextStyle( + fontSize: 18.0, + fontWeight: FontWeight.bold, + fontFamily: 'Lato', + color: pageIconColor(context)), + ); + } + + @override + Widget Function(BuildContext, Widget) get rootWrapper => + (BuildContext context, Widget scaffold) => + GradientBackground(scaffold: scaffold); + + @override + Widget trailing(BuildContext context) { + return Material( + color: Colors.transparent, + child: Semantics( + label: S.of(context).share, + child: IconButton( + padding: EdgeInsets.zero, + constraints: BoxConstraints(), + highlightColor: Colors.transparent, + splashColor: Colors.transparent, + iconSize: 25, + onPressed: () { + ShareUtil.share( + text: addressListViewModel.uri.toString(), + context: context, + ); + }, + icon: Icon( + Icons.share, + size: 20, + color: pageIconColor(context), + ), + ), + )); + } + + @override + Widget body(BuildContext context) { + final isElectrumWallet = addressListViewModel.isElectrumWallet; + return (addressListViewModel.type == WalletType.monero || + addressListViewModel.type == WalletType.haven || + addressListViewModel.type == WalletType.nano || + isElectrumWallet) + ? KeyboardActions( + config: KeyboardActionsConfig( + keyboardActionsPlatform: KeyboardActionsPlatform.IOS, + keyboardBarColor: Theme.of(context).extension()!.keyboardBarColor, + nextFocus: false, + actions: [ + KeyboardActionsItem( + focusNode: _cryptoAmountFocus, + toolbarButtons: [(_) => KeyboardDoneButton()], + ) + ]), + child: SingleChildScrollView( + child: Column( + children: [ + Padding( + padding: EdgeInsets.fromLTRB(24, 50, 24, 24), + child: QRWidget( + addressListViewModel: addressListViewModel, + formKey: _formKey, + heroTag: _heroTag, + amountTextFieldFocusNode: _cryptoAmountFocus, + amountController: _amountController, + isLight: currentTheme.type == ThemeType.light), + ), + Observer( + builder: (_) => ListView.separated( + padding: EdgeInsets.all(0), + separatorBuilder: (context, _) => const HorizontalSectionDivider(), + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemCount: addressListViewModel.items.length, + itemBuilder: (context, index) { + final item = addressListViewModel.items[index]; + Widget cell = Container(); + + if (item is WalletAccountListHeader) { + cell = HeaderTile( + showTrailingButton: true, + walletAddressListViewModel: addressListViewModel, + trailingButtonTap: () async { + if (addressListViewModel.type == WalletType.monero || + addressListViewModel.type == WalletType.haven) { + await showPopUp( + context: context, + builder: (_) => getIt.get()); + } else { + await showPopUp( + context: context, + builder: (_) => getIt.get()); + } + }, + title: S.of(context).accounts, + trailingIcon: Icon( + Icons.arrow_forward_ios, + size: 14, + color: Theme.of(context).extension()!.iconsColor, + )); + } + + if (item is WalletAddressListHeader) { + cell = HeaderTile( + title: S.of(context).addresses, + walletAddressListViewModel: addressListViewModel, + showTrailingButton: !addressListViewModel.isAutoGenerateSubaddressEnabled, + showSearchButton: true, + trailingButtonTap: () => + Navigator.of(context).pushNamed(Routes.newSubaddress), + trailingIcon: Icon( + Icons.add, + size: 20, + color: Theme.of(context) + .extension()! + .iconsColor, + )); + } + + if (item is WalletAddressListItem) { + cell = Observer(builder: (_) { + final isCurrent = + item.address == addressListViewModel.address.address; + final backgroundColor = isCurrent + ? Theme.of(context).extension()!.currentTileBackgroundColor + : Theme.of(context).extension()!.tilesBackgroundColor; + final textColor = isCurrent + ? Theme.of(context).extension()!.currentTileTextColor + : Theme.of(context).extension()!.tilesTextColor; + + return AddressCell.fromItem(item, + isCurrent: isCurrent, + hasBalance: addressListViewModel.isElectrumWallet, + backgroundColor: backgroundColor, + textColor: textColor, + onTap: (_) => addressListViewModel.setAddress(item), + onEdit: () => Navigator.of(context) + .pushNamed(Routes.newSubaddress, arguments: item)); + }); + } + + return index != 0 + ? cell + : ClipRRect( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(30), + topRight: Radius.circular(30)), + child: cell, + ); + })), + ], + ), + )) + : Padding( + padding: EdgeInsets.fromLTRB(24, 24, 24, 32), + child: Column( + children: [ + Expanded( + flex: 7, + child: QRWidget( + formKey: _formKey, + heroTag: _heroTag, + addressListViewModel: addressListViewModel, + amountTextFieldFocusNode: _cryptoAmountFocus, + amountController: _amountController, + isLight: currentTheme.type == ThemeType.light), + ), + Expanded( + flex: 2, + child: SizedBox(), + ), + Text(S.of(context).electrum_address_disclaimer, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 15, + color: Theme.of(context).extension()!.labelTextColor)), + ], + ), + ); + } +} diff --git a/lib/src/screens/wallet_list/wallet_list_page.dart b/lib/src/screens/wallet_list/wallet_list_page.dart index 717bb0a94..c0b45cc61 100644 --- a/lib/src/screens/wallet_list/wallet_list_page.dart +++ b/lib/src/screens/wallet_list/wallet_list_page.dart @@ -96,6 +96,7 @@ class WalletListBody extends StatefulWidget { class WalletListBodyState extends State { final moneroIcon = Image.asset('assets/images/monero_logo.png', height: 24, width: 24); final bitcoinIcon = Image.asset('assets/images/bitcoin.png', height: 24, width: 24); + final lightningIcon = Image.asset('assets/images/bitcoin.png', height: 24, width: 24); final litecoinIcon = Image.asset('assets/images/litecoin_icon.png', height: 24, width: 24); final nonWalletTypeIcon = Image.asset('assets/images/close.png', height: 24, width: 24); final havenIcon = Image.asset('assets/images/haven_logo.png', height: 24, width: 24); @@ -299,6 +300,8 @@ class WalletListBodyState extends State { switch (type) { case WalletType.bitcoin: return bitcoinIcon; + case WalletType.lightning: + return lightningIcon; case WalletType.monero: return moneroIcon; case WalletType.litecoin: diff --git a/lib/view_model/dashboard/transaction_list_item.dart b/lib/view_model/dashboard/transaction_list_item.dart index d8c4776b7..18f55b3e5 100644 --- a/lib/view_model/dashboard/transaction_list_item.dart +++ b/lib/view_model/dashboard/transaction_list_item.dart @@ -72,6 +72,7 @@ class TransactionListItem extends ActionListItem with Keyable { price: price); break; case WalletType.bitcoin: + case WalletType.lightning: case WalletType.litecoin: case WalletType.bitcoinCash: amount = calculateFiatAmountRaw( diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index afe617803..e5e68f9e4 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -264,6 +264,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with bool get hasAllAmount => (wallet.type == WalletType.bitcoin || + wallet.type == WalletType.lightning || wallet.type == WalletType.litecoin || wallet.type == WalletType.bitcoinCash) && depositCurrency == wallet.currency; diff --git a/lib/view_model/restore/restore_from_qr_vm.dart b/lib/view_model/restore/restore_from_qr_vm.dart index c8637c4be..59297dfe9 100644 --- a/lib/view_model/restore/restore_from_qr_vm.dart +++ b/lib/view_model/restore/restore_from_qr_vm.dart @@ -66,6 +66,7 @@ abstract class WalletRestorationFromQRVMBase extends WalletCreationVM with Store spendKey: restoreWallet.spendKey ?? '', height: restoreWallet.height ?? 0); case WalletType.bitcoin: + case WalletType.lightning: case WalletType.litecoin: return bitcoin!.createBitcoinRestoreWalletFromWIFCredentials( name: name, password: password, wif: wif); diff --git a/lib/view_model/restore/wallet_restore_from_qr_code.dart b/lib/view_model/restore/wallet_restore_from_qr_code.dart index bfc9b7980..547ebe7a6 100644 --- a/lib/view_model/restore/wallet_restore_from_qr_code.dart +++ b/lib/view_model/restore/wallet_restore_from_qr_code.dart @@ -22,6 +22,9 @@ class WalletRestoreFromQRCode { 'bitcoin': WalletType.bitcoin, 'bitcoin-wallet': WalletType.bitcoin, 'bitcoin_wallet': WalletType.bitcoin, + 'lightning': WalletType.lightning, + 'lightning-wallet': WalletType.lightning, + 'lightning_wallet': WalletType.lightning, 'litecoin': WalletType.litecoin, 'litecoin-wallet': WalletType.litecoin, 'litecoin_wallet': WalletType.litecoin, diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart index a3bf281ca..8117bb9c0 100644 --- a/lib/view_model/transaction_details_view_model.dart +++ b/lib/view_model/transaction_details_view_model.dart @@ -141,6 +141,7 @@ abstract class TransactionDetailsViewModelBase with Store { case WalletType.monero: return S.current.view_transaction_on + 'Monero.com'; case WalletType.bitcoin: + case WalletType.lightning: return S.current.view_transaction_on + 'mempool.space'; case WalletType.litecoin: case WalletType.bitcoinCash: diff --git a/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart b/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart index 6380bb07e..1ce2cdb14 100644 --- a/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart +++ b/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart @@ -58,7 +58,7 @@ abstract class UnspentCoinsListViewModelBase with Store { String formatAmountToString(int fullBalance) { if (wallet.type == WalletType.monero) return monero!.formatterMoneroAmountToString(amount: fullBalance); - if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type)) + if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash, WalletType.lightning].contains(wallet.type)) return bitcoin!.formatterBitcoinAmountToString(amount: fullBalance); return ''; } @@ -67,7 +67,7 @@ abstract class UnspentCoinsListViewModelBase with Store { if (wallet.type == WalletType.monero) { await monero!.updateUnspents(wallet); } - if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type)) { + if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash, WalletType.lightning].contains(wallet.type)) { await bitcoin!.updateUnspents(wallet); } @@ -76,7 +76,7 @@ abstract class UnspentCoinsListViewModelBase with Store { List _getUnspents() { if (wallet.type == WalletType.monero) return monero!.getUnspents(wallet); - if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type)) + if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash, WalletType.lightning].contains(wallet.type)) return bitcoin!.getUnspents(wallet); return List.empty(); } diff --git a/lib/view_model/wallet_keys_view_model.dart b/lib/view_model/wallet_keys_view_model.dart index 2671f1623..1a9bd56ce 100644 --- a/lib/view_model/wallet_keys_view_model.dart +++ b/lib/view_model/wallet_keys_view_model.dart @@ -19,6 +19,7 @@ class WalletKeysViewModel = WalletKeysViewModelBase with _$WalletKeysViewModel; abstract class WalletKeysViewModelBase with Store { WalletKeysViewModelBase(this._appStore) : title = _appStore.wallet!.type == WalletType.bitcoin || + _appStore.wallet!.type == WalletType.lightning || _appStore.wallet!.type == WalletType.litecoin || _appStore.wallet!.type == WalletType.bitcoinCash || _appStore.wallet!.type == WalletType.ethereum || @@ -103,6 +104,7 @@ abstract class WalletKeysViewModelBase with Store { } if (_appStore.wallet!.type == WalletType.bitcoin || + _appStore.wallet!.type == WalletType.lightning || _appStore.wallet!.type == WalletType.litecoin || _appStore.wallet!.type == WalletType.bitcoinCash) { items.addAll([ diff --git a/lib/view_model/wallet_new_vm.dart b/lib/view_model/wallet_new_vm.dart index 4e3befc62..ef7c33e04 100644 --- a/lib/view_model/wallet_new_vm.dart +++ b/lib/view_model/wallet_new_vm.dart @@ -63,7 +63,8 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store { case WalletType.bitcoin: return bitcoin!.createBitcoinNewWalletCredentials(name: name); case WalletType.lightning: - return lightning!.createLightningNewWalletCredentials(name: name); + // return lightning!.createLightningNewWalletCredentials(name: name);// TODO: CW-563 see if necessary + return bitcoin!.createBitcoinNewWalletCredentials(name: name); case WalletType.litecoin: return bitcoin!.createBitcoinNewWalletCredentials(name: name); case WalletType.haven: diff --git a/lib/view_model/wallet_restore_view_model.dart b/lib/view_model/wallet_restore_view_model.dart index 8d1e3b223..bc4e6af15 100644 --- a/lib/view_model/wallet_restore_view_model.dart +++ b/lib/view_model/wallet_restore_view_model.dart @@ -90,6 +90,12 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { mnemonic: seed, password: password, ); + case WalletType.lightning: + return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials( + name: name, + mnemonic: seed, + password: password, + ); case WalletType.litecoin: return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials( name: name, mnemonic: seed, password: password); diff --git a/tool/configure.dart b/tool/configure.dart index 4460f56e2..169cfc739 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -54,6 +54,7 @@ Future main(List args) async { hasBanano: hasBanano, hasBitcoinCash: hasBitcoinCash, hasPolygon: hasPolygon, + hasLightning: hasLightning, ); } @@ -1058,7 +1059,8 @@ Future generateWalletTypes( required bool hasNano, required bool hasBanano, required bool hasBitcoinCash, - required bool hasPolygon}) async { + required bool hasPolygon, + required bool hasLightning}) async { final walletTypesFile = File(walletTypesPath); if (walletTypesFile.existsSync()) { @@ -1077,6 +1079,10 @@ Future generateWalletTypes( outputContent += '\tWalletType.bitcoin,\n'; } + if (hasLightning) { + outputContent += '\tWalletType.lightning,\n'; + } + if (hasEthereum) { outputContent += '\tWalletType.ethereum,\n'; }