Detect Provider

Learn how to detect if the Gorbag wallet is available in the user's browser.

Detection Based on Wallet Adapter

The Gorbag wallet adapter uses detection strategies that check for wallet availability:

TYPESCRIPT
1// From the GorbagWalletAdapter source
2private _checkWalletReady(): boolean {
3 const isAvailable = !!(window.gorbag?.solana?.isGorbag || window.solana?.isGorbag);
4
5 if (isAvailable && this._readyState !== WalletReadyState.Installed) {
6 this.setReadyState(WalletReadyState.Installed);
7 } else if (!isAvailable && this._readyState !== WalletReadyState.NotDetected && this._readyState !== WalletReadyState.Unsupported) {
8 // Only set back to NotDetected if wallet is no longer available and not in Unsupported state
9 this.setReadyState(WalletReadyState.NotDetected);
10 }
11
12 return isAvailable;
13}

Detecting from Window Object

Check for the Gorbag wallet in the browser window:

JAVASCRIPT
1// Check if Gorbag provider is available
2export function isGorbagAvailable() {
3 if (typeof window !== 'undefined') {
4 // Check both possible locations
5 const isGorbagAvailable = !!(window.gorbag?.solana?.isGorbag || window.solana?.isGorbag);
6 return isGorbagAvailable;
7 }
8 return false;
9}
10
11// Usage
12if (isGorbagAvailable()) {
13 console.log('Gorbag wallet is available');
14} else {
15 console.log('Gorbag wallet is not available');
16}

Ready State Detection

The wallet adapter provides ready states to indicate wallet availability:

JAVASCRIPT
1import { useWallet } from '@solana/wallet-adapter-react';
2
3// Wallet ready states:
4// - Unsupported: Wallet is not supported on this platform
5// - NotDetected: Wallet is not installed
6// - Loadable: Wallet is available but requires loading (e.g., mobile)
7// - Installed: Wallet is installed and ready to use
8
9export function WalletStatus() {
10 const { wallets } = useWallet();
11
12 const gorbagWallet = wallets.find(wallet => wallet.adapter.name === 'Gorbag');
13
14 if (!gorbagWallet) {
15 return <div>Gorbag wallet not configured</div>;
16 }
17
18 const { readyState } = gorbagWallet;
19
20 return (
21 <div>
22 Gorbag Wallet State: {readyState}
23 {readyState === 'Installed' && <p>Wallet is ready to connect!</p>}
24 {readyState === 'NotDetected' && <p>Please install the Gorbag wallet extension</p>}
25 </div>
26 );
27}

Detection with Polling Strategy

The wallet adapter uses a polling strategy to detect wallet installation:

TYPESCRIPT
1// This is how the adapter detects the wallet automatically
2constructor(config: GorbagWalletAdapterConfig = {}) {
3 super();
4
5 if (this._readyState !== WalletReadyState.Unsupported) {
6 // Check immediately if wallet exists
7 setTimeout(() => {
8 this._checkWalletReady();
9 }, 0);
10
11 if (isIosAndRedirectable()) {
12 this.setReadyState(WalletReadyState.Loadable);
13 } else {
14 scopePollingDetectionStrategy(() => {
15 return this._checkWalletReady();
16 });
17 }
18 }
19}