Skip to content

Commit ecd14b0

Browse files
cleanup
1 parent 51b9e6f commit ecd14b0

File tree

5 files changed

+127
-47
lines changed

5 files changed

+127
-47
lines changed

apps/playground-web/src/app/connect/sign-in/button/RightSection.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ import { XIcon } from "lucide-react";
33
import { usePathname } from "next/navigation";
44
import { useEffect, useState } from "react";
55
import {
6+
abstract,
7+
arbitrum,
68
arbitrumSepolia,
9+
base,
710
baseSepolia,
8-
defineChain,
11+
ethereum,
12+
optimism,
913
optimismSepolia,
14+
polygon,
1015
sepolia,
1116
} from "thirdweb/chains";
1217
import {
@@ -115,7 +120,12 @@ export function RightSection(props: {
115120
auth={connectOptions.enableAuth ? playgroundAuth : undefined}
116121
autoConnect={false}
117122
chains={[
118-
defineChain(578),
123+
base,
124+
ethereum,
125+
polygon,
126+
optimism,
127+
arbitrum,
128+
abstract,
119129
sepolia,
120130
baseSepolia,
121131
optimismSepolia,

apps/playground-web/src/components/styled-connect-button.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
import { useTheme } from "next-themes";
44
import {
55
abstract,
6+
arbitrum,
67
arbitrumSepolia,
8+
base,
79
baseSepolia,
10+
ethereum,
11+
optimism,
812
optimismSepolia,
13+
polygon,
914
polygonAmoy,
1015
sepolia,
1116
} from "thirdweb/chains";
@@ -28,6 +33,11 @@ export function StyledConnectButton(
2833
polygonAmoy,
2934
arbitrumSepolia,
3035
abstract,
36+
base,
37+
ethereum,
38+
polygon,
39+
optimism,
40+
arbitrum,
3141
]}
3242
client={THIRDWEB_CLIENT}
3343
theme={theme === "light" ? "light" : "dark"}

apps/playground-web/src/components/styled-connect-embed.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
import { useTheme } from "next-themes";
44
import {
5+
abstract,
6+
arbitrum,
57
arbitrumSepolia,
8+
base,
69
baseSepolia,
10+
ethereum,
11+
optimism,
712
optimismSepolia,
13+
polygon,
814
polygonAmoy,
915
sepolia,
1016
} from "thirdweb/chains";
@@ -35,6 +41,12 @@ export function StyledConnectEmbed(
3541
optimismSepolia,
3642
polygonAmoy,
3743
arbitrumSepolia,
44+
abstract,
45+
base,
46+
ethereum,
47+
polygon,
48+
optimism,
49+
arbitrum,
3850
]}
3951
client={THIRDWEB_CLIENT}
4052
theme={theme === "light" ? "light" : "dark"}

packages/thirdweb/package.json

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"@tanstack/react-query": "5.81.5",
2626
"@thirdweb-dev/engine": "workspace:*",
2727
"@thirdweb-dev/insight": "workspace:*",
28-
"@walletconnect/universal-provider": "2.21.4",
2928
"@walletconnect/sign-client": "2.20.1",
29+
"@walletconnect/universal-provider": "2.21.4",
3030
"abitype": "1.0.8",
3131
"cross-spawn": "7.0.6",
3232
"fuse.js": "7.1.0",
@@ -341,26 +341,66 @@
341341
"types": "./dist/types/exports/thirdweb.d.ts",
342342
"typesVersions": {
343343
"*": {
344-
"adapters/*": ["./dist/types/exports/adapters/*.d.ts"],
345-
"ai": ["./dist/types/exports/ai.d.ts"],
346-
"auth": ["./dist/types/exports/auth.d.ts"],
347-
"bridge": ["./dist/types/exports/bridge.d.ts"],
348-
"chains": ["./dist/types/exports/chains.d.ts"],
349-
"contract": ["./dist/types/exports/contract.d.ts"],
350-
"deploys": ["./dist/types/exports/deploys.d.ts"],
351-
"event": ["./dist/types/exports/event.d.ts"],
352-
"extensions/*": ["./dist/types/exports/extensions/*.d.ts"],
353-
"modules": ["./dist/types/exports/modules.d.ts"],
354-
"pay": ["./dist/types/exports/pay.d.ts"],
355-
"react": ["./dist/types/exports/react.d.ts"],
356-
"react-native": ["./dist/types/exports/react.native.d.ts"],
357-
"rpc": ["./dist/types/exports/rpc.d.ts"],
358-
"social": ["./dist/types/exports/social.d.ts"],
359-
"storage": ["./dist/types/exports/storage.d.ts"],
360-
"transaction": ["./dist/types/exports/transaction.d.ts"],
361-
"utils": ["./dist/types/exports/utils.d.ts"],
362-
"wallets": ["./dist/types/exports/wallets.d.ts"],
363-
"wallets/*": ["./dist/types/exports/wallets/*.d.ts"]
344+
"adapters/*": [
345+
"./dist/types/exports/adapters/*.d.ts"
346+
],
347+
"ai": [
348+
"./dist/types/exports/ai.d.ts"
349+
],
350+
"auth": [
351+
"./dist/types/exports/auth.d.ts"
352+
],
353+
"bridge": [
354+
"./dist/types/exports/bridge.d.ts"
355+
],
356+
"chains": [
357+
"./dist/types/exports/chains.d.ts"
358+
],
359+
"contract": [
360+
"./dist/types/exports/contract.d.ts"
361+
],
362+
"deploys": [
363+
"./dist/types/exports/deploys.d.ts"
364+
],
365+
"event": [
366+
"./dist/types/exports/event.d.ts"
367+
],
368+
"extensions/*": [
369+
"./dist/types/exports/extensions/*.d.ts"
370+
],
371+
"modules": [
372+
"./dist/types/exports/modules.d.ts"
373+
],
374+
"pay": [
375+
"./dist/types/exports/pay.d.ts"
376+
],
377+
"react": [
378+
"./dist/types/exports/react.d.ts"
379+
],
380+
"react-native": [
381+
"./dist/types/exports/react.native.d.ts"
382+
],
383+
"rpc": [
384+
"./dist/types/exports/rpc.d.ts"
385+
],
386+
"social": [
387+
"./dist/types/exports/social.d.ts"
388+
],
389+
"storage": [
390+
"./dist/types/exports/storage.d.ts"
391+
],
392+
"transaction": [
393+
"./dist/types/exports/transaction.d.ts"
394+
],
395+
"utils": [
396+
"./dist/types/exports/utils.d.ts"
397+
],
398+
"wallets": [
399+
"./dist/types/exports/wallets.d.ts"
400+
],
401+
"wallets/*": [
402+
"./dist/types/exports/wallets/*.d.ts"
403+
]
364404
}
365405
},
366406
"typings": "./dist/types/exports/thirdweb.d.ts",

packages/thirdweb/src/wallets/wallet-connect/controller.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ type SavedConnectParams = {
5858

5959
const ADD_ETH_CHAIN_METHOD = "wallet_addEthereumChain";
6060

61-
// const defaultShowQrModal = true; // Unused in UniversalProvider
62-
6361
const storageKeys = {
6462
lastUsedChainId: "tw.wc.lastUsedChainId",
6563
requestedChains: "tw.wc.requestedChains",
@@ -124,24 +122,39 @@ export async function connectWC(
124122
}
125123

126124
// For UniversalProvider, we still need chain configuration for session management
127-
const { requiredChain, optionalChains: chainsToRequest } = getChainsToRequest(
128-
{
129-
chain: chainToRequest,
130-
client: options.client,
131-
optionalChains: optionalChains,
132-
},
133-
);
125+
const { chains: chainsToRequest, rpcMap } = getChainsToRequest({
126+
chain: chainToRequest,
127+
client: options.client,
128+
optionalChains: optionalChains,
129+
});
134130

135131
// For UniversalProvider, we need to connect with namespaces
136132
if (provider.session) {
137133
await provider.connect({
138134
...(wcOptions?.pairingTopic
139135
? { pairingTopic: wcOptions?.pairingTopic }
140136
: {}),
137+
namespaces: {
138+
[NAMESPACE]: {
139+
chains: chainsToRequest,
140+
events: ["chainChanged", "accountsChanged"],
141+
methods: [
142+
"eth_sendTransaction",
143+
"eth_signTransaction",
144+
"eth_sign",
145+
"personal_sign",
146+
"eth_signTypedData",
147+
],
148+
rpcMap,
149+
},
150+
},
141151
});
142152
}
143153

144-
setRequestedChainsIds(chainsToRequest, storage);
154+
setRequestedChainsIds(
155+
chainsToRequest.map((x) => Number(x.split(":")[1])),
156+
storage,
157+
);
145158
// If session exists and chains are authorized, enable provider for required chain
146159
const addresses = await provider.enable();
147160
const address = addresses[0];
@@ -150,7 +163,7 @@ export async function connectWC(
150163
}
151164

152165
// For UniversalProvider, get chainId from the session namespaces
153-
const currentChainId = requiredChain?.id || chainsToRequest[0] || 1;
166+
const currentChainId = chainsToRequest[0] || 1;
154167
const providerChainId = normalizeChainId(currentChainId);
155168

156169
const chain =
@@ -264,8 +277,6 @@ async function initProvider(
264277
// });
265278

266279
const provider = await UniversalProvider.init({
267-
projectId: wcOptions?.projectId || DEFAULT_PROJECT_ID,
268-
relayUrl: "wss://relay.walletconnect.com",
269280
metadata: {
270281
description:
271282
wcOptions?.appMetadata?.description ||
@@ -276,6 +287,8 @@ async function initProvider(
276287
name: wcOptions?.appMetadata?.name || getDefaultAppMetadata().name,
277288
url: wcOptions?.appMetadata?.url || getDefaultAppMetadata().url,
278289
},
290+
projectId: wcOptions?.projectId || DEFAULT_PROJECT_ID,
291+
relayUrl: "wss://relay.walletconnect.com",
279292
});
280293

281294
provider.events.setMaxListeners(Number.POSITIVE_INFINITY);
@@ -540,26 +553,23 @@ async function getRequestedChainsIds(storage: AsyncStorage): Promise<number[]> {
540553
return data ? JSON.parse(data) : [];
541554
}
542555

543-
type ArrayOneOrMore<T> = {
544-
0: T;
545-
} & Array<T>;
546-
547556
function getChainsToRequest(options: {
548557
chain?: Chain;
549558
optionalChains?: Chain[];
550559
client: ThirdwebClient;
551560
}): {
552561
rpcMap: Record<number, string>;
553-
requiredChain: Chain | undefined;
554-
optionalChains: ArrayOneOrMore<number>;
562+
chains: string[];
555563
} {
556564
const rpcMap: Record<number, string> = {};
565+
const chainIds: number[] = [];
557566

558567
if (options.chain) {
559568
rpcMap[options.chain.id] = getRpcUrlForChain({
560569
chain: options.chain,
561570
client: options.client,
562571
});
572+
chainIds.push(options.chain.id);
563573
}
564574

565575
// limit optional chains to 10
@@ -570,18 +580,16 @@ function getChainsToRequest(options: {
570580
chain: chain,
571581
client: options.client,
572582
});
583+
chainIds.push(chain.id);
573584
}
574585

575586
if (!options.chain && optionalChains.length === 0) {
576587
rpcMap[1] = getCachedChain(1).rpc;
588+
chainIds.push(1);
577589
}
578590

579591
return {
580-
optionalChains:
581-
optionalChains.length > 0
582-
? (optionalChains.map((x) => x.id) as ArrayOneOrMore<number>)
583-
: [1],
584-
requiredChain: options.chain ? options.chain : undefined,
592+
chains: chainIds.map((x) => `eip155:${x}`),
585593
rpcMap,
586594
};
587595
}

0 commit comments

Comments
 (0)