From 7d078de2fb99eedbec13d16eba42a8ce1d3843c7 Mon Sep 17 00:00:00 2001 From: nacho <25931366+ignaciosantise@users.noreply.github.com> Date: Wed, 5 Nov 2025 15:39:24 -0300 Subject: [PATCH 01/13] chore: added useAppKitTheme hook --- .changeset/spotty-foxes-fry.md | 13 ++++ packages/appkit/src/hooks/useAppKitTheme.ts | 81 +++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 .changeset/spotty-foxes-fry.md create mode 100644 packages/appkit/src/hooks/useAppKitTheme.ts diff --git a/.changeset/spotty-foxes-fry.md b/.changeset/spotty-foxes-fry.md new file mode 100644 index 00000000..4d0fcbc3 --- /dev/null +++ b/.changeset/spotty-foxes-fry.md @@ -0,0 +1,13 @@ +--- +'@reown/appkit-react-native': patch +'@reown/appkit-ui-react-native': patch +'@reown/appkit-bitcoin-react-native': patch +'@reown/appkit-coinbase-react-native': patch +'@reown/appkit-common-react-native': patch +'@reown/appkit-core-react-native': patch +'@reown/appkit-ethers-react-native': patch +'@reown/appkit-solana-react-native': patch +'@reown/appkit-wagmi-react-native': patch +--- + +chore: added useAppKitTheme hook diff --git a/packages/appkit/src/hooks/useAppKitTheme.ts b/packages/appkit/src/hooks/useAppKitTheme.ts new file mode 100644 index 00000000..d944c2d4 --- /dev/null +++ b/packages/appkit/src/hooks/useAppKitTheme.ts @@ -0,0 +1,81 @@ +import { useMemo } from 'react'; +import { useSnapshot } from 'valtio'; +import type { ThemeMode, ThemeVariables } from '@reown/appkit-common-react-native'; +import { ThemeController } from '@reown/appkit-core-react-native'; +import { useAppKit } from './useAppKit'; + +/** + * Interface representing the result of the useAppKitTheme hook + */ +interface UseAppKitThemeReturn { + /** The current theme mode ('dark' or 'light'), or undefined if using system default */ + themeMode: ThemeMode | undefined; + /** The current theme variables, currently only supports 'accent' color */ + themeVariables: ThemeVariables | undefined; + /** Function to set the theme mode */ + setThemeMode: (themeMode: ThemeMode | undefined) => void; + /** Function to set theme variables */ + setThemeVariables: (themeVariables: ThemeVariables | undefined) => void; +} + +/** + * Hook to control the visual appearance of the AppKit modal + * + * @remarks + * This hook provides access to the theme mode and theme variables, allowing you to + * customize the modal's appearance. Use this hook when you need to implement dark/light + * mode or match the modal's appearance with your application's theme. + * + * Currently, the only supported theme variable is `accent`, which controls the primary + * accent color used throughout the modal interface. + * + * @returns {UseAppKitThemeReturn} An object containing: + * - `themeMode`: The current theme mode ('dark' or 'light') + * - `themeVariables`: The current theme variables (only 'accent' is supported) + * - `setThemeMode`: Function to change the theme mode + * - `setThemeVariables`: Function to update theme variables + * + * @throws {Error} If used outside of an AppKitProvider + * + * @example + * ```typescript + * import { useAppKitTheme } from '@reown/appkit-react-native'; + * + * function MyComponent() { + * const { themeMode, themeVariables, setThemeMode, setThemeVariables } = useAppKitTheme(); + * + * // Set theme to dark mode + * setThemeMode('dark'); + * + * // Customize the accent color + * setThemeVariables({ + * accent: '#00BB7F' + * }); + * + * return ( + * + * Current theme: {themeMode} + * Accent color: {themeVariables?.accent} + * + * ); + * } + * ``` + */ +export function useAppKitTheme(): UseAppKitThemeReturn { + useAppKit(); // Use the hook for checks + const { themeMode, themeVariables } = useSnapshot(ThemeController.state); + + const stableFunctions = useMemo( + () => ({ + setThemeMode: ThemeController.setThemeMode.bind(ThemeController), + setThemeVariables: ThemeController.setThemeVariables.bind(ThemeController) + }), + [] + ); + + return { + themeMode, + themeVariables, + ...stableFunctions + }; +} From 43d157998f64f241b9dc27357c3770fb92dc5f62 Mon Sep 17 00:00:00 2001 From: nacho <25931366+ignaciosantise@users.noreply.github.com> Date: Wed, 5 Nov 2025 15:56:55 -0300 Subject: [PATCH 02/13] chore: export hook --- packages/appkit/src/hooks/useAppKitTheme.ts | 2 +- packages/appkit/src/index.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/appkit/src/hooks/useAppKitTheme.ts b/packages/appkit/src/hooks/useAppKitTheme.ts index d944c2d4..6d4712f0 100644 --- a/packages/appkit/src/hooks/useAppKitTheme.ts +++ b/packages/appkit/src/hooks/useAppKitTheme.ts @@ -7,7 +7,7 @@ import { useAppKit } from './useAppKit'; /** * Interface representing the result of the useAppKitTheme hook */ -interface UseAppKitThemeReturn { +export interface UseAppKitThemeReturn { /** The current theme mode ('dark' or 'light'), or undefined if using system default */ themeMode: ThemeMode | undefined; /** The current theme variables, currently only supports 'accent' color */ diff --git a/packages/appkit/src/index.ts b/packages/appkit/src/index.ts index 96c88cd4..cef464c0 100644 --- a/packages/appkit/src/index.ts +++ b/packages/appkit/src/index.ts @@ -32,6 +32,7 @@ export type { AppKitConfig } from './types'; export { useAppKit } from './hooks/useAppKit'; export { useProvider } from './hooks/useProvider'; export { useAccount, type Account as UseAccountReturn } from './hooks/useAccount'; +export { useAppKitTheme, type UseAppKitThemeReturn } from './hooks/useAppKitTheme'; export { useWalletInfo } from './hooks/useWalletInfo'; export { useAppKitEvents, useAppKitEventSubscription } from './hooks/useAppKitEvents'; export { useAppKitState } from './hooks/useAppKitState'; From 61a4164356a51d70f1dcf93cf8f6e41197abfc01 Mon Sep 17 00:00:00 2001 From: nacho <25931366+ignaciosantise@users.noreply.github.com> Date: Wed, 5 Nov 2025 16:12:27 -0300 Subject: [PATCH 03/13] chore: added JSDocs to hooks, improved context check --- packages/appkit/src/AppKitContext.tsx | 2 +- packages/appkit/src/hooks/useAccount.ts | 4 +- packages/appkit/src/hooks/useAppKit.ts | 57 ++++++++++++---- packages/appkit/src/hooks/useAppKitContext.ts | 43 ++++++++++++ packages/appkit/src/hooks/useAppKitEvents.ts | 66 ++++++++++++++++++- packages/appkit/src/hooks/useAppKitLogs.ts | 14 +--- packages/appkit/src/hooks/useAppKitState.ts | 37 ++++++++++- packages/appkit/src/hooks/useAppKitTheme.ts | 4 +- packages/appkit/src/hooks/useProvider.ts | 7 +- packages/appkit/src/hooks/useWalletInfo.ts | 35 +++++++++- .../core/src/controllers/ThemeController.ts | 6 +- 11 files changed, 234 insertions(+), 41 deletions(-) create mode 100644 packages/appkit/src/hooks/useAppKitContext.ts diff --git a/packages/appkit/src/AppKitContext.tsx b/packages/appkit/src/AppKitContext.tsx index 2d90df28..5f1d64c4 100644 --- a/packages/appkit/src/AppKitContext.tsx +++ b/packages/appkit/src/AppKitContext.tsx @@ -1,7 +1,7 @@ import React, { createContext, useContext, useMemo, type ReactNode } from 'react'; import { AppKit } from './AppKit'; -interface AppKitContextType { +export interface AppKitContextType { appKit: AppKit | null; } diff --git a/packages/appkit/src/hooks/useAccount.ts b/packages/appkit/src/hooks/useAccount.ts index a3a30e87..02fd7ec9 100644 --- a/packages/appkit/src/hooks/useAccount.ts +++ b/packages/appkit/src/hooks/useAccount.ts @@ -6,8 +6,8 @@ import { } from '@reown/appkit-core-react-native'; import { useMemo } from 'react'; import { useSnapshot } from 'valtio'; -import { useAppKit } from './useAppKit'; import type { AccountType, AppKitNetwork } from '@reown/appkit-common-react-native'; +import { useAppKitContext } from './useAppKitContext'; /** * Represents a blockchain account with its associated metadata @@ -64,7 +64,7 @@ export interface Account { * @throws Will log errors via LogController if account parsing fails */ export function useAccount() { - useAppKit(); // Use the hook for checks + useAppKitContext(); const { activeAddress: address, diff --git a/packages/appkit/src/hooks/useAppKit.ts b/packages/appkit/src/hooks/useAppKit.ts index 910b26ed..2dff2dc1 100644 --- a/packages/appkit/src/hooks/useAppKit.ts +++ b/packages/appkit/src/hooks/useAppKit.ts @@ -1,27 +1,60 @@ -import { useContext, useMemo } from 'react'; +import { useMemo } from 'react'; import type { ChainNamespace } from '@reown/appkit-common-react-native'; import type { AppKit } from '../AppKit'; -import { AppKitContext } from '../AppKitContext'; +import { useAppKitContext } from './useAppKitContext'; +/** + * Interface representing the return value of the useAppKit hook + */ interface UseAppKitReturn { + /** Function to open the AppKit modal with optional view configuration */ open: AppKit['open']; + /** Function to close the AppKit modal */ close: AppKit['close']; + /** Function to disconnect the wallet, optionally scoped to a specific namespace */ disconnect: (namespace?: ChainNamespace) => void; + /** Function to switch to a different network */ switchNetwork: AppKit['switchNetwork']; } +/** + * Hook to access core AppKit functionality for controlling the modal + * + * @remarks + * This hook provides access to the main AppKit instance methods for opening/closing + * the modal, disconnecting wallets, and switching networks. All functions are memoized + * and properly bound to ensure stable references across renders. + * + * @returns {UseAppKitReturn} An object containing: + * - `open`: Opens the AppKit modal, optionally with a specific view + * - `close`: Closes the AppKit modal + * - `disconnect`: Disconnects the current wallet connection (optionally for a specific namespace) + * - `switchNetwork`: Switches to a different blockchain network + * + * @throws {Error} If used outside of an AppKitProvider + * @throws {Error} If AppKit instance is not available in context + * + * @example + * ```tsx + * function MyComponent() { + * const { open, close, disconnect, switchNetwork } = useAppKit(); + * + * return ( + * + *