feat(stellar-wallet-snap): use shareable state management lib - #297
feat(stellar-wallet-snap): use shareable state management lib#297Julink-eth wants to merge 3 commits into
Conversation
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
🟢 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/ testInMemoryStateimplementations with@metamask/snap-networks-utilsequivalents (State,IStateManager,InMemoryState). - Centralized the Stellar snap’s unencrypted state shape and defaults in
services/state/stateTypes.ts, and wiredcontext.tsto use it. - Updated repositories, tests, and fixtures to use the shared
IStateManager+ sharedInMemoryState; 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.
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. |
|



Explanation
@metamask/snap-networks-utilsstate helpers (IStateManager,State,InMemoryState) from #288.State/IStateManagerimplementations and the cacheInMemoryStatetest double. Tests and fixtures use the sharedInMemoryState.stateTypes.ts(UnencryptedStateValue/DEFAULT_UNENCRYPTED_STATE).context.tswithnew State({ encrypted: false, defaultState: DEFAULT_UNENCRYPTED_STATE })and type consumers asIStateManager.getState/setState/updateStatewrappers fromutils/snap.ts(only the old localStateused them). SharedStatetalks tosnap_getState/snap_setState/snap_manageStatedirectly.async-mutexon the Stellar package:SynchronizeServicestill uses it.References
Checklist