Skip to content

feat(stellar-wallet-snap): use shareable state management lib - #297

Open
Julink-eth wants to merge 3 commits into
mainfrom
feat/WPN-2059-stellar-shared-state
Open

feat(stellar-wallet-snap): use shareable state management lib#297
Julink-eth wants to merge 3 commits into
mainfrom
feat/WPN-2059-stellar-shared-state

Conversation

@Julink-eth

Copy link
Copy Markdown
Contributor

Explanation

  • Switch Stellar to the shared @metamask/snap-networks-utils state helpers (IStateManager, State, InMemoryState) from #288.
  • Delete the local State / IStateManager implementations and the cache InMemoryState test double. Tests and fixtures use the shared InMemoryState.
  • Keep Stellar-only state shape in stateTypes.ts (UnencryptedStateValue / DEFAULT_UNENCRYPTED_STATE).
  • Wire context.ts with new State({ encrypted: false, defaultState: DEFAULT_UNENCRYPTED_STATE }) and type consumers as IStateManager.
  • Remove unused getState / setState / updateState wrappers from utils/snap.ts (only the old local State used them). Shared State talks to snap_getState / snap_setState / snap_manageState directly.
  • Keep async-mutex on the Stellar package: SynchronizeService still uses it.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@Julink-eth
Julink-eth requested a review from a team as a code owner September 9, 2026 14:57
@Julink-eth
Julink-eth deployed to default-branch September 9, 2026 14:57 — with GitHub Actions Active
@Julink-eth

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/bitcoin-wallet-snap@2.0.1-preview-768fd87
@metamask-previews/snap-networks-utils@1.0.0-preview-768fd87
@metamask-previews/solana-wallet-snap@6.0.0-preview-768fd87
@metamask-previews/stellar-wallet-snap@0.1.0-preview-768fd87
@metamask-previews/tron-wallet-snap@3.2.0-preview-768fd87

@stanleyyconsensys stanleyyconsensys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think ur PR should ship after @taran-a one ?

becoz he moving cache utils in share library

i can see the behavior of lock is changing , but I guess somehow it is a fix, glad u fix it

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The migration to the shared state helpers is consistent across production code and tests/fixtures, and no remaining references to the removed local state utilities were found.

Pull request overview

This PR migrates @metamask/stellar-wallet-snap from its bespoke snap-state abstractions to the shared state helpers in @metamask/snap-networks-utils, consolidating state locking/serialization behavior with the cross-snap implementation added in #288.

Changes:

  • Replaced local State / IStateManager / test InMemoryState implementations with @metamask/snap-networks-utils equivalents (State, IStateManager, InMemoryState).
  • Centralized the Stellar snap’s unencrypted state shape and defaults in services/state/stateTypes.ts, and wired context.ts to use it.
  • Updated repositories, tests, and fixtures to use the shared IStateManager + shared InMemoryState; removed now-unused snap state RPC wrapper helpers.
File summaries
File Description
packages/stellar-wallet-snap/src/utils/snap.ts Removes now-unused snap state RPC wrapper helpers (get/set/update) in favor of shared State calling RPC directly.
packages/stellar-wallet-snap/src/utils/mocks/snap.ts Aligns snap utils mock exports with removed wrapper helpers.
packages/stellar-wallet-snap/src/services/transaction/TransactionSynchronizeService.test.ts Switches tests to shared InMemoryState instead of local State.
packages/stellar-wallet-snap/src/services/transaction/TransactionRepository.ts Updates repository to depend on shared IStateManager.
packages/stellar-wallet-snap/src/services/transaction/TransactionRepository.test.ts Refactors repository tests to use shared InMemoryState and shared default unencrypted state.
packages/stellar-wallet-snap/src/services/transaction/mocks/transaction.fixtures.ts Updates transaction fixtures to use shared InMemoryState.
packages/stellar-wallet-snap/src/services/state/stateTypes.ts Introduces Stellar-specific unencrypted state shape + defaults (kept snap-specific).
packages/stellar-wallet-snap/src/services/state/State.ts Removes local State implementation superseded by shared State.
packages/stellar-wallet-snap/src/services/state/State.test.ts Removes tests for local State implementation (covered by shared lib).
packages/stellar-wallet-snap/src/services/state/IStateManager.ts Removes local IStateManager type superseded by shared IStateManager.
packages/stellar-wallet-snap/src/services/state/index.ts Removes state barrel exports that referenced deleted local state files.
packages/stellar-wallet-snap/src/services/on-chain-account/OnChainAccountRepository.ts Swaps local IStateManager import for shared IStateManager.
packages/stellar-wallet-snap/src/services/on-chain-account/mocks/onChainAccount.fixtures.ts Updates fixtures to use shared InMemoryState.
packages/stellar-wallet-snap/src/services/cache/StateCache.ts Swaps local IStateManager import for shared IStateManager.
packages/stellar-wallet-snap/src/services/cache/StateCache.test.ts Updates tests to use shared InMemoryState.
packages/stellar-wallet-snap/src/services/cache/InMemoryState.ts Removes local cache InMemoryState test double superseded by shared InMemoryState.
packages/stellar-wallet-snap/src/services/asset-metadata/AssetMetadataRepository.ts Swaps local IStateManager import for shared IStateManager.
packages/stellar-wallet-snap/src/services/asset-metadata/AssetMetadataRepository.test.ts Updates state manager mock shape to match shared IStateManager (adds setKeyWith, deleteKeys).
packages/stellar-wallet-snap/src/services/asset-metadata/mocks/assets.fixtures.ts Updates fixtures to use shared InMemoryState.
packages/stellar-wallet-snap/src/services/account/AccountsRepository.ts Swaps local IStateManager import for shared IStateManager.
packages/stellar-wallet-snap/src/services/account/mocks/account.fixtures.ts Updates fixtures to use shared InMemoryState.
packages/stellar-wallet-snap/src/context.ts Wires shared State with DEFAULT_UNENCRYPTED_STATE and removes inline default state literal.
packages/stellar-wallet-snap/snap.manifest.json Updates bundle shasum to match new build output.
Review details
  • Files reviewed: 23/23 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Julink-eth

Copy link
Copy Markdown
Contributor Author

i think ur PR should ship after @taran-a one ?

becoz he moving cache utils in share library

i can see the behavior of lock is changing , but I guess somehow it is a fix, glad u fix it

Yes I can wait for Andrew to merge the cache shared utils in each snap first and make sure everything still works correctly with my PRs.
Yeah the lock changing is a fix indeed.

@sonarqubecloud

Copy link
Copy Markdown

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants