WalletStandardConnect

Trait WalletStandardConnect 

Source
pub trait WalletStandardConnect: Wallet {
    // Required methods
    fn connect<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Account>, WalletError>> + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn connect_with_options<'life0, 'async_trait>(
        &'life0 mut self,
        options: StandardConnectInput,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Account>, WalletError>> + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
}
Expand description

Trait for wallets that support connecting to authorize accounts.

This trait defines methods for connecting to a wallet and authorizing accounts for use by the app. It provides both a simple connect method and a method that accepts connection options.

§Example Implementation

#[async_trait(?Send)]
impl WalletStandardConnect for MyWallet {
    async fn connect(&mut self) -> WalletResult<Vec<Self::Account>> {
        // Prompt the user to select accounts
        let selected_accounts = prompt_user_for_accounts();

        // Update the wallet's state
        self.current_account = selected_accounts.first().cloned();

        Ok(selected_accounts)
    }

    async fn connect_with_options(
        &mut self,
        options: StandardConnectInput,
    ) -> WalletResult<Vec<Self::Account>> {
        if options.silent.unwrap_or(false) {
            // Return previously authorized accounts without prompting
            Ok(self.authorized_accounts.clone())
        } else {
            // Prompt the user
            self.connect().await
        }
    }
}

Required Methods§

Source

fn connect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Account>, WalletError>> + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Connect to the wallet and authorize accounts.

This method prompts the user to authorize accounts for use by the app. It returns a list of authorized accounts and updates the wallet’s state to reflect the connection.

§Returns

A WalletResult containing a vector of authorized accounts if successful, or a WalletError if the connection fails.

§Errors

This method may return errors such as:

  • WalletError::WalletConnection if the connection fails
  • WalletError::WalletWindowClosed if the user closes the wallet window
  • WalletError::WalletWindowBlocked if the wallet window is blocked
Source

fn connect_with_options<'life0, 'async_trait>( &'life0 mut self, options: StandardConnectInput, ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Account>, WalletError>> + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Connect to the wallet with specific options.

This method allows more control over the connection process through the provided options. It can be used to request a silent connection without user prompts.

§Parameters
  • options - Connection options that control the behavior of the connection process
§Returns

A WalletResult containing a vector of authorized accounts if successful, or a WalletError if the connection fails.

§Errors

This method may return errors such as:

  • WalletError::WalletConnection if the connection fails
  • WalletError::WalletWindowClosed if the user closes the wallet window
  • WalletError::WalletWindowBlocked if the wallet window is blocked

Implementors§