Skip to content

Commit e160deb

Browse files
[SDK] Fix wallet reconnection for previously connected wallets (#8066)
1 parent a6f846f commit e160deb

File tree

10 files changed

+19
-38
lines changed

10 files changed

+19
-38
lines changed

.changeset/clean-wings-repeat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Always reconnect any previously connected wallet properly

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/components/client/live-stats.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ export function ChainLiveStats(props: { rpc: string }) {
203203
>
204204
{eip7702Support.data ? (
205205
eip7702Support.data.isSupported ? (
206-
"Enabled"
206+
"Available"
207207
) : (
208-
"Disabled"
208+
"Not Available"
209209
)
210210
) : eip7702Support.isError ? (
211-
"Disabled"
211+
"Not Available"
212212
) : (
213213
<div className="flex h-[28px] w-[80px] py-1">
214214
<Skeleton className="h-full w-full" />

packages/thirdweb/src/react/core/hooks/wallets/useAutoConnect.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export function useAutoConnectCore(
1414
storage: AsyncStorage,
1515
props: AutoConnectProps & { wallets: Wallet[] },
1616
createWalletFn: (id: WalletId) => Wallet,
17-
getInstalledWallets?: () => Wallet[],
1817
) {
1918
const manager = useConnectionManagerCtx("useAutoConnect");
2019
const { connect } = useConnect({
@@ -28,7 +27,6 @@ export function useAutoConnectCore(
2827
autoConnectCore({
2928
connectOverride: connect,
3029
createWalletFn,
31-
getInstalledWallets,
3230
manager,
3331
props,
3432
setLastAuthProvider,

packages/thirdweb/src/react/web/hooks/wallets/useAutoConnect.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { webLocalStorage } from "../../../../utils/storage/webStorage.js";
22
import type { AutoConnectProps } from "../../../../wallets/connection/types.js";
33
import { createWallet } from "../../../../wallets/create-wallet.js";
44
import { getDefaultWallets } from "../../../../wallets/defaultWallets.js";
5-
import { getInstalledWalletProviders } from "../../../../wallets/injected/mipdStore.js";
65
import { useAutoConnectCore } from "../../../core/hooks/wallets/useAutoConnect.js";
76

87
/**
@@ -34,15 +33,5 @@ export function useAutoConnect(props: AutoConnectProps) {
3433
wallets,
3534
},
3635
createWallet,
37-
() => {
38-
const specifiedWalletIds = new Set(wallets.map((x) => x.id));
39-
40-
// pass the wallets that are not already specified but are installed by the user
41-
const installedWallets = getInstalledWalletProviders()
42-
.filter((x) => !specifiedWalletIds.has(x.info.rdns))
43-
.map((x) => createWallet(x.info.rdns));
44-
45-
return installedWallets;
46-
},
4736
);
4837
}

packages/thirdweb/src/react/web/ui/ConnectWallet/Details.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ describe("Details Modal", () => {
560560
);
561561

562562
// Add assertions to check if the modal is rendered correctly
563-
expect(screen.getByText("Connect Modal")).toBeInTheDocument();
563+
expect(screen.getByText("Manage Wallet")).toBeInTheDocument();
564564
});
565565

566566
it("should call closeModal when the close button is clicked", async () => {

packages/thirdweb/src/transaction/prepare-transaction.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { baseSepolia } from "thirdweb/chains";
12
import { describe, expect, test as it } from "vitest";
23
import { TEST_ACCOUNT_B } from "~test/test-wallets.js";
34
import { TEST_WALLET_A, TEST_WALLET_B } from "../../test/src/addresses.js";
45
import { FORKED_ETHEREUM_CHAIN } from "../../test/src/chains.js";
56
import { TEST_CLIENT } from "../../test/src/test-clients.js";
6-
import { defineChain } from "../chains/utils.js";
77
import { toWei } from "../utils/units.js";
88
import { signAuthorization } from "./actions/eip7702/authorization.js";
99
import { estimateGas } from "./actions/estimate-gas.js";
@@ -33,7 +33,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("prepareTransaction", () => {
3333
});
3434
const preparedTx = prepareTransaction({
3535
authorizationList: [authorization],
36-
chain: defineChain(911867),
36+
chain: baseSepolia,
3737
client: TEST_CLIENT,
3838
to: TEST_WALLET_B,
3939
value: 0n,

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { createWalletAdapter } from "../../adapters/wallet-adapter.js";
55
import { ethereum } from "../../chains/chain-definitions/ethereum.js";
66
import { webLocalStorage } from "../../utils/storage/webStorage.js";
77
import { createWallet } from "../create-wallet.js";
8-
import { getInstalledWalletProviders } from "../injected/mipdStore.js";
98
import { autoConnect } from "./autoConnect.js";
109
import { autoConnectCore } from "./autoConnectCore.js";
1110

@@ -25,7 +24,6 @@ describe("autoConnect", () => {
2524

2625
beforeEach(() => {
2726
vi.clearAllMocks();
28-
vi.mocked(getInstalledWalletProviders).mockReturnValue([]);
2927
vi.mocked(createWallet).mockReturnValue(mockWallet);
3028
vi.mocked(autoConnectCore).mockResolvedValue(true);
3129
});
@@ -38,7 +36,6 @@ describe("autoConnect", () => {
3836

3937
expect(autoConnectCore).toHaveBeenCalledWith({
4038
createWalletFn: createWallet,
41-
getInstalledWallets: expect.any(Function),
4239
manager: expect.any(Object),
4340
props: {
4441
client: TEST_CLIENT,

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { webLocalStorage } from "../../utils/storage/webStorage.js";
22
import { createWallet } from "../create-wallet.js";
33
import { getDefaultWallets } from "../defaultWallets.js";
4-
import { getInstalledWalletProviders } from "../injected/mipdStore.js";
54
import type { Wallet } from "../interfaces/wallet.js";
65
import { createConnectionManager } from "../manager/index.js";
76
import { autoConnectCore } from "./autoConnectCore.js";
@@ -44,16 +43,6 @@ export async function autoConnect(
4443
const manager = createConnectionManager(webLocalStorage);
4544
const result = await autoConnectCore({
4645
createWalletFn: createWallet,
47-
getInstalledWallets: () => {
48-
const specifiedWalletIds = new Set(wallets.map((x) => x.id));
49-
50-
// pass the wallets that are not already specified but are installed by the user
51-
const installedWallets = getInstalledWalletProviders()
52-
.filter((x) => !specifiedWalletIds.has(x.info.rdns))
53-
.map((x) => createWallet(x.info.rdns));
54-
55-
return installedWallets;
56-
},
5746
manager,
5847
props: {
5948
...props,

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type AutoConnectCoreProps = {
2828
connectOverride?: (
2929
walletOrFn: Wallet | (() => Promise<Wallet>),
3030
) => Promise<Wallet | null>;
31-
getInstalledWallets?: () => Wallet[];
3231
setLastAuthProvider?: (
3332
authProvider: AuthArgsType["strategy"],
3433
storage: AsyncStorage,
@@ -69,7 +68,6 @@ const _autoConnectCore = async ({
6968
createWalletFn,
7069
manager,
7170
connectOverride,
72-
getInstalledWallets,
7371
setLastAuthProvider,
7472
}: AutoConnectCoreProps): Promise<boolean> => {
7573
const { wallets, onConnect } = props;
@@ -120,7 +118,13 @@ const _autoConnectCore = async ({
120118
// in that case, we default to the passed chain to connect to
121119
const lastConnectedChain =
122120
(await getLastConnectedChain(storage)) || props.chain;
123-
const availableWallets = [...wallets, ...(getInstalledWallets?.() ?? [])];
121+
const availableWallets = lastConnectedWalletIds.map((id) => {
122+
const specifiedWallet = wallets.find((w) => w.id === id);
123+
if (specifiedWallet) {
124+
return specifiedWallet;
125+
}
126+
return createWalletFn(id as WalletId);
127+
});
124128
const activeWallet =
125129
lastActiveWalletId &&
126130
(availableWallets.find((w) => w.id === lastActiveWalletId) ||

packages/thirdweb/src/wallets/manager/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,12 @@ export function createConnectionManager(storage: AsyncStorage) {
238238
// save last connected wallet ids to storage
239239
effect(
240240
async () => {
241-
const prevAccounts = (await getStoredConnectedWalletIds(storage)) || [];
242241
const accounts = connectedWallets.getValue();
243242
const ids = accounts.map((acc) => acc?.id).filter((c) => !!c) as string[];
244243

245244
storage.setItem(
246245
CONNECTED_WALLET_IDS,
247-
stringify(Array.from(new Set([...prevAccounts, ...ids]))),
246+
stringify(Array.from(new Set([...ids]))),
248247
);
249248
},
250249
[connectedWallets],

0 commit comments

Comments
 (0)