Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove pasting handling #633

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class SendOptionsBottomSheet extends StatefulWidget {
}

class _SendOptionsBottomSheetState extends State<SendOptionsBottomSheet> {
ModalRoute? _loaderRoute;

@override
Widget build(BuildContext context) {
final texts = context.texts();
Expand All @@ -46,7 +44,7 @@ class _SendOptionsBottomSheetState extends State<SendOptionsBottomSheet> {
texts.bottom_action_bar_paste_invoice,
style: theme.bottomSheetTextStyle,
),
onTap: () => _pasteFromClipboard(context),
onTap: () => _showEnterPaymentInfoDialog(context, widget.firstPaymentItemKey),
),
Divider(
height: 0.0,
Expand All @@ -73,57 +71,6 @@ class _SendOptionsBottomSheetState extends State<SendOptionsBottomSheet> {
);
}

// TODO: Improve error handling flow to reduce open Enter Payment Info Dialog calls
Future<void> _pasteFromClipboard(BuildContext context) async {
try {
final inputBloc = context.read<InputBloc>();
_setLoading(true);
// Get clipboard data
await Clipboard.getData("text/plain").then(
(clipboardData) async {
// Close bottom sheet
Navigator.of(context).pop();
final clipboardText = clipboardData?.text;
_log.v("Clipboard text: $clipboardText");
if (clipboardText != null) {
// Parse clipboard text
await inputBloc.parseInput(input: clipboardText).then(
(inputType) {
// Handle parsed input
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)) {
_showEnterPaymentInfoDialog(context, widget.firstPaymentItemKey);
} else {
inputBloc.addIncomingInput(clipboardText);
}
},
);
} else {
_setLoading(false);
// If clipboard data is empty, display EnterPaymentInfoDialog
_showEnterPaymentInfoDialog(
context,
widget.firstPaymentItemKey,
);
}
},
);
} catch (e) {
_setLoading(false);
// If there's an error getting the clipboard data, display EnterPaymentInfoDialog
_showEnterPaymentInfoDialog(
context,
widget.firstPaymentItemKey,
);
} finally {
_setLoading(false);
}
}

Future<void> _showEnterPaymentInfoDialog(
BuildContext context,
GlobalKey<State<StatefulWidget>> firstPaymentItemKey,
Expand Down Expand Up @@ -152,17 +99,4 @@ class _SendOptionsBottomSheetState extends State<SendOptionsBottomSheet> {
),
);
}

void _setLoading(bool visible) {
if (visible && _loaderRoute == null) {
_loaderRoute = createLoaderRoute(context);
Navigator.of(context).push(_loaderRoute!);
return;
}

if (!visible && (_loaderRoute != null && _loaderRoute!.isActive)) {
_loaderRoute!.navigator?.removeRoute(_loaderRoute!);
_loaderRoute = null;
}
}
}
Loading