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/thirty-cheetahs-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Allow connecting wallets without setting them as active with useConnect
4 changes: 0 additions & 4 deletions packages/thirdweb/src/react/core/account/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import type React from "react";
import { createContext, useContext } from "react";
import type { ThirdwebClient } from "../../../client/client.js";
import { isAddress } from "../../../utils/address.js";
/**
* Props for the <AccountProvider /> component
* @component
Expand Down Expand Up @@ -53,9 +52,6 @@ export function AccountProvider(
"AccountProvider: No address passed. Ensure an address is always provided to the AccountProvider",
);
}
if (!isAddress(props.address)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't wanna throw and break the page on bad input here, should throw inside the queries instead

throw new Error(`AccountProvider: Invalid address: ${props.address}`);
}
return (
<AccountProviderContext.Provider value={props}>
{props.children}
Expand Down
4 changes: 2 additions & 2 deletions packages/thirdweb/src/react/core/utils/walletname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function useWalletName(props: {
/**
* @internal Exported for tests only
*/
function getQueryKeys(props: {
export function getQueryKeys(props: {
id: WalletId;
formatFn?: (str: string) => string;
}) {
Expand All @@ -41,7 +41,7 @@ function getQueryKeys(props: {
/**
* @internal Exported for tests only
*/
async function fetchWalletName(props: {
export async function fetchWalletName(props: {
id: WalletId;
formatFn?: (str: string) => string;
}) {
Expand Down
5 changes: 4 additions & 1 deletion packages/thirdweb/src/wallets/manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type ConnectionManager = ReturnType<typeof createConnectionManager>;
export type ConnectManagerOptions = {
client: ThirdwebClient;
accountAbstraction?: SmartWalletOptions;
setWalletAsActive?: boolean;
onConnect?: (wallet: Wallet) => void;
};

Expand Down Expand Up @@ -146,7 +147,9 @@ export function createConnectionManager(storage: AsyncStorage) {
// add personal wallet to connected wallets list even if it's not the active one
addConnectedWallet(wallet);

handleSetActiveWallet(activeWallet);
if (options?.setWalletAsActive !== false) {
handleSetActiveWallet(activeWallet);
}

wallet.subscribe("accountChanged", async () => {
// We reimplement connect here to prevent memory leaks
Expand Down
Loading