diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 873fe2977..65df32a87 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -35,7 +35,6 @@ import 'package:cw_core/utils/file.dart'; import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:flutter/foundation.dart'; -import 'package:hex/hex.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:rxdart/subjects.dart'; @@ -623,16 +622,9 @@ abstract class ElectrumWalletBase final ins = []; for (final vin in original.inputs) { - try { - final id = HEX.encode(HEX.decode(vin.txId).reversed.toList()); - final txHex = await electrumClient.getTransactionHex(hash: id); - final tx = bitcoin_base.BtcTransaction.fromRaw(txHex); - ins.add(tx); - } catch (_) { - ins.add(bitcoin_base.BtcTransaction.fromRaw( - await electrumClient.getTransactionHex(hash: vin.txId), - )); - } + final txHex = await electrumClient.getTransactionHex(hash: vin.txId); + final tx = bitcoin_base.BtcTransaction.fromRaw(txHex); + ins.add(tx); } return ElectrumTransactionBundle(original, @@ -913,4 +905,4 @@ BitcoinAddressType _getScriptType(BitcoinBaseAddress type) { } else { return SegwitAddresType.p2wpkh; } -} +} \ No newline at end of file diff --git a/lib/di.dart b/lib/di.dart index 7f2404422..a6a2aa786 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -14,7 +14,7 @@ import 'package:cake_wallet/core/yat_service.dart'; import 'package:cake_wallet/entities/background_tasks.dart'; import 'package:cake_wallet/entities/exchange_api_mode.dart'; import 'package:cake_wallet/entities/parse_address_from_domain.dart'; -import 'package:cake_wallet/view_model/LightningSendViewModel.dart'; +import 'package:cake_wallet/view_model/lightning_send_view_model.dart'; import 'package:cw_core/receive_page_option.dart'; import 'package:cake_wallet/ethereum/ethereum.dart'; import 'package:cake_wallet/lightning/lightning.dart'; diff --git a/lib/reactions/fiat_rate_update.dart b/lib/reactions/fiat_rate_update.dart index 4c312b044..a8802664b 100644 --- a/lib/reactions/fiat_rate_update.dart +++ b/lib/reactions/fiat_rate_update.dart @@ -29,18 +29,22 @@ Future startFiatRateUpdate( if (appStore.wallet!.type == WalletType.haven) { await updateHavenRate(fiatConversionStore); + return; } Iterable? currencies = []; switch (appStore.wallet!.type) { case WalletType.ethereum: - currencies = ethereum!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled); + currencies = + ethereum!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled); break; case WalletType.polygon: - currencies = polygon!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled); + currencies = + polygon!.getERC20Currencies(appStore.wallet!).where((element) => element.enabled); break; case WalletType.solana: - currencies = solana!.getSPLTokenCurrencies(appStore.wallet!).where((element) => element.enabled); + currencies = + solana!.getSPLTokenCurrencies(appStore.wallet!).where((element) => element.enabled); break; case WalletType.lightning: currencies = [CryptoCurrency.btc]; diff --git a/lib/src/screens/exchange_trade/exchange_trade_page.dart b/lib/src/screens/exchange_trade/exchange_trade_page.dart index c4dcae32c..c89f9bbca 100644 --- a/lib/src/screens/exchange_trade/exchange_trade_page.dart +++ b/lib/src/screens/exchange_trade/exchange_trade_page.dart @@ -24,22 +24,17 @@ import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; import 'package:cake_wallet/src/widgets/alert_with_one_action.dart'; import 'package:cake_wallet/themes/extensions/transaction_trade_theme.dart'; -void showInformation( - ExchangeTradeViewModel exchangeTradeViewModel, BuildContext context) { +void showInformation(ExchangeTradeViewModel exchangeTradeViewModel, BuildContext context) { final trade = exchangeTradeViewModel.trade; final walletName = exchangeTradeViewModel.wallet.name; final information = exchangeTradeViewModel.isSendable - ? S.current.exchange_result_confirm( - trade.amount, trade.from.toString(), walletName) + - exchangeTradeViewModel.extraInfo - : S.current.exchange_result_description( - trade.amount, trade.from.toString()) + - exchangeTradeViewModel.extraInfo; + ? S.current.exchange_result_confirm(trade.amount, trade.from.toString(), walletName) + + exchangeTradeViewModel.extraInfo + : S.current.exchange_result_description(trade.amount, trade.from.toString()) + + exchangeTradeViewModel.extraInfo; - showPopUp( - context: context, - builder: (_) => InformationPage(information: information)); + showPopUp(context: context, builder: (_) => InformationPage(information: information)); } class ExchangeTradePage extends BasePage { @@ -72,8 +67,7 @@ class ExchangeTradePage extends BasePage { } @override - Widget body(BuildContext context) => - ExchangeTradeForm(exchangeTradeViewModel); + Widget body(BuildContext context) => ExchangeTradeForm(exchangeTradeViewModel); } class ExchangeTradeForm extends StatefulWidget { @@ -138,7 +132,9 @@ class ExchangeTradeState extends State { style: TextStyle( fontSize: 14.0, fontWeight: FontWeight.w500, - color: Theme.of(context).extension()!.detailsTitlesColor), + color: Theme.of(context) + .extension()! + .detailsTitlesColor), ), if (trade.expiredAt != null) TimerWidget(trade.expiredAt!, @@ -159,10 +155,13 @@ class ExchangeTradeState extends State { decoration: BoxDecoration( border: Border.all( width: 3, - color: Theme.of(context).extension()!.qrCodeColor - ) + color: Theme.of(context) + .extension()! + .qrCodeColor)), + child: QrImage( + data: trade.inputAddress ?? fetchingLabel, + version: 14, ), - child: QrImage(data: trade.inputAddress ?? fetchingLabel), )))), Spacer(flex: 3) ]), @@ -192,10 +191,8 @@ class ExchangeTradeState extends State { ? Builder( builder: (context) => GestureDetector( onTap: () { - Clipboard.setData( - ClipboardData(text: value)); - showBar(context, - S.of(context).copied_to_clipboard); + Clipboard.setData(ClipboardData(text: value)); + showBar(context, S.of(context).copied_to_clipboard); }, child: content, )) @@ -209,17 +206,14 @@ class ExchangeTradeState extends State { bottomSectionPadding: EdgeInsets.fromLTRB(24, 0, 24, 24), bottomSection: Observer(builder: (_) { final trade = widget.exchangeTradeViewModel.trade; - final sendingState = - widget.exchangeTradeViewModel.sendViewModel.state; + final sendingState = widget.exchangeTradeViewModel.sendViewModel.state; return widget.exchangeTradeViewModel.isSendable && !(sendingState is TransactionCommitted) ? LoadingPrimaryButton( - isDisabled: trade.inputAddress == null || - trade.inputAddress!.isEmpty, + isDisabled: trade.inputAddress == null || trade.inputAddress!.isEmpty, isLoading: sendingState is IsExecutingState, - onPressed: () => - widget.exchangeTradeViewModel.confirmSending(), + onPressed: () => widget.exchangeTradeViewModel.confirmSending(), text: S.of(context).confirm, color: Theme.of(context).primaryColor, textColor: Colors.white) @@ -257,26 +251,24 @@ class ExchangeTradeState extends State { return ConfirmSendingAlert( alertTitle: S.of(popupContext).confirm_sending, amount: S.of(popupContext).send_amount, - amountValue: widget.exchangeTradeViewModel.sendViewModel - .pendingTransaction!.amountFormatted, + amountValue: widget + .exchangeTradeViewModel.sendViewModel.pendingTransaction!.amountFormatted, fee: S.of(popupContext).send_fee, - feeValue: widget.exchangeTradeViewModel.sendViewModel - .pendingTransaction!.feeFormatted, + feeValue: widget + .exchangeTradeViewModel.sendViewModel.pendingTransaction!.feeFormatted, rightButtonText: S.of(popupContext).send, leftButtonText: S.of(popupContext).cancel, actionRightButton: () async { Navigator.of(popupContext).pop(); - await widget.exchangeTradeViewModel.sendViewModel - .commitTransaction(); + await widget.exchangeTradeViewModel.sendViewModel.commitTransaction(); transactionStatePopup(); }, actionLeftButton: () => Navigator.of(popupContext).pop(), - feeFiatAmount: widget.exchangeTradeViewModel - .pendingTransactionFeeFiatAmountFormatted, - fiatAmountValue: widget.exchangeTradeViewModel - .pendingTransactionFiatAmountValueFormatted, - outputs: widget.exchangeTradeViewModel.sendViewModel - .outputs); + feeFiatAmount: + widget.exchangeTradeViewModel.pendingTransactionFeeFiatAmountFormatted, + fiatAmountValue: + widget.exchangeTradeViewModel.pendingTransactionFiatAmountValueFormatted, + outputs: widget.exchangeTradeViewModel.sendViewModel.outputs); }); }); } @@ -304,85 +296,26 @@ class ExchangeTradeState extends State { void transactionStatePopup() { if (this.mounted) { showPopUp( - context: context, - builder: (BuildContext popupContext) { - return Observer(builder: (_) { - final state = widget - .exchangeTradeViewModel.sendViewModel.state; + context: context, + builder: (BuildContext popupContext) { + return Observer(builder: (_) { + final state = widget.exchangeTradeViewModel.sendViewModel.state; - if (state is TransactionCommitted) { - return Stack( - children: [ - Container( - color: Theme.of(popupContext).colorScheme.background, - child: Center( - child: Image.asset( - 'assets/images/birthday_cake.png'), - ), - ), - Center( - child: Padding( - padding: EdgeInsets.only( - top: 220, left: 24, right: 24), - child: Text( - S.of(popupContext).send_success(widget - .exchangeTradeViewModel - .wallet - .currency - .toString()), - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 22, - fontWeight: FontWeight.bold, - color: Theme.of(popupContext).extension()!.titleColor, - decoration: TextDecoration.none, - ), + if (state is TransactionCommitted) { + return Stack( + children: [ + Container( + color: Theme.of(popupContext).colorScheme.background, + child: Center( + child: Image.asset('assets/images/birthday_cake.png'), ), ), - ), - Positioned( - left: 24, - right: 24, - bottom: 24, - child: PrimaryButton( - onPressed: () { - Navigator.pushNamedAndRemoveUntil( - popupContext, - Routes.dashboard, - (route) => false, - ); - RequestReviewHandler.requestReview(); - }, - text: S.of(popupContext).got_it, - color: Theme.of(popupContext).primaryColor, - textColor: Colors.white)) - ], - ); - } - - return Stack( - children: [ - Container( - color: Theme.of(popupContext).colorScheme.background, - child: Center( - child: Image.asset( - 'assets/images/birthday_cake.png'), - ), - ), - BackdropFilter( - filter: ImageFilter.blur( - sigmaX: 3.0, sigmaY: 3.0), - child: Container( - decoration: BoxDecoration( - color: Theme.of(popupContext) - .colorScheme - .background - .withOpacity(0.25)), - child: Center( + Center( child: Padding( - padding: EdgeInsets.only(top: 220), + padding: EdgeInsets.only(top: 220, left: 24, right: 24), child: Text( - S.of(popupContext).send_sending, + S.of(popupContext).send_success( + widget.exchangeTradeViewModel.wallet.currency.toString()), textAlign: TextAlign.center, style: TextStyle( fontSize: 22, @@ -393,12 +326,60 @@ class ExchangeTradeState extends State { ), ), ), + Positioned( + left: 24, + right: 24, + bottom: 24, + child: PrimaryButton( + onPressed: () { + Navigator.pushNamedAndRemoveUntil( + popupContext, + Routes.dashboard, + (route) => false, + ); + RequestReviewHandler.requestReview(); + }, + text: S.of(popupContext).got_it, + color: Theme.of(popupContext).primaryColor, + textColor: Colors.white)) + ], + ); + } + + return Stack( + children: [ + Container( + color: Theme.of(popupContext).colorScheme.background, + child: Center( + child: Image.asset('assets/images/birthday_cake.png'), + ), ), - ) - ], - ); + BackdropFilter( + filter: ImageFilter.blur(sigmaX: 3.0, sigmaY: 3.0), + child: Container( + decoration: BoxDecoration( + color: Theme.of(popupContext).colorScheme.background.withOpacity(0.25)), + child: Center( + child: Padding( + padding: EdgeInsets.only(top: 220), + child: Text( + S.of(popupContext).send_sending, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + color: Theme.of(popupContext).extension()!.titleColor, + decoration: TextDecoration.none, + ), + ), + ), + ), + ), + ) + ], + ); + }); }); - }); } } } diff --git a/lib/src/screens/receive/lightning_invoice_page.dart b/lib/src/screens/receive/lightning_invoice_page.dart index b739d70ad..9e4798e34 100644 --- a/lib/src/screens/receive/lightning_invoice_page.dart +++ b/lib/src/screens/receive/lightning_invoice_page.dart @@ -1,6 +1,7 @@ import 'package:cake_wallet/lightning/lightning.dart'; import 'package:cake_wallet/src/screens/receive/widgets/lightning_input_form.dart'; import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart'; +import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions_content_override.dart'; import 'package:cake_wallet/themes/extensions/dashboard_page_theme.dart'; import 'package:cake_wallet/themes/extensions/exchange_page_theme.dart'; @@ -242,9 +243,10 @@ class LightningInvoicePage extends BasePage { showPopUp( context: context, builder: (BuildContext context) { - return AlertWithTwoActionsContentOverride( + return AlertWithTwoActions( alertTitle: S.of(context).invoice_created, - alertContent: Column( + alertContent: '', + contentWidget: Column( children: [ Center( child: AspectRatio( diff --git a/lib/src/screens/receive/widgets/qr_image.dart b/lib/src/screens/receive/widgets/qr_image.dart index 90bde8647..54e3534d1 100644 --- a/lib/src/screens/receive/widgets/qr_image.dart +++ b/lib/src/screens/receive/widgets/qr_image.dart @@ -23,8 +23,7 @@ class QrImage extends StatelessWidget { return qr.QrImageView( data: data, errorCorrectionLevel: errorCorrectionLevel, - // Previous value: 7 something happened after flutter upgrade monero wallets addresses are longer than ver. 7 ??? - version: 14,// previously 9, but btc lightning addresses are /really/ long + version: 9,// Previous value: 7 something happened after flutter upgrade monero wallets addresses are longer than ver. 7 ??? size: size, foregroundColor: foregroundColor, backgroundColor: backgroundColor, diff --git a/lib/src/screens/send/lightning_send_confirm_page.dart b/lib/src/screens/send/lightning_send_confirm_page.dart index 242ac57b9..f5616eb46 100644 --- a/lib/src/screens/send/lightning_send_confirm_page.dart +++ b/lib/src/screens/send/lightning_send_confirm_page.dart @@ -11,7 +11,7 @@ import 'package:cake_wallet/themes/extensions/keyboard_theme.dart'; import 'package:cake_wallet/themes/theme_base.dart'; import 'package:cake_wallet/utils/responsive_layout_util.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; -import 'package:cake_wallet/view_model/LightningSendViewModel.dart'; +import 'package:cake_wallet/view_model/lightning_send_view_model.dart'; import 'package:cake_wallet/view_model/lightning_view_model.dart'; import 'package:cw_core/crypto_currency.dart'; import 'package:flutter/material.dart'; @@ -250,24 +250,10 @@ class LightningSendConfirmPage extends BasePage { text: S.of(context).send, onPressed: () async { try { - final sdk = await BreezSDK(); - late BZG.SendPaymentRequest req; - - lightningSendViewModel.setLoading(true); - - if (invoice.amountMsat == null) { - req = BZG.SendPaymentRequest( - bolt11: invoice.bolt11, - amountMsat: int.parse(_amountController.text) * 1000, - ); - } else { - req = BZG.SendPaymentRequest(bolt11: invoice.bolt11); - } - - await sdk.sendPayment(req: req); - - lightningSendViewModel.setLoading(false); - + await lightningSendViewModel.send( + invoice, + int.parse(_amountController.text) + ); showPopUp( context: context, builder: (BuildContext context) { @@ -281,7 +267,6 @@ class LightningSendConfirmPage extends BasePage { }); }); } catch (e) { - lightningSendViewModel.setLoading(false); showPopUp( context: context, builder: (BuildContext context) { diff --git a/lib/src/screens/send/lightning_send_page.dart b/lib/src/screens/send/lightning_send_page.dart index 994d90440..3e44fc12c 100644 --- a/lib/src/screens/send/lightning_send_page.dart +++ b/lib/src/screens/send/lightning_send_page.dart @@ -11,8 +11,7 @@ import 'package:cake_wallet/themes/theme_base.dart'; import 'package:cake_wallet/utils/payment_request.dart'; import 'package:cake_wallet/utils/responsive_layout_util.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; -import 'package:cake_wallet/view_model/LightningSendViewModel.dart'; -import 'package:cake_wallet/view_model/lightning_view_model.dart'; +import 'package:cake_wallet/view_model/lightning_send_view_model.dart'; import 'package:cake_wallet/view_model/send/output.dart'; import 'package:cw_core/crypto_currency.dart'; import 'package:flutter/material.dart'; @@ -35,7 +34,6 @@ class LightningSendPage extends BasePage { final AuthService authService; final LightningSendViewModel lightningSendViewModel; final GlobalKey _formKey; - final controller = PageController(initialPage: 0); final bolt11Controller = TextEditingController(); final bolt11FocusNode = FocusNode(); @@ -206,7 +204,7 @@ class LightningSendPage extends BasePage { Future send(BuildContext context) async { try { - await processInput(context); + await lightningSendViewModel.processInput(context, bolt11Controller.text); } catch (e) { showPopUp( context: context, @@ -225,29 +223,6 @@ class LightningSendPage extends BasePage { return false; } - Future processInput(BuildContext context) async { - FocusScope.of(context).unfocus(); - - final sdk = await BreezSDK(); - - late InputType inputType; - - try { - inputType = await sdk.parseInput(input: bolt11Controller.text); - } catch (_) { - throw Exception("Unknown input type"); - } - - if (inputType is InputType_Bolt11) { - final bolt11 = await sdk.parseInvoice(bolt11Controller.text); - Navigator.of(context).pushNamed(Routes.lightningSendConfirm, arguments: bolt11); - } else if (inputType is InputType_LnUrlPay) { - throw Exception("Unsupported input type"); - } else { - throw Exception("Unknown input type"); - } - } - void _setEffects(BuildContext context) { if (_effectsInstalled) { return; diff --git a/lib/src/widgets/alert_with_two_actions.dart b/lib/src/widgets/alert_with_two_actions.dart index ddb11c3ee..80423840e 100644 --- a/lib/src/widgets/alert_with_two_actions.dart +++ b/lib/src/widgets/alert_with_two_actions.dart @@ -10,6 +10,7 @@ class AlertWithTwoActions extends BaseAlertDialog { required this.rightButtonText, required this.actionLeftButton, required this.actionRightButton, + this.contentWidget, this.alertBarrierDismissible = true, this.isDividerExist = false, // this.leftActionColor, @@ -20,6 +21,7 @@ class AlertWithTwoActions extends BaseAlertDialog { final String alertContent; final String leftButtonText; final String rightButtonText; + final Widget? contentWidget; final VoidCallback actionLeftButton; final VoidCallback actionRightButton; final bool alertBarrierDismissible; @@ -47,4 +49,9 @@ class AlertWithTwoActions extends BaseAlertDialog { // Color get rightButtonColor => rightActionColor; @override bool get isDividerExists => isDividerExist; + + @override + Widget content(BuildContext context) { + return contentWidget ?? super.content(context); + } } diff --git a/lib/src/widgets/alert_with_two_actions_content_override.dart b/lib/src/widgets/alert_with_two_actions_content_override.dart deleted file mode 100644 index 33a2e4727..000000000 --- a/lib/src/widgets/alert_with_two_actions_content_override.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'dart:ui'; -import 'package:cake_wallet/src/widgets/base_alert_dialog.dart'; -import 'package:flutter/cupertino.dart'; - -class AlertWithTwoActionsContentOverride extends BaseAlertDialog { - AlertWithTwoActionsContentOverride({ - required this.alertTitle, - required this.alertContent, - required this.leftButtonText, - required this.rightButtonText, - required this.actionLeftButton, - required this.actionRightButton, - this.alertBarrierDismissible = true, - this.isDividerExist = false, - }); - - final String alertTitle; - final Widget alertContent; - final String leftButtonText; - final String rightButtonText; - final VoidCallback actionLeftButton; - final VoidCallback actionRightButton; - final bool alertBarrierDismissible; - // final Color leftActionColor; - // final Color rightActionColor; - final bool isDividerExist; - - @override - String get titleText => alertTitle; - @override - String get leftActionButtonText => leftButtonText; - @override - String get rightActionButtonText => rightButtonText; - @override - VoidCallback get actionLeft => actionLeftButton; - @override - VoidCallback get actionRight => actionRightButton; - @override - bool get barrierDismissible => alertBarrierDismissible; - - @override - Widget content(BuildContext context) { - return alertContent; - } - - @override - bool get isDividerExists => isDividerExist; -} diff --git a/lib/view_model/dashboard/transaction_list_item.dart b/lib/view_model/dashboard/transaction_list_item.dart index d3a936056..5af8a4db6 100644 --- a/lib/view_model/dashboard/transaction_list_item.dart +++ b/lib/view_model/dashboard/transaction_list_item.dart @@ -74,6 +74,8 @@ class TransactionListItem extends ActionListItem with Keyable { price: price); break; case WalletType.bitcoin: + case WalletType.litecoin: + case WalletType.bitcoinCash: amount = calculateFiatAmountRaw( cryptoAmount: bitcoin!.formatterBitcoinAmountToDouble(amount: transaction.amount), price: price); @@ -83,12 +85,6 @@ class TransactionListItem extends ActionListItem with Keyable { cryptoAmount: lightning!.formatterLightningAmountToDouble(amount: transaction.amount), price: price); break; - case WalletType.litecoin: - case WalletType.bitcoinCash: - amount = calculateFiatAmountRaw( - cryptoAmount: bitcoin!.formatterBitcoinAmountToDouble(amount: transaction.amount), - price: price); - break; case WalletType.haven: final asset = haven!.assetOfTransaction(transaction); final price = balanceViewModel.fiatConvertationStore.prices[asset]; diff --git a/lib/view_model/lightning_send_view_model.dart b/lib/view_model/lightning_send_view_model.dart index d4a35a65e..ac0a795c1 100644 --- a/lib/view_model/lightning_send_view_model.dart +++ b/lib/view_model/lightning_send_view_model.dart @@ -1,12 +1,17 @@ import 'dart:async'; import 'package:breez_sdk/breez_sdk.dart'; import 'package:breez_sdk/bridge_generated.dart' as BZG; +import 'package:breez_sdk/bridge_generated.dart'; import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart'; import 'package:cake_wallet/entities/fiat_currency.dart'; import 'package:cake_wallet/lightning/lightning.dart'; +import 'package:cake_wallet/routes.dart'; +import 'package:cake_wallet/src/widgets/alert_with_one_action.dart'; import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart'; import 'package:cake_wallet/store/settings_store.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cw_core/crypto_currency.dart'; +import 'package:flutter/widgets.dart'; import 'package:mobx/mobx.dart'; part 'lightning_send_view_model.g.dart'; @@ -21,7 +26,7 @@ abstract class LightningSendViewModelBase with Store { final SettingsStore settingsStore; final FiatConversionStore fiatConversionStore; - + @observable bool loading = false; @@ -40,4 +45,52 @@ abstract class LightningSendViewModelBase with Store { return amount; } + @action + Future send(BZG.LNInvoice invoice, int satAmount) async { + try { + setLoading(true); + + final sdk = await BreezSDK(); + late BZG.SendPaymentRequest req; + + if (invoice.amountMsat == null) { + req = BZG.SendPaymentRequest( + bolt11: invoice.bolt11, + amountMsat: satAmount * 1000, + ); + } else { + req = BZG.SendPaymentRequest(bolt11: invoice.bolt11); + } + + await sdk.sendPayment(req: req); + + setLoading(false); + } catch (e) { + setLoading(false); + } + } + + @action + Future processInput(BuildContext context, String input) async { + FocusScope.of(context).unfocus(); + + final sdk = await BreezSDK(); + + late InputType inputType; + + try { + inputType = await sdk.parseInput(input: input); + } catch (_) { + throw Exception("Unknown input type"); + } + + if (inputType is InputType_Bolt11) { + final bolt11 = await sdk.parseInvoice(input); + Navigator.of(context).pushNamed(Routes.lightningSendConfirm, arguments: bolt11); + } else if (inputType is InputType_LnUrlPay) { + throw Exception("Unsupported input type"); + } else { + throw Exception("Unknown input type"); + } + } } 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 80232038a..6436c7144 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 @@ -1,5 +1,4 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart'; -import 'package:cake_wallet/lightning/lightning.dart'; import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart'; import 'package:cw_core/unspent_coins_info.dart'; @@ -63,8 +62,6 @@ abstract class UnspentCoinsListViewModelBase with Store { return monero!.formatterMoneroAmountToString(amount: fullBalance); if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type)) return bitcoin!.formatterBitcoinAmountToString(amount: fullBalance); - if (wallet.type == WalletType.lightning) - return lightning!.formatterLightningAmountToString(amount: fullBalance); return ''; } @@ -72,7 +69,7 @@ abstract class UnspentCoinsListViewModelBase with Store { if (wallet.type == WalletType.monero) { await monero!.updateUnspents(wallet); } - if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash, WalletType.lightning] + if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash] .contains(wallet.type)) { await bitcoin!.updateUnspents(wallet); } @@ -82,7 +79,7 @@ abstract class UnspentCoinsListViewModelBase with Store { List _getUnspents() { if (wallet.type == WalletType.monero) return monero!.getUnspents(wallet); - if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash, WalletType.lightning] + if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash] .contains(wallet.type)) return bitcoin!.getUnspents(wallet); return List.empty(); }