refactor(frontend): consolidate per-account override prefetch helper · Issue #198 · LeanerCloud/cloud-commitments-cli · GitHub
Skip to content

refactor(frontend): consolidate per-account override prefetch helper #198

Closed

Description

@cristim

Context

PR #193 introduced two near-identical helpers for prefetching per-account AccountServiceOverride data into a Map<accountID, AccountServiceOverride[]> cache:

  • openFanOutModal (sub-option ii) — collects single-account-bucket account IDs, fetches via Promise.all, swallows per-account errors, passes the cache to resolveBucketPaymentSeed.
  • openPurchaseModal (sub-option iii) — collects all rec account IDs, fetches via Promise.all, swallows per-account errors, passes the cache to resolvePerRecPaymentSeed.

The fetch+cache shape is ~10 lines and identical aside from "which account IDs do we collect?". The seed functions themselves are different (per-bucket vs per-rec), so they don't merge — but the prefetch wrapper does.

What needs to happen

Extract a shared helper, e.g.:

// frontend/src/lib/overrides.ts
export async function fetchOverridesForAccounts(
  ids: Iterable<string>,
): Promise<Map<string, AccountServiceOverride[]>> {
  const out = new Map<string, AccountServiceOverride[]>();
  await Promise.all(
    Array.from(ids).map(async (id) => {
      try {
        out.set(id, await listAccountServiceOverrides(id));
      } catch {
        // Silent fallback — callers handle missing entries gracefully.
      }
    }),
  );
  return out;
}

Then openFanOutModal and openPurchaseModal each become a 1-line call.

Bonus: single mock target for tests

The existing tests mock api.listAccountServiceOverrides directly. After this refactor, they could either keep doing that (the helper still calls the same API) or mock the new helper directly for cleaner test fixtures.

References

Effort & priority

  • Effort: XS (mechanical extract + test mock check)
  • Priority: P3 (no functional change; only cleanup)

Activity

  1. added a commit that references this issue on Jun 8, 2026
    c5e3275
  2. added a commit that references this issue on Jun 19, 2026
    59f81cb
  3. added a commit that references this issue on Jul 10, 2026
    dfb1381
  4. added a commit that references this issue on Jul 17, 2026
    81d033f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions