Skip to content

Commit 26692e0

Browse files
Fix Coinbase wallet transaction desktop popup for mobile QR login
1 parent 5f11ae0 commit 26692e0

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

.changeset/sixty-bobcats-add.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix cb wallet transaction desktop popup when logged in via mobile QR code

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ let _provider: ProviderInterface | undefined;
129129
* @internal
130130
*/
131131
export async function getCoinbaseWebProvider(
132-
options?: CreateWalletArgs<typeof COINBASE>[1],
132+
options?: CreateWalletArgs<typeof COINBASE>[1]
133133
): Promise<ProviderInterface> {
134134
if (!_provider) {
135135
let CoinbaseWalletSDK: unknown = (await import("@coinbase/wallet-sdk"))
@@ -169,7 +169,7 @@ export async function getCoinbaseWebProvider(
169169
* @returns True if the wallet is a Coinbase SDK wallet, false otherwise.
170170
*/
171171
export function isCoinbaseSDKWallet(
172-
wallet: Wallet,
172+
wallet: Wallet
173173
): wallet is Wallet<typeof COINBASE> {
174174
return wallet.id === COINBASE;
175175
}
@@ -188,7 +188,17 @@ function createAccount({
188188
onTransactionRequested: async () => {
189189
// make sure to show the coinbase popup BEFORE doing any transaction preprocessing
190190
// otherwise the popup might get blocked in safari
191-
await showCoinbasePopup(provider);
191+
// but only if using cb smart wallet (web based)
192+
if (window.localStorage) {
193+
// this is the local storage key for the signer type in the cb web sdk
194+
// value can be "scw" (web) or "walletlink" (mobile wallet)
195+
const signerType = window.localStorage.getItem(
196+
"-CBWSDK:SignerConfigurator:SignerType"
197+
);
198+
if (signerType === "scw") {
199+
await showCoinbasePopup(provider);
200+
}
201+
}
192202
},
193203
async sendTransaction(tx: SendTransactionOption) {
194204
const transactionHash = (await provider.request({
@@ -249,7 +259,7 @@ function createAccount({
249259
}
250260

251261
const { domain, message, primaryType } = parseTypedData(
252-
typedData,
262+
typedData
253263
) as ox__TypedData.Definition;
254264

255265
const types = {
@@ -281,7 +291,7 @@ function createAccount({
281291
try {
282292
const { callParams, chain } = await toProviderCallParams(
283293
options,
284-
account,
294+
account
285295
);
286296
const callId = await provider.request({
287297
method: "wallet_sendCalls",
@@ -294,7 +304,7 @@ function createAccount({
294304
} catch (error) {
295305
if (/unsupport|not support/i.test((error as Error).message)) {
296306
throw new Error(
297-
`${COINBASE} errored calling wallet_sendCalls, with error: ${error instanceof Error ? error.message : stringify(error)}`,
307+
`${COINBASE} errored calling wallet_sendCalls, with error: ${error instanceof Error ? error.message : stringify(error)}`
298308
);
299309
}
300310
throw error;
@@ -310,7 +320,7 @@ function createAccount({
310320
} catch (error) {
311321
if (/unsupport|not support/i.test((error as Error).message)) {
312322
throw new Error(
313-
`${COINBASE} does not support wallet_getCallsStatus, reach out to them directly to request EIP-5792 support.`,
323+
`${COINBASE} does not support wallet_getCallsStatus, reach out to them directly to request EIP-5792 support.`
314324
);
315325
}
316326
throw error;
@@ -345,7 +355,7 @@ function onConnect(
345355
chain: Chain,
346356
provider: ProviderInterface,
347357
emitter: WalletEmitter<typeof COINBASE>,
348-
client: ThirdwebClient,
358+
client: ThirdwebClient
349359
): [Account, Chain, DisconnectFn, SwitchChainFn] {
350360
const account = createAccount({ address, client, provider });
351361

@@ -399,7 +409,7 @@ function onConnect(
399409
export async function connectCoinbaseWalletSDK(
400410
options: WalletConnectionOption<typeof COINBASE>,
401411
emitter: WalletEmitter<typeof COINBASE>,
402-
provider: ProviderInterface,
412+
provider: ProviderInterface
403413
): Promise<ReturnType<typeof onConnect>> {
404414
const accounts = (await provider.request({
405415
method: "eth_requestAccounts",
@@ -435,7 +445,7 @@ export async function connectCoinbaseWalletSDK(
435445
export async function autoConnectCoinbaseWalletSDK(
436446
options: WalletConnectionOption<typeof COINBASE>,
437447
emitter: WalletEmitter<typeof COINBASE>,
438-
provider: ProviderInterface,
448+
provider: ProviderInterface
439449
): Promise<ReturnType<typeof onConnect>> {
440450
// connected accounts
441451
const addresses = (await provider.request({
@@ -462,7 +472,7 @@ export async function autoConnectCoinbaseWalletSDK(
462472

463473
async function switchChainCoinbaseWalletSDK(
464474
provider: ProviderInterface,
465-
chain: Chain,
475+
chain: Chain
466476
) {
467477
const chainIdHex = numberToHex(chain.id);
468478

packages/thirdweb/src/x402/fetchWithPayment.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export function wrapFetchWithPayment(
8282
parsedPaymentRequirements,
8383
chain.id,
8484
"exact",
85+
error,
8586
);
8687

8788
if (!selectedPaymentRequirements) {
@@ -141,10 +142,11 @@ function defaultPaymentRequirementsSelector(
141142
paymentRequirements: RequestedPaymentRequirements[],
142143
chainId: number,
143144
scheme: "exact",
145+
error?: string,
144146
) {
145147
if (!paymentRequirements.length) {
146148
throw new Error(
147-
"No valid payment requirements found in server 402 response",
149+
`No valid payment requirements found in server 402 response. ${error}`,
148150
);
149151
}
150152
const currentWalletNetwork = ChainIdToNetwork[chainId] || `eip155:${chainId}`;

0 commit comments

Comments
 (0)