|
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 { |
| 5 | + type Account, |
6 | 6 | EIP1193, |
7 | 7 | type InAppWalletConnectionOptions, |
8 | 8 | type InAppWalletCreationOptions, |
@@ -55,7 +55,7 @@ type StorageItem = { "tw.lastChainId": number }; |
55 | 55 | * inAppWalletConnector({ |
56 | 56 | * client, |
57 | 57 | * // optional: turn on smart accounts |
58 | | - * smartAccounts: { |
| 58 | + * smartAccount: { |
59 | 59 | * sponsorGas: true, |
60 | 60 | * chain: thirdwebChain(sepolia) |
61 | 61 | * } |
@@ -95,10 +95,21 @@ export function inAppWalletConnector( |
95 | 95 | connect: async (params) => { |
96 | 96 | const lastChainId = await config.storage?.getItem("tw.lastChainId"); |
97 | 97 | if (params?.isReconnecting) { |
98 | | - const account = await wallet.autoConnect({ |
| 98 | + const { autoConnect } = await import("thirdweb/wallets"); |
| 99 | + let account: Account | undefined; |
| 100 | + await autoConnect({ |
99 | 101 | client, |
100 | 102 | chain: defineChain(lastChainId || 1), |
| 103 | + wallets: [wallet], |
| 104 | + onConnect: (wallet) => { |
| 105 | + account = wallet.getAccount(); |
| 106 | + }, |
101 | 107 | }); |
| 108 | + |
| 109 | + if (!account) { |
| 110 | + throw new Error("Wallet failed to reconnect"); |
| 111 | + } |
| 112 | + |
102 | 113 | return { |
103 | 114 | accounts: [getAddress(account.address)], |
104 | 115 | chainId: lastChainId || 1, |
@@ -137,6 +148,7 @@ export function inAppWalletConnector( |
137 | 148 | const lastChainId = await config.storage?.getItem("tw.lastChainId"); |
138 | 149 | const chain = defineChain(params?.chainId || lastChainId || 1); |
139 | 150 | if (!wallet.getAccount()) { |
| 151 | + const { autoConnect } = await import("thirdweb/wallets"); |
140 | 152 | await autoConnect({ |
141 | 153 | client, |
142 | 154 | chain, |
|
0 commit comments