Skip to content

Commit a802b1a

Browse files
committed
fix: auto connect should return true when connected to wallet
refactor: move connection manager into an internal construct
1 parent 5da7bbb commit a802b1a

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

packages/thirdweb/src/wallets/connection/autoConnect.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,39 @@ import { createWallet } from "../create-wallet.js";
33
import { getDefaultWallets } from "../defaultWallets.js";
44
import { getInstalledWalletProviders } from "../injected/mipdStore.js";
55
import type { Wallet } from "../interfaces/wallet.js";
6-
import type { ConnectionManager } from "../manager/index.js";
6+
import { createConnectionManager } from "../manager/index.js";
77
import { autoConnectCore } from "./autoConnectCore.js";
88
import type { AutoConnectProps } from "./types.js";
99

1010
/**
11-
* Attempts to automatically connect to a wallet based on the provided configuration.
11+
* Attempts to automatically connect to the last connected wallet.
1212
* It combines both specified wallets and installed wallet providers that aren't already specified.
1313
*
1414
* @example
1515
*
1616
* ```tsx
1717
* import { autoConnect } from "thirdweb/wallets";
1818
*
19-
* const walletManager = createConnectionManager();
2019
* const autoConnected = await autoConnect({
2120
* client,
22-
* walletManager,
21+
* onConnect: (wallet) => {
22+
* console.log("wallet", wallet);
23+
* },
2324
* });
2425
* ```
2526
*
26-
*
2727
* @param props - The auto-connect configuration properties
2828
* @param props.wallets - Array of wallet instances to consider for auto-connection
29-
* @param walletManager - The connection manager instance handling wallet connections
3029
* @returns {boolean} a promise resolving to true or false depending on whether the auto connect function connected to a wallet or not
3130
*/
3231
export const autoConnect = async (
3332
props: AutoConnectProps & {
34-
wallets: Wallet[];
35-
walletManager: ConnectionManager;
33+
wallets?: Wallet[];
3634
},
3735
) => {
3836
const wallets = props.wallets || getDefaultWallets(props);
39-
return autoConnectCore({
37+
const manager = createConnectionManager(webLocalStorage);
38+
const result = await autoConnectCore({
4039
storage: webLocalStorage,
4140
props: {
4241
...props,
@@ -53,6 +52,7 @@ export const autoConnect = async (
5352

5453
return installedWallets;
5554
},
56-
manager: props.walletManager,
55+
manager,
5756
});
57+
return result;
5858
};

packages/thirdweb/src/wallets/connection/autoConnectCore.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export const autoConnectCore = async ({
9292
// in that case, we default to the passed chain to connect to
9393
const lastConnectedChain =
9494
(await getLastConnectedChain(storage)) || props.chain;
95-
9695
const availableWallets = [...wallets, ...(getInstalledWallets?.() ?? [])];
9796
const activeWallet =
9897
lastActiveWalletId &&
@@ -127,15 +126,12 @@ export const autoConnectCore = async ({
127126
client: props.client,
128127
accountAbstraction: props.accountAbstraction,
129128
}));
130-
131129
if (connectedWallet) {
132-
if (onConnect) {
133-
try {
134-
onConnect(connectedWallet);
135-
autoConnected = true;
136-
} catch {
137-
// ignore
138-
}
130+
autoConnected = true;
131+
try {
132+
onConnect?.(connectedWallet);
133+
} catch {
134+
// ignore
139135
}
140136
} else {
141137
manager.activeWalletConnectionStatusStore.setValue("disconnected");

0 commit comments

Comments
 (0)