Skip to content

Commit 1e2f55d

Browse files
Montoyabgravenorst
andauthored
Snaps: Update snap_notify to include expanded view (#1774)
* Update snap_notify method reference * Update snaps/reference/snaps-api.md Co-authored-by: Byron Gravenorst <[email protected]> * Expanded view docs cleanup * Add multiple notification examples * Add to what's new * Fix lint spelling * Fix header level for expanded view * Update snaps/features/notifications.md --------- Co-authored-by: Byron Gravenorst <[email protected]>
1 parent 545d0ff commit 1e2f55d

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

docs/whats-new.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ of the [MetaMask developer page](https://metamask.io/developer/).
1111

1212
## December 2024
1313

14+
- Documented [Snap Notifications Expanded View](/snaps/features/notifications/#expanded-view).
15+
([#1774](https://github.com/MetaMask/metamask-docs/pull/1774))
1416
- Documented [`snap_getInterfaceContext`](/snaps/reference/snaps-api/#snap_getinterfacecontext).
1517
([#1772](https://github.com/MetaMask/metamask-docs/pull/1772))
1618

snaps/features/custom-ui/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ implementing the following features:
1616
- [Home pages](home-pages.md)
1717
- [Transaction insights](../transaction-insights.md)
1818
- [Signature insights](../signature-insights.md)
19+
- [Notifications (Expanded View)](../notifications.md#expanded-view)
1920

2021
:::note
2122
JSX is supported in the MetaMask extension and Flask version 12 and later.

snaps/features/notifications.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,32 @@ Each Snap can trigger up to:
6363
- Two native notifications per five minutes.
6464
:::
6565

66+
## Expanded view
67+
68+
In-app notifications can include an optional expanded view that will be displayed when the user clicks on the notification. The expanded view includes a title, content, and an optional footer link.
69+
70+
The following example displays a notification in MetaMask, with the message "Hello, world!" When the user clicks on the notification, the expanded view displays a page with a title, a paragraph, and a link to the MetaMask Snaps directory:
71+
72+
```javascript title="index.js"
73+
await snap.request({
74+
method: "snap_notify",
75+
params: {
76+
type: "inApp",
77+
message: "Hello, world!",
78+
title: "Hello",
79+
content: (
80+
<Box>
81+
<Text>Did you know you can find more Snaps in the MetaMask Snaps Directory?</Text>
82+
</Box>
83+
),
84+
footerLink: {
85+
text: "Visit the directory",
86+
href: "https://snaps.metamask.io"
87+
}
88+
},
89+
})
90+
```
91+
6692
## Example
6793
6894
See the

snaps/reference/snaps-api.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,9 @@ await snap.request({
864864
## `snap_notify`
865865

866866
Displays a [notification](../features/notifications.md) in MetaMask or natively in the OS.
867-
Snaps can trigger a short notification text for actionable or time sensitive information.
867+
Snaps can trigger a short (up to 80 characters) notification message for actionable or time sensitive information.
868+
`inApp` notifications can also include an optional [expanded view](../features/notifications.md#expanded-view).
869+
The expanded view has a title, content, and optional footer link shown when a user clicks on the notification.
868870

869871
#### Parameters
870872

@@ -874,8 +876,21 @@ An object containing the contents of the notification:
874876
We recommend using `type: "inApp"` because there's no guarantee that native notifications are
875877
displayed to the user.
876878
- `message` - A message to show in the notification.
879+
- Optional expanded view parameters
880+
- `title` - The title of the expanded view, shown when a user expands the notification.
881+
- `content` - A custom Snap UI shown in the expanded view
882+
- `footerLink` (optional) - A custom footer object with `text` and `href`, displayed as an action button
883+
in the footer of the expanded view.
877884

878-
#### Example
885+
:::caution
886+
Expanded view can only be used with notifications of type `inApp`.
887+
Expanded view must have at least a `title` and `content`.
888+
:::
889+
890+
#### Examples
891+
892+
<Tabs>
893+
<TabItem value="In-app">
879894

880895
```javascript title="index.js"
881896
await snap.request({
@@ -887,6 +902,46 @@ await snap.request({
887902
})
888903
```
889904

905+
</TabItem>
906+
<TabItem value="In-app with Expanded View">
907+
908+
```javascript title="index.js"
909+
await snap.request({
910+
method: "snap_notify",
911+
params: {
912+
type: "inApp",
913+
message: "Hello, world!",
914+
title: "Hello from a Snap",
915+
content: (
916+
<Box>
917+
<Heading>Hello, world!</Heading>
918+
<Text>This is a notification sent from a Snap.</Text>
919+
</Box>
920+
),
921+
footerLink: {
922+
href: "https://snaps.metamask.io",
923+
text: "Find more Snaps",
924+
},
925+
},
926+
})
927+
```
928+
929+
</TabItem>
930+
<TabItem value="Native">
931+
932+
```javascript title="index.js"
933+
await snap.request({
934+
method: "snap_notify",
935+
params: {
936+
type: "native",
937+
message: "Hello, world!",
938+
},
939+
})
940+
```
941+
942+
</TabItem>
943+
</Tabs>
944+
890945
## Interactive UI methods
891946

892947
The following methods are used in [interactive UI](../features/custom-ui/interactive-ui.md).

0 commit comments

Comments
 (0)