Skip to content

Commit a18fc8e

Browse files
authored
Connect UI context cleanup (#2761)
1 parent 6574e4d commit a18fc8e

38 files changed

+294
-1072
lines changed

.changeset/light-llamas-chew.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+
Connect UI context code cleanup

packages/thirdweb/src/react/core/hooks/others/useWalletBalance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
type GetWalletBalanceOptions,
44
getWalletBalance,
55
} from "../../../../wallets/utils/getWalletBalance.js";
6-
import { useWalletConnectionCtx } from "./useWalletConnectionCtx.js";
6+
import { useConnectUI } from "./useWalletConnectionCtx.js";
77

88
/**
99
* Custom hook to fetch the balance of a wallet for a specific token.
@@ -15,7 +15,7 @@ export function useWalletBalance(
1515
options: Omit<Partial<GetWalletBalanceOptions>, "client">,
1616
) {
1717
const { chain, address, tokenAddress } = options;
18-
const { client } = useWalletConnectionCtx();
18+
const { client } = useConnectUI();
1919
const query = queryOptions({
2020
queryKey: [
2121
"walletBalance",

packages/thirdweb/src/react/core/hooks/others/useWalletConnectionCtx.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { useContext } from "react";
2-
import { WalletConnectionContext } from "../../providers/wallet-connection.js";
2+
import { ConnectUIContext } from "../../providers/wallet-connection.js";
33

44
/**
55
* @internal
66
*/
7-
export function useWalletConnectionCtx() {
8-
const val = useContext(WalletConnectionContext);
7+
export function useConnectUI() {
8+
const val = useContext(ConnectUIContext);
99
if (!val) {
1010
throw new Error(
11-
"useWalletConnectionCtx must be used within a <ConnectWallet /> or <AutoConnect /> component.",
11+
"useConnectUI must be used within a <ConnectButton /> or <ConnectEmbed />",
1212
);
1313
}
1414
return val;

packages/thirdweb/src/react/core/providers/wallet-connection.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { createContext } from "react";
22
import type { Chain } from "../../../chains/types.js";
33
import type { ThirdwebClient } from "../../../client/client.js";
4+
import type { ConnectButton_connectModalOptions } from "../../../exports/react.js";
45
import type { Wallet } from "../../../wallets/interfaces/wallet.js";
56
import type { SmartWalletOptions } from "../../../wallets/smart/types.js";
67
import type { AppMetadata } from "../../../wallets/types.js";
78
import type { ConnectLocale } from "../../web/ui/ConnectWallet/locale/types.js";
89
import type { LocaleId } from "../../web/ui/types.js";
910

10-
export const WalletConnectionContext = /* @__PURE__ */ createContext<{
11+
export const ConnectUIContext = /* @__PURE__ */ createContext<{
1112
wallets: Wallet[];
1213
client: ThirdwebClient;
1314
chain?: Chain;
@@ -21,4 +22,9 @@ export const WalletConnectionContext = /* @__PURE__ */ createContext<{
2122
};
2223
accountAbstraction?: SmartWalletOptions;
2324
showAllWallets?: boolean;
25+
onConnect?: (wallet: Wallet) => void;
26+
isEmbed: boolean;
27+
connectModal: Omit<ConnectButton_connectModalOptions, "size"> & {
28+
size: "compact" | "wide";
29+
};
2430
} | null>(null);

0 commit comments

Comments
 (0)