thirdweb 5.111.11-nightly-eb1a9c3c3e670290e28ad86e14ddae4c7cf7455d-20251112000353 → 5.112.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/exports/react.js.map +1 -1
- package/dist/cjs/exports/react.native.js.map +1 -1
- package/dist/cjs/react/core/hooks/connection/types.js +3 -0
- package/dist/cjs/react/core/hooks/connection/types.js.map +1 -0
- package/dist/cjs/react/core/hooks/wallets/useAuthToken.js +11 -10
- package/dist/cjs/react/core/hooks/wallets/useAuthToken.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectModal.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectModalContent.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectModalContent.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/useConnectModal.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/cjs/wallets/connection/autoConnect.js +3 -2
- package/dist/cjs/wallets/connection/autoConnect.js.map +1 -1
- package/dist/cjs/wallets/connection/autoConnectCore.js +15 -13
- package/dist/cjs/wallets/connection/autoConnectCore.js.map +1 -1
- package/dist/cjs/wallets/manager/index.js +2 -2
- package/dist/cjs/wallets/manager/index.js.map +1 -1
- package/dist/esm/exports/react.js.map +1 -1
- package/dist/esm/exports/react.native.js.map +1 -1
- package/dist/esm/react/core/hooks/connection/types.js +2 -0
- package/dist/esm/react/core/hooks/connection/types.js.map +1 -0
- package/dist/esm/react/core/hooks/wallets/useAuthToken.js +11 -10
- package/dist/esm/react/core/hooks/wallets/useAuthToken.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectModal.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectModalContent.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectModalContent.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/useConnectModal.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/wallets/connection/autoConnect.js +3 -2
- package/dist/esm/wallets/connection/autoConnect.js.map +1 -1
- package/dist/esm/wallets/connection/autoConnectCore.js +15 -13
- package/dist/esm/wallets/connection/autoConnectCore.js.map +1 -1
- package/dist/esm/wallets/manager/index.js +2 -2
- package/dist/esm/wallets/manager/index.js.map +1 -1
- package/dist/scripts/bridge-widget.js +4 -4
- package/dist/types/exports/react.d.ts +1 -0
- package/dist/types/exports/react.d.ts.map +1 -1
- package/dist/types/exports/react.native.d.ts +3 -1
- package/dist/types/exports/react.native.d.ts.map +1 -1
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts +5 -3
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts.map +1 -1
- package/dist/types/react/core/hooks/connection/ConnectEmbedProps.d.ts +5 -3
- package/dist/types/react/core/hooks/connection/ConnectEmbedProps.d.ts.map +1 -1
- package/dist/types/react/core/hooks/connection/types.d.ts +3 -0
- package/dist/types/react/core/hooks/connection/types.d.ts.map +1 -0
- package/dist/types/react/core/hooks/wallets/useAuthToken.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectModal.d.ts +2 -1
- package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectModal.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectModalContent.d.ts +2 -1
- package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectModalContent.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/useConnectModal.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/dist/types/wallets/connection/autoConnect.d.ts +3 -2
- package/dist/types/wallets/connection/autoConnect.d.ts.map +1 -1
- package/dist/types/wallets/connection/autoConnectCore.d.ts.map +1 -1
- package/dist/types/wallets/connection/types.d.ts +4 -3
- package/dist/types/wallets/connection/types.d.ts.map +1 -1
- package/dist/types/wallets/manager/index.d.ts +2 -1
- package/dist/types/wallets/manager/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/exports/react.native.ts +7 -0
- package/src/exports/react.ts +1 -0
- package/src/react/core/hooks/connection/ConnectButtonProps.ts +5 -3
- package/src/react/core/hooks/connection/ConnectEmbedProps.ts +5 -3
- package/src/react/core/hooks/connection/types.ts +6 -0
- package/src/react/core/hooks/wallets/useAuthToken.ts +19 -12
- package/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx +2 -1
- package/src/react/web/ui/ConnectWallet/Modal/ConnectModal.tsx +2 -1
- package/src/react/web/ui/ConnectWallet/Modal/ConnectModalContent.tsx +3 -2
- package/src/react/web/ui/ConnectWallet/useConnectModal.tsx +2 -1
- package/src/version.ts +1 -1
- package/src/wallets/connection/autoConnect.ts +3 -2
- package/src/wallets/connection/autoConnectCore.test.ts +26 -19
- package/src/wallets/connection/autoConnectCore.ts +15 -11
- package/src/wallets/connection/types.ts +4 -3
- package/src/wallets/manager/connection-manager.test.ts +1 -1
- package/src/wallets/manager/index.ts +4 -3
|
@@ -17,8 +17,9 @@ import type { AutoConnectProps } from "./types.js";
|
|
|
17
17
|
*
|
|
18
18
|
* const autoConnected = await autoConnect({
|
|
19
19
|
* client,
|
|
20
|
-
* onConnect: (
|
|
21
|
-
* console.log("wallet",
|
|
20
|
+
* onConnect: (activeWallet, allConnectedWallets) => {
|
|
21
|
+
* console.log("active wallet", activeWallet);
|
|
22
|
+
* console.log("all connected wallets", allConnectedWallets);
|
|
22
23
|
* },
|
|
23
24
|
* });
|
|
24
25
|
* ```
|
|
@@ -19,6 +19,23 @@ describe("useAutoConnectCore", () => {
|
|
|
19
19
|
const mockStorage = new MockStorage();
|
|
20
20
|
const manager = createConnectionManager(mockStorage);
|
|
21
21
|
|
|
22
|
+
const wallet1 = createWalletAdapter({
|
|
23
|
+
adaptedAccount: TEST_ACCOUNT_A,
|
|
24
|
+
chain: ethereum,
|
|
25
|
+
client: TEST_CLIENT,
|
|
26
|
+
onDisconnect: () => {},
|
|
27
|
+
switchChain: () => {},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const wallet2 = createWalletAdapter({
|
|
31
|
+
adaptedAccount: { ...TEST_ACCOUNT_A, address: "0x123" },
|
|
32
|
+
chain: ethereum,
|
|
33
|
+
client: TEST_CLIENT,
|
|
34
|
+
onDisconnect: () => {},
|
|
35
|
+
switchChain: () => {},
|
|
36
|
+
});
|
|
37
|
+
wallet2.id = "io.metamask" as unknown as "adapter";
|
|
38
|
+
|
|
22
39
|
afterEach(() => {
|
|
23
40
|
vi.restoreAllMocks();
|
|
24
41
|
});
|
|
@@ -161,23 +178,6 @@ describe("useAutoConnectCore", () => {
|
|
|
161
178
|
});
|
|
162
179
|
|
|
163
180
|
it("should connect multiple wallets correctly", async () => {
|
|
164
|
-
const wallet1 = createWalletAdapter({
|
|
165
|
-
adaptedAccount: TEST_ACCOUNT_A,
|
|
166
|
-
chain: ethereum,
|
|
167
|
-
client: TEST_CLIENT,
|
|
168
|
-
onDisconnect: () => {},
|
|
169
|
-
switchChain: () => {},
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const wallet2 = createWalletAdapter({
|
|
173
|
-
adaptedAccount: { ...TEST_ACCOUNT_A, address: "0x123" },
|
|
174
|
-
chain: ethereum,
|
|
175
|
-
client: TEST_CLIENT,
|
|
176
|
-
onDisconnect: () => {},
|
|
177
|
-
switchChain: () => {},
|
|
178
|
-
});
|
|
179
|
-
wallet2.id = "io.metamask" as unknown as "adapter";
|
|
180
|
-
|
|
181
181
|
mockStorage.setItem("thirdweb:active-wallet-id", wallet1.id);
|
|
182
182
|
mockStorage.setItem(
|
|
183
183
|
"thirdweb:connected-wallet-ids",
|
|
@@ -228,7 +228,10 @@ describe("useAutoConnectCore", () => {
|
|
|
228
228
|
storage: mockStorage,
|
|
229
229
|
});
|
|
230
230
|
|
|
231
|
-
expect(mockOnConnect).toHaveBeenCalledWith(
|
|
231
|
+
expect(mockOnConnect).toHaveBeenCalledWith(
|
|
232
|
+
wallet,
|
|
233
|
+
manager.connectedWallets.getValue(),
|
|
234
|
+
);
|
|
232
235
|
});
|
|
233
236
|
|
|
234
237
|
it("should continue even if onConnect callback throws", async () => {
|
|
@@ -262,7 +265,10 @@ describe("useAutoConnectCore", () => {
|
|
|
262
265
|
storage: mockStorage,
|
|
263
266
|
});
|
|
264
267
|
|
|
265
|
-
expect(mockOnConnect).toHaveBeenCalledWith(
|
|
268
|
+
expect(mockOnConnect).toHaveBeenCalledWith(
|
|
269
|
+
wallet,
|
|
270
|
+
manager.connectedWallets.getValue(),
|
|
271
|
+
);
|
|
266
272
|
});
|
|
267
273
|
|
|
268
274
|
it("should call setLastAuthProvider if authProvider is present", async () => {
|
|
@@ -300,6 +306,7 @@ describe("useAutoConnectCore", () => {
|
|
|
300
306
|
});
|
|
301
307
|
|
|
302
308
|
it("should set connection status to disconnect if no connectedWallet is returned", async () => {
|
|
309
|
+
manager.activeWalletStore.setValue(undefined);
|
|
303
310
|
const wallet = createWalletAdapter({
|
|
304
311
|
adaptedAccount: TEST_ACCOUNT_A,
|
|
305
312
|
chain: ethereum,
|
|
@@ -152,22 +152,12 @@ const _autoConnectCore = async ({
|
|
|
152
152
|
|
|
153
153
|
try {
|
|
154
154
|
// connected wallet could be activeWallet or smart wallet
|
|
155
|
-
|
|
155
|
+
await (connectOverride
|
|
156
156
|
? connectOverride(activeWallet)
|
|
157
157
|
: manager.connect(activeWallet, {
|
|
158
158
|
accountAbstraction: props.accountAbstraction,
|
|
159
159
|
client: props.client,
|
|
160
160
|
}));
|
|
161
|
-
if (connectedWallet) {
|
|
162
|
-
autoConnected = true;
|
|
163
|
-
try {
|
|
164
|
-
onConnect?.(connectedWallet);
|
|
165
|
-
} catch {
|
|
166
|
-
// ignore
|
|
167
|
-
}
|
|
168
|
-
} else {
|
|
169
|
-
manager.activeWalletConnectionStatusStore.setValue("disconnected");
|
|
170
|
-
}
|
|
171
161
|
} catch (e) {
|
|
172
162
|
if (e instanceof Error) {
|
|
173
163
|
console.warn("Error auto connecting wallet:", e.message);
|
|
@@ -216,6 +206,20 @@ const _autoConnectCore = async ({
|
|
|
216
206
|
});
|
|
217
207
|
}
|
|
218
208
|
manager.isAutoConnecting.setValue(false);
|
|
209
|
+
|
|
210
|
+
const connectedActiveWallet = manager.activeWalletStore.getValue();
|
|
211
|
+
const allConnectedWallets = manager.connectedWallets.getValue();
|
|
212
|
+
if (connectedActiveWallet) {
|
|
213
|
+
autoConnected = true;
|
|
214
|
+
try {
|
|
215
|
+
onConnect?.(connectedActiveWallet, allConnectedWallets);
|
|
216
|
+
} catch (e) {
|
|
217
|
+
console.error("Error calling onConnect callback:", e);
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
manager.activeWalletConnectionStatusStore.setValue("disconnected");
|
|
221
|
+
}
|
|
222
|
+
|
|
219
223
|
return autoConnected; // useQuery needs a return value
|
|
220
224
|
};
|
|
221
225
|
|
|
@@ -101,13 +101,14 @@ export type AutoConnectProps = {
|
|
|
101
101
|
*
|
|
102
102
|
* ```tsx
|
|
103
103
|
* <AutoConnect
|
|
104
|
-
* onConnect={(
|
|
105
|
-
* console.log("auto connected to",
|
|
104
|
+
* onConnect={(activeWallet, otherWallets) => {
|
|
105
|
+
* console.log("auto connected to", activeWallet)
|
|
106
|
+
* console.log("other wallets that were also connected", otherWallets)
|
|
106
107
|
* }}
|
|
107
108
|
* />
|
|
108
109
|
* ```
|
|
109
110
|
*/
|
|
110
|
-
onConnect?: (
|
|
111
|
+
onConnect?: (activeWallet: Wallet, otherWallets: Wallet[]) => void;
|
|
111
112
|
|
|
112
113
|
/**
|
|
113
114
|
* Optional chain to autoconnect to
|
|
@@ -49,7 +49,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("Connection Manager", () => {
|
|
|
49
49
|
|
|
50
50
|
await manager.connect(wallet, { client, onConnect });
|
|
51
51
|
|
|
52
|
-
expect(onConnect).toHaveBeenCalledWith(wallet);
|
|
52
|
+
expect(onConnect).toHaveBeenCalledWith(wallet, [wallet]);
|
|
53
53
|
expect(storage.setItem).toHaveBeenCalled();
|
|
54
54
|
});
|
|
55
55
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Chain } from "../../chains/types.js";
|
|
2
2
|
import { cacheChains } from "../../chains/utils.js";
|
|
3
3
|
import type { ThirdwebClient } from "../../client/client.js";
|
|
4
|
+
import type { OnConnectCallback } from "../../react/core/hooks/connection/types.js";
|
|
4
5
|
import { computedStore } from "../../reactive/computedStore.js";
|
|
5
6
|
import { effect } from "../../reactive/effect.js";
|
|
6
7
|
import { createStore } from "../../reactive/store.js";
|
|
@@ -29,7 +30,7 @@ export type ConnectManagerOptions = {
|
|
|
29
30
|
client: ThirdwebClient;
|
|
30
31
|
accountAbstraction?: SmartWalletOptions;
|
|
31
32
|
setWalletAsActive?: boolean;
|
|
32
|
-
onConnect?:
|
|
33
|
+
onConnect?: OnConnectCallback;
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
/**
|
|
@@ -158,7 +159,7 @@ export function createConnectionManager(storage: AsyncStorage) {
|
|
|
158
159
|
wallet.subscribe("accountChanged", async () => {
|
|
159
160
|
// We reimplement connect here to prevent memory leaks
|
|
160
161
|
const newWallet = await handleConnection(wallet, options);
|
|
161
|
-
options?.onConnect?.(newWallet);
|
|
162
|
+
options?.onConnect?.(newWallet, connectedWallets.getValue());
|
|
162
163
|
});
|
|
163
164
|
|
|
164
165
|
return activeWallet;
|
|
@@ -167,7 +168,7 @@ export function createConnectionManager(storage: AsyncStorage) {
|
|
|
167
168
|
const connect = async (wallet: Wallet, options?: ConnectManagerOptions) => {
|
|
168
169
|
// connectedWallet can be either wallet or smartWallet
|
|
169
170
|
const connectedWallet = await handleConnection(wallet, options);
|
|
170
|
-
options?.onConnect?.(connectedWallet);
|
|
171
|
+
options?.onConnect?.(connectedWallet, connectedWallets.getValue());
|
|
171
172
|
return connectedWallet;
|
|
172
173
|
};
|
|
173
174
|
|