You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To display a custom dialog, call [`snap_dialog`](../../reference/snaps-api.md#snap_dialog)
129
+
without providing a `type`. Custom dialogs can be resolved by calling [`snap_resolveInterface`](../../reference/snaps-api.md#snap_resolveinterface). The UI passed to a custom dialog should contain a `Footer` element. Its buttons will be displayed at the bottom of the dialog. Here is a complete example:
130
+
131
+
```tsx title="index.tsx"
132
+
import {
133
+
UserInputEventType,
134
+
typeOnRpcRequestHandler,
135
+
typeOnUserInputHandler,
136
+
} from"@metamask/snaps-sdk";
137
+
import {
138
+
Box,
139
+
Text,
140
+
Heading,
141
+
Container,
142
+
Footer,
143
+
Button,
144
+
} from"@metamask/snaps-sdk/jsx";
145
+
146
+
/**
147
+
* Handle incoming JSON-RPC requests, sent through wallet_invokeSnap.
148
+
*
149
+
* @paramargs - The request handler args as object.
150
+
* @paramargs.origin - The origin of the request, e.g., the website that
151
+
* invoked the snap.
152
+
* @paramargs.request - A validated JSON-RPC request object.
153
+
* @returns The result of snap_dialog.
154
+
* @throws If the request method is not valid for this snap.
if (event.type===UserInputEventType.ButtonClickEvent) {
186
+
switch (event.name) {
187
+
case"no": // User selected "No" in the footer.
188
+
awaitsnap.request({
189
+
method: "snap_resolveInterface",
190
+
params: {
191
+
id,
192
+
value: false,
193
+
},
194
+
});
195
+
break;
196
+
197
+
case"yes": {
198
+
// User selected "Yes" in the footer
199
+
awaitsnap.request({
200
+
method: "snap_resolveInterface",
201
+
params: {
202
+
id,
203
+
value: true,
204
+
},
205
+
});
206
+
break;
207
+
}
208
+
209
+
default:
210
+
break;
211
+
}
212
+
}
213
+
};
214
+
```
215
+
216
+
This code outputs a custom dialog with two buttons: **Yes** and **No**.
217
+
When the user selects one of the buttons, `onUserInput` is called with the button's name. From there, `snap_resolveInterface` is called. This resolves the dialog, and returns the value passed to `snap_resolveInterface` as the result of the dialog.
Copy file name to clipboardExpand all lines: snaps/reference/snaps-api.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Displays a [dialog](../features/custom-ui/dialogs.md) in the MetaMask UI.
25
25
26
26
An object containing the contents of the dialog:
27
27
28
-
-`type` - The type of dialog.
28
+
-`type` - (Optional) The type of dialog. Not providing a type will create a fully [custom dialog](../features/custom-ui/dialogs.md#display-a-custom-dialog).
29
29
Possible values are:
30
30
-`"alert"` - An alert that can only be acknowledged.
31
31
-`"confirmation"` - A confirmation that can be accepted or rejected.
@@ -997,6 +997,22 @@ console.log(state)
997
997
*/
998
998
```
999
999
1000
+
### `snap_resolveInterface`
1001
+
1002
+
Resolves an interactive interface.
1003
+
For use in [custom dialogs](../features/custom-ui/dialogs.md#display-a-custom-dialog).
1004
+
1005
+
#### Parameters
1006
+
1007
+
An object containing:
1008
+
1009
+
-`id` - The ID of the interface to be resolved.
1010
+
-`result` - The result to return to the interface's caller.
1011
+
1012
+
#### Example
1013
+
1014
+
For a full example of how to use `snap_resolveInterface`, see the [custom dialogs](../features/custom-ui/dialogs.md#display-a-custom-dialog) documentation.
0 commit comments