Skip to content

Expose an aggregated pending-requests stream across all accounts #745

Description

@nogringo

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions