File tree Expand file tree Collapse file tree 3 files changed +57
-4
lines changed
Expand file tree Collapse file tree 3 files changed +57
-4
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,11 @@ The latest major MetaMask documentation updates are listed by the month they wer
99For a comprehensive list of recent product changes, visit the "Release Notes" section at the bottom
1010of the [ MetaMask developer page] ( https://metamask.io/developer/ ) .
1111
12+ ## December 2024
13+
14+ - Documented [ ` snap_getInterfaceContext ` ] ( /snaps/reference/snaps-api/#snap_getinterfacecontext ) .
15+ ([ #1772 ] ( https://github.com/MetaMask/metamask-docs/pull/1772 ) )
16+
1217## November 2024
1318
1419- Documented [ Unichain Sepolia] ( /services/reference/unichain ) support. ([ #1725 ] ( https://github.com/MetaMask/metamask-docs/pull/1725 ) )
Original file line number Diff line number Diff line change @@ -58,11 +58,13 @@ The following is an example flow:
58585 . Custom logic sends the funds.
59596 . ` snap_updateInterface ` is called again, replacing the whole UI with a success message.
6060
61- ## Get an interactive interface's state
61+ ## Get an interactive interface's state and context
6262
63- At any point you can retrieve an interactive interface's state.
64- To do this, call the [ ` snap_getInterfaceState ` ] ( ../../reference/snaps-api.md#snap_getinterfacestate )
65- method with the ID of the interface.
63+ At any point, you can retrieve an interactive interface's state and context.
64+ To retrieve its state, call the [ ` snap_getInterfaceState ` ] ( ../../reference/snaps-api.md#snap_getinterfacestate )
65+ method with the interface ID.
66+ To retrieve its context, call [ ` snap_getInterfaceContext ` ] ( ../../reference/snaps-api.md#snap_getinterfacecontext )
67+ with the interface ID.
6668
6769## Example
6870
Original file line number Diff line number Diff line change @@ -986,6 +986,52 @@ console.log(state)
986986*/
987987```
988988
989+ ### ` snap_getInterfaceContext `
990+
991+ Gets the context of an interactive interface by its ID.
992+ For use in [ interactive UI] ( ../features/custom-ui/interactive-ui.md ) .
993+
994+ #### Parameters
995+
996+ - ` id ` - The ID of the interface.
997+
998+ #### Returns
999+
1000+ An object of type ` InterfaceContext ` if a custom context object was passed when creating or updating the interface, or ` null ` .
1001+
1002+ #### Example
1003+
1004+ ``` js title="index.js"
1005+ const interfaceId = await snap .request ({
1006+ method: " snap_createInterface" ,
1007+ params: {
1008+ ui: (
1009+ < Box>
1010+ < Heading> Hello, world! < / Heading>
1011+ < Text > Welcome to my Snap homepage! < / Text >
1012+ < / Box>
1013+ ),
1014+ context: {
1015+ key: " value"
1016+ }
1017+ },
1018+ })
1019+
1020+ const context = await snap .request ({
1021+ method: " snap_getInterfaceContext" ,
1022+ params: {
1023+ id: interfaceId,
1024+ },
1025+ })
1026+
1027+ console .log (context)
1028+ /*
1029+ {
1030+ "key": "value"
1031+ }
1032+ */
1033+ ```
1034+
9891035### ` snap_resolveInterface `
9901036
9911037Resolves an interactive interface.
You can’t perform that action at this time.
0 commit comments