Skip to content

Commit ef99d0f

Browse files
committed
fix(sdk): wagmi adapter autoconnecting
1 parent 1d844ac commit ef99d0f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/wagmi-adapter/src/connector.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { type CreateConnectorFn, createConnector } from "@wagmi/core";
22
import type { Prettify } from "@wagmi/core/chains";
33
import { type ThirdwebClient, defineChain, getAddress } from "thirdweb";
4-
import { autoConnect } from "thirdweb/wallets";
54
import {
5+
type Account,
66
EIP1193,
77
type InAppWalletConnectionOptions,
88
type InAppWalletCreationOptions,
@@ -55,7 +55,7 @@ type StorageItem = { "tw.lastChainId": number };
5555
* inAppWalletConnector({
5656
* client,
5757
* // optional: turn on smart accounts
58-
* smartAccounts: {
58+
* smartAccount: {
5959
* sponsorGas: true,
6060
* chain: thirdwebChain(sepolia)
6161
* }
@@ -95,10 +95,21 @@ export function inAppWalletConnector(
9595
connect: async (params) => {
9696
const lastChainId = await config.storage?.getItem("tw.lastChainId");
9797
if (params?.isReconnecting) {
98-
const account = await wallet.autoConnect({
98+
const { autoConnect } = await import("thirdweb/wallets");
99+
let account: Account | undefined;
100+
await autoConnect({
99101
client,
100102
chain: defineChain(lastChainId || 1),
103+
wallets: [wallet],
104+
onConnect: (wallet) => {
105+
account = wallet.getAccount();
106+
},
101107
});
108+
109+
if (!account) {
110+
throw new Error("Wallet failed to reconnect");
111+
}
112+
102113
return {
103114
accounts: [getAddress(account.address)],
104115
chainId: lastChainId || 1,
@@ -137,6 +148,7 @@ export function inAppWalletConnector(
137148
const lastChainId = await config.storage?.getItem("tw.lastChainId");
138149
const chain = defineChain(params?.chainId || lastChainId || 1);
139150
if (!wallet.getAccount()) {
151+
const { autoConnect } = await import("thirdweb/wallets");
140152
await autoConnect({
141153
client,
142154
chain,

0 commit comments

Comments
 (0)