From 4f8cba6425e58b0553a0f9815e8293287cc9616a Mon Sep 17 00:00:00 2001 From: Erdem Yerebasmaz Date: Wed, 26 Jun 2024 12:53:39 +0300 Subject: [PATCH] Integrate input parser closes #22 --- lib/bloc/input/input_bloc.dart | 36 ++++--------------- .../enter_payment_info_dialog.dart | 12 ++++--- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/lib/bloc/input/input_bloc.dart b/lib/bloc/input/input_bloc.dart index 7e515c13..83b49c5b 100644 --- a/lib/bloc/input/input_bloc.dart +++ b/lib/bloc/input/input_bloc.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_breez_liquid/flutter_breez_liquid.dart' as liquid_sdk; +import 'package:flutter_breez_liquid/flutter_breez_liquid.dart'; import 'package:l_breez/bloc/input/input_data.dart'; import 'package:l_breez/bloc/input/input_printer.dart'; import 'package:l_breez/bloc/input/input_source.dart'; @@ -70,28 +70,10 @@ class InputBloc extends Cubit { // Emit an empty InputState with isLoading to display a loader on UI layer emit(const InputState.loading()); try { - /* - final parsedInput = await parseInput(input: input.data); + final parsedInput = await parse(input: input.data); return await _handleParsedInput(parsedInput, input.source); - */ - final parsedInput = parseInvoice(input: input.data); - final req = liquid_sdk.PrepareSendRequest(invoice: parsedInput.bolt11); - final resp = await ServiceInjector().liquidSDK.wallet!.prepareSendPayment(req: req); - // TODO: Liquid/FRB - Address BigInt & Int changes - return InputState.invoice( - Invoice( - bolt11: resp.invoice, - paymentHash: parsedInput.paymentHash, - description: parsedInput.description ?? "", - amountMsat: parsedInput.amountMsat ?? BigInt.zero, - expiry: parsedInput.expiry, - lspFee: resp.feesSat.toInt(), - ), - input.source, - ); } catch (e) { - // TODO: Liquid - Revert back to "Failed to parse input" once InputParser is fully integrated into Liquid SDK - _log.severe("Failed to prepare Send Payment", e); + _log.severe("Failed to parse input", e); return const InputState.empty(); } }); @@ -101,10 +83,6 @@ class InputBloc extends Cubit { _log.info("handlePaymentRequest: $inputData source: $source"); final LNInvoice lnInvoice = inputData.invoice; - /*NodeState? nodeState = await _breezSDK.nodeInfo(); - if (nodeState == null || nodeState.id == lnInvoice.payeePubkey) { - return const InputState.empty(); - }*/ final invoice = Invoice( bolt11: lnInvoice.bolt11, paymentHash: lnInvoice.paymentHash, @@ -115,8 +93,6 @@ class InputBloc extends Cubit { return InputState.invoice(invoice, source); } - // TODO: Liquid - Implement input parser to parse bolt11 invoice - https://github.com/breez/breez-liquid-sdk/issues/232 - // ignore: unused_element Future _handleParsedInput(InputType parsedInput, InputSource source) async { _log.info("handleParsedInput: $source => ${inputTypeToString(parsedInput)}"); InputState result; @@ -143,8 +119,8 @@ class InputBloc extends Cubit { return result; } - liquid_sdk.LNInvoice parseInvoice({required String input}) { - _log.info("parseInvoice: $input"); - return liquid_sdk.parseInvoice(input: input); + Future parseInput({required String input}) async { + _log.info("parseInput: $input"); + return await parse(input: input); } } diff --git a/lib/routes/home/widgets/bottom_actions_bar/enter_payment_info_dialog.dart b/lib/routes/home/widgets/bottom_actions_bar/enter_payment_info_dialog.dart index df8a2b17..d4cdd317 100644 --- a/lib/routes/home/widgets/bottom_actions_bar/enter_payment_info_dialog.dart +++ b/lib/routes/home/widgets/bottom_actions_bar/enter_payment_info_dialog.dart @@ -208,13 +208,15 @@ class EnterPaymentInfoDialogState extends State { final texts = context.texts(); try { _setValidatorErrorMessage(""); - // TODO: Liquid - Previously parseInput, parseInvoice only parses LNInvoice's. - final inputType = context.read().parseInvoice(input: input); + final inputType = context.read().parseInput(input: input); _log.info("Parsed input type: '${inputType.runtimeType.toString()}"); // Can't compare against a list of InputType as runtime type comparison is a bit tricky with binding generated enums - // TODO: Liquid - Add other supported InputType's once parse_invoice has evolved into parse_input. - // ignore: unnecessary_type_check - if (inputType is! LNInvoice) { + if (!(inputType is InputType_Bolt11 || + inputType is InputType_LnUrlPay || + inputType is InputType_LnUrlWithdraw || + inputType is InputType_LnUrlAuth || + inputType is InputType_LnUrlError || + inputType is InputType_NodeId)) { _setValidatorErrorMessage(texts.payment_info_dialog_error_unsupported_input); } } catch (e) {