[NWC] Phase 3: Automatic hold invoice payment for sellers via NWC#467
[NWC] Phase 3: Automatic hold invoice payment for sellers via NWC#467
Conversation
Add NWC auto-payment flow to PayLightningInvoiceScreen. When a wallet is connected via NWC, the user sees a 'Pay with Wallet' button instead of the manual QR code flow. New files: - NwcPaymentWidget: reusable payment UI with progress states (idle → paying → success/failed), balance check, error handling, and manual fallback - NWC_PHASE3_IMPLEMENTATION.md: detailed documentation Modified: - PayLightningInvoiceScreen: detects NWC connection, shows auto-pay or manual flow based on wallet state + user choice - NwcNotifier: added payInvoice() method with auto balance refresh - Localization: 11 new strings in EN, ES, IT for payment UI Features: - Balance-aware: disables button if wallet balance < invoice amount - Error handling: INSUFFICIENT_BALANCE, PAYMENT_FAILED, RATE_LIMITED, QUOTA_EXCEEDED, timeout — all with user-friendly messages - Retry: failed payments can be retried without leaving the screen - Fallback: 'Pay manually' link switches to QR code flow - No regression: manual flow unchanged when no NWC wallet connected Closes #458
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughAdds NWC Phase 3 implementation: automatic Lightning invoice payment via connected wallet. Introduces NwcPaymentWidget for UI/state management, payInvoice method to NwcNotifier, integrates NWC auto-pay flow into PayLightningInvoiceScreen with manual fallback, and adds localization strings for payment states across EN/ES/IT. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Screen as PayLightningInvoiceScreen
participant Widget as NwcPaymentWidget
participant Notifier as NwcNotifier
participant Client as NwcClient
participant Wallet as Lightning Wallet
User->>Screen: Navigate with invoice & amount
Screen->>Screen: Check NWC connection status
alt NWC Connected
Screen->>Widget: Render with invoice & sats
User->>Widget: Tap "Pay with Wallet"
Widget->>Widget: Set status=paying
Widget->>Notifier: payInvoice(lnInvoice)
Notifier->>Client: payInvoice(PayInvoiceParams)
Client->>Wallet: Request payment via NIP-47
Wallet->>Wallet: Process & sign invoice
Wallet-->>Client: PayInvoiceResult with preimage
Client-->>Notifier: Return result
Notifier->>Notifier: Call getBalance() to refresh
Notifier-->>Widget: Return PayInvoiceResult
Widget->>Widget: Set status=success
Widget-->>User: Display preimage & success
User->>Screen: Success callback
Screen->>Screen: Navigate home
else NWC Not Connected
Screen->>Screen: Render manual flow
User->>User: Copy & pay invoice manually
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@lib/shared/widgets/nwc_payment_widget.dart`:
- Around line 68-79: Replace the hardcoded "Preimage:" label with a localized
string (add a new key nwcPreimageLabel in all ARB files and use your app's
localization accessor, e.g. AppLocalizations.of(context).nwcPreimageLabel) and
stop calling substring directly on the preimage; instead add a small safe helper
(e.g. _preview(String? p, [int len = 8]) that returns p==null?'' : (p.length <=
len ? p : p.substring(0, len) + '...')) and use it wherever preimage previews
are shown (references: nwc_payment_widget, the code around
nwcNotifier.payInvoice, setState where _preimage is set, and logger.i calls) so
both the 8-char and 16-char previews use the safe helper.
- Add _truncatePreimage helper to prevent substring exceptions on short/null preimage values - Localize hardcoded 'Preimage:' label via nwcPreimageLabel key - Add nwcPreimageLabel to EN/ES/IT ARB files
The seller pays the hold invoice (escrow), not the buyer. The buyer provides an invoice to receive sats, not the seller.
Summary
Adds automatic Lightning invoice payment via NWC (Nostr Wallet Connect) to the buyer/seller escrow flow. When an NWC wallet is connected, users see a "Pay with Wallet" button instead of the manual QR code flow.
Changes
New Files
lib/shared/widgets/nwc_payment_widget.dart— Reusable NWC payment widget with progress states (idle → paying → success/failed)docs/NWC_PHASE3_IMPLEMENTATION.md— Detailed implementation documentationModified Files
lib/features/order/screens/pay_lightning_invoice_screen.dart— Detects NWC connection, shows auto-pay or manual flowlib/features/wallet/providers/nwc_provider.dart— AddedpayInvoice()method with auto balance refreshlib/l10n/intl_en.arb,intl_es.arb,intl_it.arb— 11 new localization stringsFeatures
Flow
PaymentRequestwith Lightning invoiceScreenshots
UI follows existing app theme (AppTheme colors, lucide_icons, 12px border radius cards).
Testing
Manual testing with Coinos NWC wallet. Widget is stateless-safe (each instance manages own payment state).
References
Summary by CodeRabbit
New Features
Documentation
Localization