Skip to content

createMockAdapter cannot restore a session across reloads #69

Description

@fernandomg

User story / Problem statement

Currently, createMockAdapter() keeps its connected flag in page memory and implements no
restore(). DiscoveryClient.tryRestore() only restores through that optional hook
(if (!adapter.restore) return), so a mock-backed session can never survive a reload: every boot
lands disconnected even though the SDK's splice_discovery_client_session record still names the
mock. This is a problem because the SDK's own adapters (extension, WalletConnect, remote) all
implement restore(), so the mock is the one adapter whose reload behaviour diverges from a real
wallet — a dev running a mock-first dApp is logged out on every refresh, and useParty().wallet's
survives-a-reload contract cannot be demonstrated without a real wallet.

Found during #63's harness walkthrough (task 12): the reload flows only became walkable after
wrapping the mock with a harness-local persistence shim answering restore().

Expected outcome

A mock-backed session survives a reload the way a real adapter's does: after connect + reload, the
provider restores to connected, useParty()/useParties() repopulate, and useParty().wallet
names the mock again. Disconnect still ends the persisted session. Tests that want a hermetic mock
keep today's behaviour.

Acceptance criteria

  • createMockAdapter() accepts an opt-in persistence option (name to taste, e.g.
    persistSession: true) that stores the connected flag in localStorage
  • With it on, the adapter implements restore(): returns the provider when the flag is set,
    null otherwise
  • disconnect clears the flag; restore() after disconnect returns null
  • Default (off) keeps the adapter fully in-memory, so existing tests are unaffected
  • JSDoc on the new option; the harness shim in docs/harness is retired when this lands

Technical notes

The shim that proves the shape (persist on connect, clear on disconnect, replay inside
restore()) is in docs/harness/src/App.tsx (withPersistedConnection, gitignored). Keep the
mock's other rule intact: it answers the connect flow only, and everything else throws naming the
method.

Additional context

Restore path: sdk.init()DiscoveryClient.restorePersistedSessionIfNeeded()
adapter.restore()DappClient rebuilt → status/listAccounts. See
@canton-network/core-wallet-discovery tryRestore().

Metadata

Metadata

Assignees

No one assigned

    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