rusnap_api/
notify.rs

1use serde::{Deserialize, Serialize};
2
3use crate::Result;
4
5use super::request;
6
7/// Type of Notify
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub enum NotifyType {
11    /// Display the notification in the MetaMask UI
12    InApp,
13    /// Display the notification in the browser
14    Native,
15}
16
17#[derive(Debug, Serialize, Deserialize)]
18struct NotifyParams<'a> {
19    #[serde(rename = "type")]
20    pub ty: NotifyType,
21    pub message: &'a str,
22}
23
24/// Displays a notification in MetaMask or natively in the browser.
25///
26/// Snap Document: [snap_notify](https://docs.metamask.io/snaps/reference/rpc-api/#snap_notify)
27pub async fn notify(ty: NotifyType, message: &str) -> Result<()> {
28    request("snap_notify", NotifyParams { ty, message }).await
29}