Skip to content

Commit 26d008f

Browse files
Update viem to 2.39.0 and wagmi to 2.19.4
1 parent f07b4b5 commit 26d008f

File tree

10 files changed

+902
-223
lines changed

10 files changed

+902
-223
lines changed

.changeset/few-hats-slide.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+
Better handling of erc5792 getCapabilities

.changeset/sixty-views-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/wagmi-adapter": patch
3+
---
4+
5+
Better handling of autoconnect to last connected chain

apps/wagmi-demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"react": "19.1.0",
1818
"react-dom": "19.1.0",
1919
"thirdweb": "workspace:*",
20-
"viem": "2.37.9",
21-
"wagmi": "2.17.5"
20+
"viem": "2.39.0",
21+
"wagmi": "2.19.4"
2222
},
2323
"devDependencies": {
2424
"@biomejs/biome": "2.0.6",

apps/wagmi-demo/src/App.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import type { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
2-
import { ConnectButton } from "thirdweb/react";
2+
import {
3+
ConnectButton,
4+
useActiveAccount,
5+
useCapabilities as useThirdwebCapabilities,
6+
} from "thirdweb/react";
7+
import { createWallet } from "thirdweb/wallets";
38
import {
49
useAccount,
510
useCallsStatus,
11+
useCapabilities,
612
useConnect,
713
useDisconnect,
814
useSendCalls,
@@ -12,6 +18,8 @@ import { chain, client, thirdwebChainForWallet, wallet } from "./wagmi.js";
1218

1319
function App() {
1420
const account = useAccount();
21+
const twAccount = useActiveAccount();
22+
1523
const { connectors, connect, status, error } = useConnect();
1624
const { disconnect } = useDisconnect();
1725
const {
@@ -33,6 +41,10 @@ function App() {
3341
enabled: !!data?.id,
3442
},
3543
});
44+
const capabilities = useCapabilities();
45+
const thirdwebCapabilities = useThirdwebCapabilities();
46+
console.log("wagmi capabilities", capabilities.error, capabilities.data);
47+
console.log("thirdweb capabilities", thirdwebCapabilities.error, thirdwebCapabilities.data);
3648
return (
3749
<>
3850
<div>
@@ -58,7 +70,12 @@ function App() {
5870
<ConnectButton
5971
client={client}
6072
chain={thirdwebChainForWallet}
61-
wallets={[wallet]}
73+
wallets={[
74+
wallet,
75+
createWallet("io.metamask"),
76+
createWallet("com.coinbase.wallet"),
77+
createWallet("me.rainbow"),
78+
]}
6279
onConnect={(wallet) => {
6380
// auto connect to wagmi on tw connect
6481
const twConnector = connectors.find(

packages/thirdweb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"qrcode": "1.5.3",
3939
"toml": "3.0.0",
4040
"uqr": "0.1.2",
41-
"viem": "2.37.9",
41+
"viem": "2.39.0",
4242
"x402": "0.7.0",
4343
"zod": "3.25.75"
4444
},

packages/thirdweb/src/adapters/eip1193/to-eip1193.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,17 @@ export function toProvider(options: ToEip1193ProviderOptions): EIP1193Provider {
164164
if (!account.getCapabilities) {
165165
throw new Error("Wallet does not support EIP-5792");
166166
}
167-
return account.getCapabilities({ chainId: chain.id });
167+
const chains = request.params[1];
168+
if (chains && Array.isArray(chains)) {
169+
const firstChainStr = chains[0];
170+
const firstChainId = isHex(firstChainStr)
171+
? hexToNumber(firstChainStr)
172+
: Number(firstChainStr);
173+
return account.getCapabilities(
174+
firstChainId ? { chainId: firstChainId } : {},
175+
);
176+
}
177+
return account.getCapabilities({});
168178
}
169179
case "wallet_sendCalls": {
170180
const account = wallet.getAccount();

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function getCapabilities<const ID extends WalletId = WalletId>({
5454

5555
export function toGetCapabilitiesResult(
5656
result: Record<string, WalletCapabilities>,
57-
chainId?: number,
57+
chainIdFilter?: number,
5858
): GetCapabilitiesResult {
5959
const capabilities = {} as WalletCapabilitiesRecord<
6060
WalletCapabilities,
@@ -69,6 +69,8 @@ export function toGetCapabilitiesResult(
6969
capabilities[Number(chainId)] = capabilitiesCopy;
7070
}
7171
return (
72-
typeof chainId === "number" ? capabilities[chainId] : capabilities
72+
typeof chainIdFilter === "number"
73+
? { [chainIdFilter]: capabilities[chainIdFilter] }
74+
: capabilities
7375
) as never;
7476
}

packages/thirdweb/src/wallets/injected/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,13 @@ function createAccount({
374374
}
375375
},
376376
async getCapabilities(options) {
377-
const chainId = options.chainId;
377+
const chainIdFilter = options.chainId;
378378
try {
379379
const result = await provider.request({
380380
method: "wallet_getCapabilities",
381381
params: [getAddress(account.address)],
382382
});
383-
return toGetCapabilitiesResult(result, chainId);
383+
return toGetCapabilitiesResult(result, chainIdFilter);
384384
} catch (error: unknown) {
385385
if (
386386
/unsupport|not support|not available/i.test((error as Error).message)

packages/wagmi-adapter/src/connector.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { type CreateConnectorFn, createConnector } from "@wagmi/core";
22
import type { Prettify } from "@wagmi/core/chains";
3-
import { defineChain, getAddress, type ThirdwebClient } from "thirdweb";
3+
import {
4+
type Chain,
5+
defineChain,
6+
getAddress,
7+
type ThirdwebClient,
8+
} from "thirdweb";
49
import {
510
EIP1193,
611
ecosystemWallet,
@@ -53,6 +58,7 @@ type StorageItem = {
5358

5459
const activeWalletIdKey = "thirdweb:active-wallet-id";
5560
const connectedWalletIdsKey = "thirdweb:connected-wallet-ids";
61+
const activeChainIdKey = "thirdweb:active-chain";
5662

5763
/**
5864
* Connect to an in-app wallet using the auth strategy of your choice.
@@ -112,13 +118,14 @@ export function inAppWalletConnector(
112118
? window.localStorage
113119
: undefined;
114120
return createConnector((config) => ({
115-
connect: async (params?: ConnectionOptions<false>) => {
121+
connect: async (params) => {
116122
wallet =
117123
params && "wallet" in params ? (params.wallet as Wallet) : wallet;
118-
const lastChainIdStr = await config.storage?.getItem(
119-
"thirdweb:lastChainId",
120-
);
121-
const lastChainId = lastChainIdStr ? Number(lastChainIdStr) : undefined;
124+
const lastChainIdStr = rawStorage?.getItem(activeChainIdKey);
125+
const lastChain = lastChainIdStr
126+
? (JSON.parse(lastChainIdStr) as Chain)
127+
: undefined;
128+
const lastChainId = lastChain ? lastChain.id : undefined;
122129
if (params?.isReconnecting) {
123130
const { autoConnect } = await import("thirdweb/wallets");
124131
const chainId = lastChainId || args.smartAccount?.chain?.id || 1;
@@ -133,7 +140,6 @@ export function inAppWalletConnector(
133140
if (!account) {
134141
throw new Error("Wallet failed to reconnect");
135142
}
136-
137143
return {
138144
accounts: [getAddress(account.address)] as any,
139145
chainId: chainId,
@@ -144,7 +150,7 @@ export function inAppWalletConnector(
144150
const alreadyConnectedAccount = wallet.getAccount();
145151
if (alreadyConnectedAccount) {
146152
return {
147-
accounts: [getAddress(alreadyConnectedAccount.address)],
153+
accounts: [getAddress(alreadyConnectedAccount.address)] as any,
148154
chainId: wallet.getChain()?.id || 1,
149155
};
150156
}
@@ -191,9 +197,11 @@ export function inAppWalletConnector(
191197
}
192198
rawStorage.setItem(activeWalletIdKey, wallet.id);
193199
}
194-
await config.storage?.setItem("thirdweb:lastChainId", chain.id);
195200
args.onConnect?.(wallet);
196-
return { accounts: [getAddress(account.address)], chainId: chain.id };
201+
return {
202+
accounts: [getAddress(account.address)] as any,
203+
chainId: chain.id,
204+
};
197205
},
198206
disconnect: async () => {
199207
await wallet.disconnect();
@@ -209,9 +217,7 @@ export function inAppWalletConnector(
209217
return wallet.getChain()?.id || 1;
210218
},
211219
getProvider: async (params) => {
212-
const lastChainIdStr = await config.storage?.getItem(
213-
"thirdweb:lastChainId",
214-
);
220+
const lastChainIdStr = await rawStorage?.getItem(activeChainIdKey);
215221
const lastChainId = lastChainIdStr ? Number(lastChainIdStr) : undefined;
216222
const chain = defineChain(
217223
params?.chainId || args.smartAccount?.chain?.id || lastChainId || 1,
@@ -262,7 +268,10 @@ export function inAppWalletConnector(
262268
config.emitter.emit("change", {
263269
chainId: chain.id,
264270
});
265-
await config.storage?.setItem("thirdweb:lastChainId", chain.id);
271+
rawStorage?.setItem(
272+
activeChainIdKey,
273+
JSON.stringify(defineChain(chain.id)),
274+
);
266275
return chain;
267276
},
268277
type: "in-app",

0 commit comments

Comments
 (0)