@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
69 lines • 2.86 kB
text/typescript
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
import type { Messenger } from "@metamask/messenger";
import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
import type { GetInterfaceContextParams, GetInterfaceContextResult } from "@metamask/snaps-sdk";
import { type InferMatching } from "@metamask/snaps-utils";
import type { PendingJsonRpcResponse } from "@metamask/utils";
import type { JsonRpcRequestWithOrigin, SnapInterfaceControllerGetInterfaceAction } from "../types.mjs";
export type GetInterfaceContextMethodActions = PermissionControllerHasPermissionAction | SnapInterfaceControllerGetInterfaceAction;
/**
* Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
* created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
*
* @example
* ```ts
* import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';
*
* const interfaceId = await snap.request({
* method: 'snap_createInterface',
* params: {
* ui: (
* <Box>
* <Heading>Hello, world!</Heading>
* <Text>Welcome to my Snap homepage!</Text>
* </Box>
* ),
* context: {
* key: 'value'
* }
* },
* })
*
* const context = await snap.request({
* method: 'snap_getInterfaceContext',
* params: {
* id: interfaceId,
* },
* })
*
* console.log(context)
* // {
* // key: 'value'
* // }
* ```
*/
export declare const getInterfaceContextHandler: {
implementation: typeof getInterfaceContextImplementation;
actionNames: ("SnapInterfaceController:getInterface" | "PermissionController:hasPermission")[];
};
declare const GetInterfaceContextParametersStruct: import("@metamask/superstruct").Struct<{
id: string;
}, {
id: import("@metamask/superstruct").Struct<string, null>;
}>;
export type GetInterfaceContextParameters = InferMatching<typeof GetInterfaceContextParametersStruct, GetInterfaceContextParams>;
/**
* The `snap_getInterfaceContext` method implementation.
*
* @param req - The JSON-RPC request object.
* @param res - The JSON-RPC response object.
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
* function.
* @param end - The `json-rpc-engine` "end" callback.
* @param _hooks - The RPC method hooks. Not used by this function.
* @param messenger - The messenger used to call controller actions.
* @returns Nothing.
*/
declare function getInterfaceContextImplementation(req: JsonRpcRequestWithOrigin<GetInterfaceContextParameters>, res: PendingJsonRpcResponse<GetInterfaceContextResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, GetInterfaceContextMethodActions>): void;
export {};
//# sourceMappingURL=getInterfaceContext.d.mts.map