Manage wallet lifecycle states

Users can have multiple states in their wallet lifecycle: having a wallet, having wallet backups, having certain recovery methods available, and more.

After initializing Portal for your user, it's crucial to determine their wallet's lifecycle state to ensure a healthy wallet state. We provide several helper methods to easily derive the state of your users' wallets:

// Checks if the user has created a wallet on any device.
await portal.doesWalletExist()

// Checks if the user's wallet share is on their current device.
await portal.isWalletOnDevice()

These methods can be used together to understand the user's wallet state and determine the next steps. For example:

async function manageWalletState(portal: Portal): Promise<void> {
  try {
    // Determine the wallet's state.
    const walletExists = await portal.doesWalletExist();
    const walletExistsOnDevice = await portal.isWalletOnDevice();
    
    if (!walletExists) {
      // Create and back up the wallet using portal.createWallet() and portal.backup().
    } else if (!walletExistsOnDevice) {
      // Recover the wallet using portal.recover().
    } else {
      // The wallet is ready to use.
    }
  } catch (error) {
    // Handle any errors that occur.
  }
}

And that's it! You're now helping your users maintain a safe and secure experience with their wallets while using your apps.

Last updated