Skip to content

wallet: Document the state-injection contract in README #8792

@grypez

Description

@grypez

Problem

@metamask/wallet has no usage documentation. The persistence contract — how consumers supply initial state and subscribe to controller state changes — is entirely implicit. Callers must read the source to understand how to wire persistence, and there is no canonical reference for the expected data shapes or event subscription pattern.

Proposed direction

Add a Usage section to packages/wallet/README.md covering:

  • Hydration: pass an initial state object keyed by controller name to the Wallet constructor. Missing keys fall back to each controller's default state.
  • Writes: subscribe to ${ControllerName}:stateChanged events on wallet.messenger; use wallet.controllerMetadata to identify which fields carry persist: true.
  • Include short code examples for both.

Acceptance

  • README.md has a Usage section with working code examples for both hydration and the stateChanged subscription pattern.
  • The role of wallet.controllerMetadata (identifying persist-flagged fields) is explained.
  • Changelog entry added.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions