|
1 | 1 | import { type CreateConnectorFn, createConnector } from "@wagmi/core"; |
2 | 2 | import type { Prettify } from "@wagmi/core/chains"; |
3 | 3 | import { type ThirdwebClient, defineChain, getAddress } from "thirdweb"; |
4 | | -import { autoConnect } from "thirdweb/wallets"; |
5 | 4 | import { |
6 | 5 | EIP1193, |
7 | 6 | type InAppWalletConnectionOptions, |
@@ -55,7 +54,7 @@ type StorageItem = { "tw.lastChainId": number }; |
55 | 54 | * inAppWalletConnector({ |
56 | 55 | * client, |
57 | 56 | * // optional: turn on smart accounts |
58 | | - * smartAccounts: { |
| 57 | + * smartAccount: { |
59 | 58 | * sponsorGas: true, |
60 | 59 | * chain: thirdwebChain(sepolia) |
61 | 60 | * } |
@@ -95,10 +94,18 @@ export function inAppWalletConnector( |
95 | 94 | connect: async (params) => { |
96 | 95 | const lastChainId = await config.storage?.getItem("tw.lastChainId"); |
97 | 96 | if (params?.isReconnecting) { |
98 | | - const account = await wallet.autoConnect({ |
| 97 | + const { autoConnect } = await import("thirdweb/wallets"); |
| 98 | + await autoConnect({ |
99 | 99 | client, |
100 | 100 | chain: defineChain(lastChainId || 1), |
| 101 | + wallets: [wallet], |
101 | 102 | }); |
| 103 | + |
| 104 | + const account = wallet.getAccount(); |
| 105 | + if (!account) { |
| 106 | + throw new Error("Wallet failed to reconnect"); |
| 107 | + } |
| 108 | + |
102 | 109 | return { |
103 | 110 | accounts: [getAddress(account.address)], |
104 | 111 | chainId: lastChainId || 1, |
@@ -137,6 +144,7 @@ export function inAppWalletConnector( |
137 | 144 | const lastChainId = await config.storage?.getItem("tw.lastChainId"); |
138 | 145 | const chain = defineChain(params?.chainId || lastChainId || 1); |
139 | 146 | if (!wallet.getAccount()) { |
| 147 | + const { autoConnect } = await import("thirdweb/wallets"); |
140 | 148 | await autoConnect({ |
141 | 149 | client, |
142 | 150 | chain, |
|
0 commit comments