Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clean-wings-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Always reconnect any previously connected wallet properly
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ export function ChainLiveStats(props: { rpc: string }) {
>
{eip7702Support.data ? (
eip7702Support.data.isSupported ? (
"Enabled"
"Available"
) : (
"Disabled"
"Not Available"
)
) : eip7702Support.isError ? (
"Disabled"
"Not Available"
) : (
<div className="flex h-[28px] w-[80px] py-1">
<Skeleton className="h-full w-full" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function useAutoConnectCore(
storage: AsyncStorage,
props: AutoConnectProps & { wallets: Wallet[] },
createWalletFn: (id: WalletId) => Wallet,
getInstalledWallets?: () => Wallet[],
) {
const manager = useConnectionManagerCtx("useAutoConnect");
const { connect } = useConnect({
Expand All @@ -28,7 +27,6 @@ export function useAutoConnectCore(
autoConnectCore({
connectOverride: connect,
createWalletFn,
getInstalledWallets,
manager,
props,
setLastAuthProvider,
Expand Down
11 changes: 0 additions & 11 deletions packages/thirdweb/src/react/web/hooks/wallets/useAutoConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { webLocalStorage } from "../../../../utils/storage/webStorage.js";
import type { AutoConnectProps } from "../../../../wallets/connection/types.js";
import { createWallet } from "../../../../wallets/create-wallet.js";
import { getDefaultWallets } from "../../../../wallets/defaultWallets.js";
import { getInstalledWalletProviders } from "../../../../wallets/injected/mipdStore.js";
import { useAutoConnectCore } from "../../../core/hooks/wallets/useAutoConnect.js";

/**
Expand Down Expand Up @@ -34,15 +33,5 @@ export function useAutoConnect(props: AutoConnectProps) {
wallets,
},
createWallet,
() => {
const specifiedWalletIds = new Set(wallets.map((x) => x.id));

// pass the wallets that are not already specified but are installed by the user
const installedWallets = getInstalledWalletProviders()
.filter((x) => !specifiedWalletIds.has(x.info.rdns))
.map((x) => createWallet(x.info.rdns));

return installedWallets;
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ describe("Details Modal", () => {
);

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

it("should call closeModal when the close button is clicked", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { baseSepolia } from "thirdweb/chains";
import { describe, expect, test as it } from "vitest";
import { TEST_ACCOUNT_B } from "~test/test-wallets.js";
import { TEST_WALLET_A, TEST_WALLET_B } from "../../test/src/addresses.js";
import { FORKED_ETHEREUM_CHAIN } from "../../test/src/chains.js";
import { TEST_CLIENT } from "../../test/src/test-clients.js";
import { defineChain } from "../chains/utils.js";
import { toWei } from "../utils/units.js";
import { signAuthorization } from "./actions/eip7702/authorization.js";
import { estimateGas } from "./actions/estimate-gas.js";
Expand Down Expand Up @@ -33,7 +33,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("prepareTransaction", () => {
});
const preparedTx = prepareTransaction({
authorizationList: [authorization],
chain: defineChain(911867),
chain: baseSepolia,
client: TEST_CLIENT,
to: TEST_WALLET_B,
value: 0n,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { createWalletAdapter } from "../../adapters/wallet-adapter.js";
import { ethereum } from "../../chains/chain-definitions/ethereum.js";
import { webLocalStorage } from "../../utils/storage/webStorage.js";
import { createWallet } from "../create-wallet.js";
import { getInstalledWalletProviders } from "../injected/mipdStore.js";
import { autoConnect } from "./autoConnect.js";
import { autoConnectCore } from "./autoConnectCore.js";

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

beforeEach(() => {
vi.clearAllMocks();
vi.mocked(getInstalledWalletProviders).mockReturnValue([]);
vi.mocked(createWallet).mockReturnValue(mockWallet);
vi.mocked(autoConnectCore).mockResolvedValue(true);
});
Expand All @@ -38,7 +36,6 @@ describe("autoConnect", () => {

expect(autoConnectCore).toHaveBeenCalledWith({
createWalletFn: createWallet,
getInstalledWallets: expect.any(Function),
manager: expect.any(Object),
props: {
client: TEST_CLIENT,
Expand Down
11 changes: 0 additions & 11 deletions packages/thirdweb/src/wallets/connection/autoConnect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { webLocalStorage } from "../../utils/storage/webStorage.js";
import { createWallet } from "../create-wallet.js";
import { getDefaultWallets } from "../defaultWallets.js";
import { getInstalledWalletProviders } from "../injected/mipdStore.js";
import type { Wallet } from "../interfaces/wallet.js";
import { createConnectionManager } from "../manager/index.js";
import { autoConnectCore } from "./autoConnectCore.js";
Expand Down Expand Up @@ -44,16 +43,6 @@ export async function autoConnect(
const manager = createConnectionManager(webLocalStorage);
const result = await autoConnectCore({
createWalletFn: createWallet,
getInstalledWallets: () => {
const specifiedWalletIds = new Set(wallets.map((x) => x.id));

// pass the wallets that are not already specified but are installed by the user
const installedWallets = getInstalledWalletProviders()
.filter((x) => !specifiedWalletIds.has(x.info.rdns))
.map((x) => createWallet(x.info.rdns));

return installedWallets;
},
manager,
props: {
...props,
Expand Down
10 changes: 7 additions & 3 deletions packages/thirdweb/src/wallets/connection/autoConnectCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
connectOverride?: (
walletOrFn: Wallet | (() => Promise<Wallet>),
) => Promise<Wallet | null>;
getInstalledWallets?: () => Wallet[];
setLastAuthProvider?: (
authProvider: AuthArgsType["strategy"],
storage: AsyncStorage,
Expand Down Expand Up @@ -69,7 +68,6 @@
createWalletFn,
manager,
connectOverride,
getInstalledWallets,
setLastAuthProvider,
}: AutoConnectCoreProps): Promise<boolean> => {
const { wallets, onConnect } = props;
Expand Down Expand Up @@ -120,7 +118,13 @@
// in that case, we default to the passed chain to connect to
const lastConnectedChain =
(await getLastConnectedChain(storage)) || props.chain;
const availableWallets = [...wallets, ...(getInstalledWallets?.() ?? [])];
const availableWallets = lastConnectedWalletIds.map((id) => {
const specifiedWallet = wallets.find((w) => w.id === id);
if (specifiedWallet) {
return specifiedWallet;
}
return createWalletFn(id as WalletId);

Check warning on line 126 in packages/thirdweb/src/wallets/connection/autoConnectCore.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L126 was not covered by tests
});
const activeWallet =
lastActiveWalletId &&
(availableWallets.find((w) => w.id === lastActiveWalletId) ||
Expand Down
3 changes: 1 addition & 2 deletions packages/thirdweb/src/wallets/manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,12 @@ export function createConnectionManager(storage: AsyncStorage) {
// save last connected wallet ids to storage
effect(
async () => {
const prevAccounts = (await getStoredConnectedWalletIds(storage)) || [];
const accounts = connectedWallets.getValue();
const ids = accounts.map((acc) => acc?.id).filter((c) => !!c) as string[];

storage.setItem(
CONNECTED_WALLET_IDS,
stringify(Array.from(new Set([...prevAccounts, ...ids]))),
stringify(Array.from(new Set([...ids]))),
);
},
[connectedWallets],
Expand Down
Loading