NWC: the wallet balance is read once at connect and never refreshed

Open
#956 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
dart, flutter

Research direction

Start with lib/features/settings/providers/nwc_provider.dart and the Rust bridge at lib/src/rust/api/nwc.dart; trace connectWallet, payInvoice, trade success, wallet screen opening, and app resume to find the refresh points. Treat failed refreshes as unknown without displaying zero. Add the provider and widget tests described in the issue; done means the wallet screen shows the updated balance after each refresh trigger and the tests pass.

Written by the indexing model from the issue text.

Description

area: ui bug priority: low

Context

NwcNotifier keeps balanceSats in NwcWalletState, and the connected wallet screen shows it (nwcBalanceSats). It has an updateBalance(int? sats) method "from a get_balance result" (lib/features/settings/providers/nwc_provider.dart:66), and the Rust bridge exposes getBalance() (lib/src/rust/api/nwc.dart:37).

What happens

Nothing calls updateBalance, and nothing calls getBalance(). The balance shown is the one read once in connectWallet (at connect, or when reconnecting at startup). After the wallet pays a hold invoice, or receives a payout from a make_invoice it generated, the settings screen keeps showing the old balance until the app restarts. That figure can be off by the whole trade amount, and the user may decide whether to pay with the wallet based on it.

How to fix

  1. Refresh the balance (getBalance() → updateBalance) when the wallet screen opens, after a successful payInvoice, after a trade where the wallet generated the payout invoice reaches success, and on app resume.
  2. Treat a failed refresh as "unknown" (keep the last value and mark it stale, or hide it). Don't show 0.
  3. Add a provider test: after updateBalance is wired to a fake getBalance, the state changes. Add a widget test that the wallet screen shows the refreshed figure.
Dominant language
Dart
Stars
11
Forks
9
Avg merge
2d 1h
Merged PRs (30d)
16

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MostroP2P/app

All issues in MostroP2P/app

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.