Skip to content

Commit eca6217

Browse files
refactor: separate onConnectRequested impl between web and native (#3344)
1 parent df84f9c commit eca6217

File tree

12 files changed

+35
-31
lines changed

12 files changed

+35
-31
lines changed

packages/thirdweb/src/exports/wallets.native.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export type {
8282
InAppWalletSocialAuth as EmbeddedWalletSocialAuth,
8383
} from "../wallets/in-app/core/wallet/types.js";
8484

85-
export type { CoinbaseSDKWalletConnectionOptions } from "../wallets/coinbase/coinbaseSDKWallet.js";
85+
export type { CoinbaseSDKWalletConnectionOptions } from "../wallets/coinbase/coinbaseWebSDK.js";
8686

8787
export type {
8888
WalletEmitter,

packages/thirdweb/src/exports/wallets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export type {
8888
InAppWalletSocialAuth as EmbeddedWalletSocialAuth,
8989
} from "../wallets/in-app/core/wallet/types.js";
9090

91-
export type { CoinbaseSDKWalletConnectionOptions } from "../wallets/coinbase/coinbaseSDKWallet.js";
91+
export type { CoinbaseSDKWalletConnectionOptions } from "../wallets/coinbase/coinbaseWebSDK.js";
9292

9393
export type {
9494
WalletEmitter,

packages/thirdweb/src/react/web/utils/usePreloadWalletProviders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function usePreloadWalletProviders({
1616
switch (w.id) {
1717
case COINBASE: {
1818
const { getCoinbaseWebProvider } = await import(
19-
"../../../wallets/coinbase/coinbaseSDKWallet.js"
19+
"../../../wallets/coinbase/coinbaseWebSDK.js"
2020
);
2121
await getCoinbaseWebProvider();
2222
// return _something_

packages/thirdweb/src/wallets/coinbase/coinbase-wallet.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { CreateWalletArgs } from "../wallet-types.js";
1616
export function coinbaseWalletSDK(args: {
1717
createOptions?: CreateWalletArgs<typeof COINBASE>[1];
1818
providerFactory: () => Promise<ProviderInterface>;
19+
onConnectRequested?: (provider: ProviderInterface) => Promise<void>;
1920
}): Wallet<typeof COINBASE> {
2021
const { createOptions } = args;
2122
const emitter = createWalletEmitter<typeof COINBASE>();
@@ -58,7 +59,7 @@ export function coinbaseWalletSDK(args: {
5859
getAccount: () => account,
5960
autoConnect: async (options) => {
6061
const { autoConnectCoinbaseWalletSDK } = await import(
61-
"./coinbaseSDKWallet.js"
62+
"./coinbaseWebSDK.js"
6263
);
6364
const provider = await args.providerFactory();
6465
const [connectedAccount, connectedChain, doDisconnect, doSwitchChain] =
@@ -77,9 +78,7 @@ export function coinbaseWalletSDK(args: {
7778
return account;
7879
},
7980
connect: async (options) => {
80-
const { connectCoinbaseWalletSDK } = await import(
81-
"./coinbaseSDKWallet.js"
82-
);
81+
const { connectCoinbaseWalletSDK } = await import("./coinbaseWebSDK.js");
8382
const provider = await args.providerFactory();
8483
const [connectedAccount, connectedChain, doDisconnect, doSwitchChain] =
8584
await connectCoinbaseWalletSDK(options, emitter, provider);
@@ -105,15 +104,10 @@ export function coinbaseWalletSDK(args: {
105104
await handleSwitchChain(newChain);
106105
},
107106
onConnectRequested: async () => {
108-
// make sure to show the coinbase popup IMMEDIATELY on connection requested
109-
// otherwise the popup might get blocked in safari
110-
// TODO these 2 awaits are fast only thanks to preloading that happens in our components
111-
// these probably need to actually imported / created synchronously to be used headless properly
112-
const { getCoinbaseWebProvider, showCoinbasePopup } = await import(
113-
"./coinbaseSDKWallet.js"
114-
);
115-
const provider = await getCoinbaseWebProvider(createOptions);
116-
await showCoinbasePopup(provider);
107+
if (args.onConnectRequested) {
108+
const provider = await args.providerFactory();
109+
return args.onConnectRequested?.(provider);
110+
}
117111
},
118112
};
119113
}

packages/thirdweb/src/wallets/coinbase/coinbaseSDKWallet.ts renamed to packages/thirdweb/src/wallets/coinbase/coinbaseWebSDK.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type {
3838
CreateWalletArgs,
3939
WalletConnectionOption,
4040
} from "../wallet-types.js";
41+
import { showCoinbasePopup } from "./utils.js";
4142

4243
export type CoinbaseWalletCreationOptions =
4344
| {
@@ -344,11 +345,6 @@ function createAccount(provider: ProviderInterface, address: string) {
344345
return account;
345346
}
346347

347-
export async function showCoinbasePopup(provider: ProviderInterface) {
348-
// biome-ignore lint/suspicious/noExplicitAny: based on the latest CB SDK - scary but works
349-
await (provider as any).communicator?.waitForPopupLoaded();
350-
}
351-
352348
function onConnect(
353349
address: string,
354350
chain: Chain,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { ProviderInterface } from "@coinbase/wallet-sdk";
2+
3+
export async function showCoinbasePopup(provider: ProviderInterface) {
4+
// biome-ignore lint/suspicious/noExplicitAny: based on the latest CB SDK - scary but works
5+
await (provider as any)?.communicator?.waitForPopupLoaded();
6+
}

packages/thirdweb/src/wallets/create-wallet.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { webLocalStorage } from "../utils/storage/webStorage.js";
1616
import { isMobile } from "../utils/web/isMobile.js";
1717
import { openWindow } from "../utils/web/openWindow.js";
1818
import { coinbaseWalletSDK } from "./coinbase/coinbase-wallet.js";
19-
import { getCoinbaseWebProvider } from "./coinbase/coinbaseSDKWallet.js";
19+
import { getCoinbaseWebProvider } from "./coinbase/coinbaseWebSDK.js";
2020
import { COINBASE } from "./constants.js";
2121
import { inAppWallet } from "./in-app/web/in-app.js";
2222
import { smartWallet } from "./smart/smart-wallet.js";
@@ -74,6 +74,14 @@ export function createWallet<const ID extends WalletId>(
7474
return coinbaseWalletSDK({
7575
createOptions: options,
7676
providerFactory: () => getCoinbaseWebProvider(options),
77+
onConnectRequested: async (provider) => {
78+
// on the web, make sure to show the coinbase popup IMMEDIATELY on connection requested
79+
// otherwise the popup might get blocked in safari
80+
// TODO awaiting the provider is fast only thanks to preloading that happens in our components
81+
// these probably need to actually imported / created synchronously to be used headless properly
82+
const { showCoinbasePopup } = await import("./coinbase/utils.js");
83+
return showCoinbasePopup(provider);
84+
},
7785
}) as Wallet<ID>;
7886
}
7987

packages/thirdweb/src/wallets/eip5792/get-calls-status.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ThirdwebClient } from "../../client/client.js";
2-
import { isCoinbaseSDKWallet } from "../coinbase/coinbaseSDKWallet.js";
2+
import { isCoinbaseSDKWallet } from "../coinbase/coinbaseWebSDK.js";
33
import { isInAppWallet } from "../in-app/core/wallet/index.js";
44
import { getInjectedProvider } from "../injected/index.js";
55
import type { Wallet } from "../interfaces/wallet.js";
@@ -64,7 +64,7 @@ export async function getCallsStatus({
6464

6565
if (isCoinbaseSDKWallet(wallet)) {
6666
const { coinbaseSDKWalletGetCallsStatus } = await import(
67-
"../coinbase/coinbaseSDKWallet.js"
67+
"../coinbase/coinbaseWebSDK.js"
6868
);
6969
return coinbaseSDKWalletGetCallsStatus({ wallet, bundleId });
7070
}

packages/thirdweb/src/wallets/eip5792/get-capabilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Prettify } from "../../utils/type-utils.js";
2-
import { isCoinbaseSDKWallet } from "../coinbase/coinbaseSDKWallet.js";
2+
import { isCoinbaseSDKWallet } from "../coinbase/coinbaseWebSDK.js";
33
import { isInAppWallet } from "../in-app/core/wallet/index.js";
44
import { getInjectedProvider } from "../injected/index.js";
55
import type { Wallet } from "../interfaces/wallet.js";
@@ -62,7 +62,7 @@ export async function getCapabilities<const ID extends WalletId = WalletId>({
6262

6363
if (isCoinbaseSDKWallet(wallet)) {
6464
const { coinbaseSDKWalletGetCapabilities } = await import(
65-
"../coinbase/coinbaseSDKWallet.js"
65+
"../coinbase/coinbaseWebSDK.js"
6666
);
6767
return coinbaseSDKWalletGetCapabilities({ wallet });
6868
}

packages/thirdweb/src/wallets/eip5792/send-calls.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
resolvePromisedValue,
1212
} from "../../utils/promise/resolve-promised-value.js";
1313
import type { OneOf } from "../../utils/type-utils.js";
14-
import { isCoinbaseSDKWallet } from "../coinbase/coinbaseSDKWallet.js";
14+
import { isCoinbaseSDKWallet } from "../coinbase/coinbaseWebSDK.js";
1515
import { isInAppWallet } from "../in-app/core/wallet/index.js";
1616
import { getInjectedProvider } from "../injected/index.js";
1717
import type { Wallet } from "../interfaces/wallet.js";
@@ -181,7 +181,7 @@ export async function sendCalls<const ID extends WalletId>(
181181

182182
if (isCoinbaseSDKWallet(wallet)) {
183183
const { coinbaseSDKWalletSendCalls } = await import(
184-
"../coinbase/coinbaseSDKWallet.js"
184+
"../coinbase/coinbaseWebSDK.js"
185185
);
186186
return coinbaseSDKWalletSendCalls({
187187
wallet,

0 commit comments

Comments
 (0)