-
Notifications
You must be signed in to change notification settings - Fork 618
Add snap_getState
, snap_setState
, snap_clearState
methods
#2916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
16a30dc
Add `snap_getState`, `snap_setState`, `snap_clearState` methods
Mrtenz 6000f18
Add missing dependency to manage state example
Mrtenz 4a336c2
Fix example tests
Mrtenz d98f427
Throw for invalid keys
Mrtenz 78658fc
Fix `@metamask/utils` version
Mrtenz 4b1576a
Use `snap_manageState`'s target name instead of hardcoding permission…
Mrtenz 978eeae
Move check for invalid state
Mrtenz 9d71f21
Validate keys
Mrtenz b61509c
Add tests for new methods
Mrtenz f5b1c15
Update types in example
Mrtenz 9144281
Add missing hook
Mrtenz 549142a
Assume methods bound to origin
Mrtenz b5ac14e
Update packages/snaps-sdk/src/types/methods/get-state.ts
Mrtenz b324ad2
Update packages/snaps-sdk/src/types/methods/set-state.ts
Mrtenz 6d1af36
Throw error for invalid branch
Mrtenz 05ffe82
Use `isObject` for better performance
Mrtenz 4b1f033
Use `isObject` for better performance in getState handler
Mrtenz 9e3c1db
More small performance optimisations
Mrtenz ce07fbb
Update coverage
Mrtenz 01c3b7e
Reuse some logic in test-snaps
Mrtenz bafff42
Add headings to test-snaps
Mrtenz aea7f62
Move forbidden keys to shared array
Mrtenz 3ad1e63
Fix some minor issues
Mrtenz bf52606
Test calls to getSnapState hook
Mrtenz 05929ba
Update packages/snaps-rpc-methods/src/permitted/getState.test.ts
Mrtenz b99cb20
Update packages/snaps-rpc-methods/src/permitted/setState.ts
Mrtenz d9c7cd8
Update packages/snaps-rpc-methods/src/permitted/setState.ts
Mrtenz 0c8be2d
Don't allow overwriting non-objects
Mrtenz bc395c1
Remove unnecessary code
Mrtenz baa0090
Update packages/snaps-rpc-methods/src/permitted/setState.ts
Mrtenz 65625fb
Coverage
Mrtenz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import type { Json } from '@metamask/utils'; | ||
|
||
import type { State } from './utils'; | ||
|
||
export type BaseParams = { encrypted?: boolean }; | ||
export type LegacyParams = { encrypted?: boolean }; | ||
|
||
export type BaseParams = { key?: string; encrypted?: boolean }; | ||
|
||
/** | ||
* The parameters for the `setState` JSON-RPC method. | ||
* | ||
* The current state will be merged with the new state. | ||
*/ | ||
export type SetStateParams = BaseParams & Partial<State>; | ||
export type SetStateParams = BaseParams & { | ||
value: Json; | ||
}; | ||
|
||
/** | ||
* The parameters for the `legacy_setState` JSON-RPC method. | ||
*/ | ||
export type LegacySetStateParams = LegacyParams & Partial<State>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.