Auto-Detection

WalletConnect calls the isInstalled() method on each registered wallet during initialization to verify it is properly installed. You must provide the implementation for this method.

The Provider Injection Pattern

Before implementing the isInstalled() method, review the provider injection pattern described in the Provider Injection section.

Implementing Provider Injection

  • Navigate to your wallet directory.
  • Open the controller.ts file.
  • Add a new local interface for your wallet that extends the Window class.
  • Declare the property your wallet injects to this interface.
The following code example is from OPWallet:
OPWalletWindow interfacetypescript
interface OPWalletWindow extends Window {
    opnet?: OPWallet;
}

Implementing isInstalled()

This method determines if the wallet is installed.

Suggested Implementation

  • Open the controller.ts file.
  • Add the isInstalled() method.
    A typical implementation follows this logic:
    • Cast the window object to your interface.
    • Get your wallet property on the casted interface.
    • Return true if the property exists; false otherwise.
The following code example is from OPWallet:
OPWallet isInstalled()typescript
class OPWallet implements WalletBase {
    ...
    isInstalled() : boolean {
        // Ensure that the window object exists (exists only on browser)
        if (typeof window === 'undefined') {
            return false;
        }

        // Check that the '.opnet' properties exists on the window object
        this.walletBase = (window as unknown as OPWalletWindow).opnet;
        return !!this.walletBase;
    }
    ...
}
When Auto Detection Runs

Auto-detection runs only after the window.load event fires. For more details on the detection process, see the Wallet Detection section.