From 9cb2059b7dd65134f741e1c77dcae52050a5c15d Mon Sep 17 00:00:00 2001 From: Ziad Saab Date: Tue, 24 Sep 2024 11:28:28 -0500 Subject: [PATCH] Document `context` parameter of interactive UI --- snaps/features/custom-ui/interactive-ui.md | 7 +++++++ snaps/reference/entry-points.md | 1 + snaps/reference/snaps-api.md | 1 + 3 files changed, 9 insertions(+) diff --git a/snaps/features/custom-ui/interactive-ui.md b/snaps/features/custom-ui/interactive-ui.md index 7eb54e057d..6518896802 100644 --- a/snaps/features/custom-ui/interactive-ui.md +++ b/snaps/features/custom-ui/interactive-ui.md @@ -37,6 +37,13 @@ If you need to [update the interface](#update-an-interactive-interface) or [get its state](#get-an-interactive-interfaces-state) at a future time, you should store its ID in the Snap's storage. +### Optionally add context to an interface + +You can optionally add context to an interface by passing a `context` object to the +[`snap_createInterface`](../../reference/snaps-api.md#snap_createinterface) method. +This object is optional and can contain any data you want to pass to the interface. +This context will be passed to [`onUserInput`](../../reference/entry-points.md#onuserinput) when the user interacts with the interface. + ## Update an interactive interface To update an interactive interface that is still active, use the diff --git a/snaps/reference/entry-points.md b/snaps/reference/entry-points.md index d965204d2b..4497adf4b0 100644 --- a/snaps/reference/entry-points.md +++ b/snaps/reference/entry-points.md @@ -654,6 +654,7 @@ To respond to [interactive UI](../features/custom-ui/interactive-ui.md) events, - `name` - The name of the component that fired the event. Optional when the event type is `ButtonClickEvent`. - `value` - When the event type is `FormSubmitEvent`, the values in the form as an object. +- `context` - The context object passed to the interface when calling [`snap_createInterface`](./snaps-api.md#snap_createinterface), or `null`. #### Example diff --git a/snaps/reference/snaps-api.md b/snaps/reference/snaps-api.md index d85837deee..270a43123e 100644 --- a/snaps/reference/snaps-api.md +++ b/snaps/reference/snaps-api.md @@ -860,6 +860,7 @@ Creates an interactive interface for use in [interactive UI](../features/custom- An object containing: - `ui` - The [custom UI](../features/custom-ui/index.md) to create. +- `context` (optional) - A custom context object that will be passed to [`onUserInput`](./entry-points.md#onuserinput) when the user interacts with the interface. #### Returns