wallet_standard/standard/
disconnect.rs

1use async_trait::async_trait;
2
3use crate::Wallet;
4use crate::WalletResult;
5
6/// Feature identifier for the standard disconnect feature.
7///
8/// This constant is used to identify the disconnect feature in the wallet's
9/// feature list. Wallets that implement the `WalletStandardDisconnect` trait
10/// should include this identifier in their feature list.
11pub const STANDARD_DISCONNECT: &str = "standard:disconnect";
12
13/// Trait for wallets that support disconnecting.
14///
15/// This trait defines a method for disconnecting from a wallet, which revokes
16/// the app's authorization to use the wallet's accounts. After disconnecting,
17/// the app will need to connect again to use the wallet.
18///
19/// # Example Implementation
20///
21/// ```rust,ignore
22/// #[async_trait(?Send)]
23/// impl WalletStandardDisconnect for MyWallet {
24///     async fn disconnect(&mut self) -> WalletResult<()> {
25///         // Clear the current account
26///         self.current_account = None;
27///
28///         // Optionally, perform any cleanup or notify the wallet's backend
29///         self.notify_backend_of_disconnect().await?;
30///
31///         Ok(())
32///     }
33/// }
34/// ```
35#[async_trait(?Send)]
36pub trait WalletStandardDisconnect: Wallet {
37	/// Disconnect from the wallet.
38	///
39	/// This method revokes the app's authorization to use the wallet's
40	/// accounts. It should clear the wallet's current account and perform any
41	/// necessary cleanup.
42	///
43	/// # Returns
44	///
45	/// A `WalletResult` containing `()` if the disconnection is successful,
46	/// or a `WalletError` if the disconnection fails.
47	///
48	/// # Errors
49	///
50	/// This method may return errors such as:
51	/// - `WalletError::WalletDisconnection` if the disconnection fails
52	/// - `WalletError::WalletDisconnected` if the wallet is already
53	///   disconnected
54	async fn disconnect(&mut self) -> WalletResult<()>;
55}