Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coinbase Wallet universal links #1016

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion packages/wallets/coinbase/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { EventEmitter, SendTransactionOptions, WalletName } from '@solana/wallet-adapter-base';
import {
BaseMessageSignerWalletAdapter,
isIosAndRedirectable,
isVersionedTransaction,
scopePollingDetectionStrategy,
WalletAccountError,
Expand All @@ -19,9 +20,9 @@ import type {
Connection,
SendOptions,
Transaction,
VersionedTransaction,
TransactionSignature,
TransactionVersion,
VersionedTransaction,
} from '@solana/web3.js';
import { PublicKey } from '@solana/web3.js';

Expand Down Expand Up @@ -75,6 +76,11 @@ export class CoinbaseWalletAdapter extends BaseMessageSignerWalletAdapter {
this._publicKey = null;

if (this._readyState !== WalletReadyState.Unsupported) {
if (isIosAndRedirectable()) {
// when in iOS (not webview), set Coinbase as loadable instead of checking for install
this._readyState = WalletReadyState.Loadable;
this.emit('readyStateChange', this._readyState);
}
scopePollingDetectionStrategy(() => {
if (window?.coinbaseSolana) {
this._readyState = WalletReadyState.Installed;
Expand All @@ -98,9 +104,26 @@ export class CoinbaseWalletAdapter extends BaseMessageSignerWalletAdapter {
return this._readyState;
}

async autoConnect(): Promise<void> {
// Skip autoconnect in the Loadable state
// We can't redirect to a universal link without user input
if (this.readyState === WalletReadyState.Installed) {
await this.connect();
}
}

async connect(): Promise<void> {
try {
if (this.connected || this.connecting) return;

if (this.readyState === WalletReadyState.Loadable) {
// redirect to the Coinbase /browse universal link
// this will open the current URL in the Coinbase in-app browser
const url = encodeURIComponent(window.location.href);
window.location.href = `https://go.cb-w.com/dapp?cb_url=${url}`;
return;
}

if (this._readyState !== WalletReadyState.Installed) throw new WalletNotReadyError();

this._connecting = true;
Expand Down
Loading