Skip to content

fix: add mounted guard after async network calls in AmountScreen - #115

Open
Delgado74 wants to merge 2 commits into
lachispame:mainfrom
Delgado74:fix/mounted-guard-amount-screen
Open

fix: add mounted guard after async network calls in AmountScreen#115
Delgado74 wants to merge 2 commits into
lachispame:mainfrom
Delgado74:fix/mounted-guard-amount-screen

Conversation

@Delgado74

Copy link
Copy Markdown
Contributor

Summary

Closes #67

Adds if (!mounted) return; guards after async network calls in _processLNURLPayment and _processLightningAddressPayment to prevent potential crashes when the user navigates away during an in-flight payment request.

Problem

After await _invoiceService.sendPaymentToLNURL(...) and await _invoiceService.sendPaymentToLightningAddress(...), the code calls _showPendingSnackBar, _showSuccessSnackBar, and Navigator.of(context).popUntil without checking if the widget is still mounted. If the user presses back while the request is in flight:

  • The widget's BuildContext becomes invalid
  • Accessing context.tokens or ScaffoldMessenger.of(context) can throw an exception

While timing may prevent a crash in many cases (fast response, slow user), the race condition exists and eliminating it is trivial.

Changes

File Change
lib/screens/11amount_screen.dart Added if (!mounted) return; after the two async network calls (lines +415, +494)

Testing

flutter analyze passes with no new issues.

Add if (!mounted) return; after await _invoiceService.sendPaymentToLNURL
and await _invoiceService.sendPaymentToLightningAddress to prevent
potential crashes when the user navigates away during a payment request.

Closes lachispame#67
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Delgado74, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 58 minutes and 54 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d9185e9a-dcff-458d-830c-b8fa429bd827

📥 Commits

Reviewing files that changed from the base of the PR and between 5b51629 and eb6ff1a.

📒 Files selected for processing (1)
  • lib/screens/11amount_screen.dart
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Add mounted guard after async network calls in AmountScreen

1 participant