Skip to content

Extract the leaf concerns from CantonConnectProvider #70

Description

@fernandomg

User story / Problem statement

Currently canton-connect/src/CantonConnectProvider.tsx is ~640 lines. The connect/cancel/restore
race core has to stay together (five concerns share four refs plus the transition helpers;
splitting them threads the same refs through every file boundary), but roughly 150-200 lines are
leaf concerns with little or no shared state: the adapter building, the two public context types,
and the in-page picker bridge. A reader pays the whole file to find any one of them.

Sized by #63's pre-undraft review pass; this issue is the profitable slice.

Expected outcome

The provider file holds only the race core and context assembly (roughly 440-540 lines depending
on whether the picker bridge moves). Behavior identical, public API identical, and the existing
test suite passes textually unchanged (it imports only the public surface).

Acceptance criteria

  • buildAdditionalAdapters and AdapterConfig move to src/adapters.ts
  • TxStatusSnapshot and CantonConnectContextValue move to src/types.ts, re-exported from
    CantonConnectProvider so existing imports keep resolving
  • Optional, judged at implementation time: the in-page picker bridge (inPagePicker,
    select/cancel, cancelPending, offeredWallets) becomes a hook taking the shared refs
    as stable params; inPagePicker's identity stays stable (it keys the sdk memo)
  • The race core (connect, runConnect, syncFromStatus, the mount effect, disconnect)
    stays in CantonConnectProvider.tsx, per canton-connect/CLAUDE.md
  • pnpm -C canton-connect test passes with no test edits; no public API change

Technical notes

Do this after the #47..#63 stack merges: a rename-heavy diff on top would churn the review
anchors. The deeper hook split (useConnectAttempt, useSessionRestore, ...) was evaluated and
rejected for now, because it scatters the transition helpers that #63's recorded reducer deferral
wants gathered in one place. Revisit only at that trigger; the reducer work shrinks the provider
naturally (the transitions become a sibling connectionReducer.ts, independently testable).

Metadata

Metadata

Assignees

Labels

area: connectcanton-connect: hooks, adapters, session, SDK facadeenhancementNew feature or requestpriority: lowNice to have, can wait

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions