Skip to content
Draft
Changes from all commits
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
36 changes: 34 additions & 2 deletions lib/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,37 @@ class SendPayment extends StatefulWidget {
class _SendPaymentState extends State<SendPayment> {
bool _isSending = true;

String _mapSendErrorToMessage(Object error) {
final raw = error.toString();
final lower = raw.toLowerCase();

if (lower.contains('insufficient') ||
lower.contains('not enough funds') ||
lower.contains('insufficient funds') ||
lower.contains('insufficient balance')) {
return 'Insufficient balance to pay this invoice (including fees).';
}

if (lower.contains('expired') ||
lower.contains('invoice has expired') ||
lower.contains('invoice expired')) {
return 'This invoice has expired and can no longer be paid.';
}

if (lower.contains('route') ||
lower.contains('routing') ||
lower.contains('no route') ||
lower.contains('could not find a route')) {
return 'Could not route your payment. Try a smaller amount or try again later.';
}

// Fallback: include a short version of the backend message if present
const maxLength = 120;
final trimmed =
raw.length <= maxLength ? raw : '${raw.substring(0, maxLength)}…';
return trimmed.isEmpty ? 'Failed to send payment.' : trimmed;
}

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -106,11 +137,12 @@ class _SendPaymentState extends State<SendPayment> {
Navigator.of(context).popUntil((route) => route.isFirst);
}
}
} catch (e) {
} catch (e, stackTrace) {
AppLogger.instance.error('Error while sending payment: $e');
AppLogger.instance.error('Stack trace while sending payment: $stackTrace');
if (!mounted) return;
ToastService().show(
message: "Failed to send payment",
message: _mapSendErrorToMessage(e),
duration: const Duration(seconds: 5),
onTap: () {},
icon: Icon(Icons.error),
Expand Down