Expose an aggregated pending-requests stream across all accounts
Labels: enhancement
Problem
Accounts.accounts holds every logged-in account, each with its own live signer and
its own pending requests. There is no way to observe them together, so every
consumer that wants a multi-account view has to wire the aggregation itself.
There is also no way to observe the set of accounts changing: addAccount and
removeAccount notify nothing, and authStateChanges only reports the logged
account.
Suggested API
Two additions on Accounts.
First, a stream of the account set:
Stream<List<Account>> get accountsChanges;
Backed by a BehaviorSubject, emitting on addAccount and removeAccount.
Then the aggregation:
Stream<Map<String, List<PendingSignerRequest>>> get pendingRequestsStream =>
accountsChanges.switchMap((accts) {
final interactive =
accts.where((a) => a.signer.requiresInteractiveSigning).toList();
if (interactive.isEmpty) return Stream.value(const {});
return Rx.combineLatestList(interactive.map(
(a) => a.pendingRequestsStream.map((r) => MapEntry(a.pubkey, r)),
)).map(Map.fromEntries);
});
switchMap handles accounts appearing and disappearing.
combineLatestList emits immediately thanks to each signer's seeded subject.
- Filtering on
requiresInteractiveSigning avoids subscribing to local signers that
will never emit anything.
Keying the map requires the pubkey normalization from the signerPubkey issue.
Rationale
This belongs in ndk, not in the Flutter widget, so non-Flutter consumers get it too
and the widget stays trivial. It is also the piece every app building a dedicated
pending-requests screen would otherwise reimplement.
Depends on
The signerPubkey issue, for well-formed map keys.
Expose an aggregated pending-requests stream across all accounts
Labels:
enhancementProblem
Accounts.accountsholds every logged-in account, each with its own live signer andits own pending requests. There is no way to observe them together, so every
consumer that wants a multi-account view has to wire the aggregation itself.
There is also no way to observe the set of accounts changing:
addAccountandremoveAccountnotify nothing, andauthStateChangesonly reports the loggedaccount.
Suggested API
Two additions on
Accounts.First, a stream of the account set:
Backed by a
BehaviorSubject, emitting onaddAccountandremoveAccount.Then the aggregation:
switchMaphandles accounts appearing and disappearing.combineLatestListemits immediately thanks to each signer's seeded subject.requiresInteractiveSigningavoids subscribing to local signers thatwill never emit anything.
Keying the map requires the pubkey normalization from the
signerPubkeyissue.Rationale
This belongs in
ndk, not in the Flutter widget, so non-Flutter consumers get it tooand the widget stays trivial. It is also the piece every app building a dedicated
pending-requests screen would otherwise reimplement.
Depends on
The
signerPubkeyissue, for well-formed map keys.