Skip to content

Commit

Permalink
Switch to blacklist approach on "Paste Invoice or Lightning Address" …
Browse files Browse the repository at this point in the history
…page form (#321)

* Switch to blacklist approach on "Paste Invoice or Lightning Address" page form

* Remove input source restriction when handling BTC Addresses

9588656 cont.
  • Loading branch information
erdemyerebasmaz authored Jan 23, 2025
1 parent d75cfed commit bb74f32
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
12 changes: 12 additions & 0 deletions lib/cubit/input/input_state.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
import 'package:l_breez/cubit/cubit.dart';

typedef TypeCheck = bool Function(InputType);

final List<TypeCheck> unsupportedInputTypeChecks = <TypeCheck>[
(InputType input) => input is InputType_NodeId,
(InputType input) => input is InputType_Url,
];

const Set<Type> unsupportedInputStates = <Type>{
NodeIdInputState,
UrlInputState,
};

class InputState {
const InputState._();

Expand Down
14 changes: 6 additions & 8 deletions lib/handlers/input_handler/src/input_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class InputHandler extends Handler {
throw inputState.data.reason;
} else if (inputState is BitcoinAddressInputState) {
return handleBitcoinAddress(context, inputState);
} else if (inputState is UrlInputState) {
} else if (unsupportedInputStates.contains(inputState.runtimeType)) {
throw context.texts().payment_info_dialog_error_unsupported_input;
} else if (inputState is EmptyInputState) {
throw 'Failed to parse input.';
Expand Down Expand Up @@ -162,13 +162,11 @@ class InputHandler extends Handler {
}

Future<dynamic> handleBitcoinAddress(BuildContext context, BitcoinAddressInputState inputState) async {
_logger.fine('handle bitcoin address $inputState');
if (inputState.source == InputSource.qrcodeReader) {
return await Navigator.of(context).pushNamed(
SendChainSwapPage.routeName,
arguments: inputState.data,
);
}
_logger.fine('Handle Bitcoin Address $inputState');
return await Navigator.of(context).pushNamed(
SendChainSwapPage.routeName,
arguments: inputState.data,
);
}

void handleResult(dynamic result) {
Expand Down
8 changes: 1 addition & 7 deletions lib/routes/enter_payment_info/enter_payment_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,12 @@ class _EnterPaymentInfoPageState extends State<EnterPaymentInfoPage> {
});
try {
final InputType inputType = await inputCubit.parseInput(input: _paymentInfoController.text);
if (!(inputType is InputType_Bolt11 ||
inputType is InputType_Bolt12Offer ||
inputType is InputType_LnUrlPay ||
inputType is InputType_LnUrlWithdraw)) {
if (unsupportedInputTypeChecks.any((TypeCheck check) => check(inputType))) {
errMsg = texts.payment_info_dialog_error_unsupported_input;
}
if (inputType is InputType_Bolt11 && inputType.invoice.amountMsat == BigInt.zero) {
errMsg = texts.payment_request_zero_amount_not_supported;
}
if (inputType is InputType_BitcoinAddress) {
errMsg = 'Please use "Send to BTC Address" option from main menu.';
}
} catch (error) {
final String errStr = error.toString();
errMsg = errStr.contains('Unrecognized') ? texts.payment_info_dialog_error_unsupported_input : errStr;
Expand Down

0 comments on commit bb74f32

Please sign in to comment.