@reown/appkit-react-native 0.0.0-develop-20251008155354 → 0.0.0-develop-20251114152149

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/lib/commonjs/AppKit.js +20 -6
  2. package/lib/commonjs/AppKit.js.map +1 -1
  3. package/lib/commonjs/hooks/useAccount.js +68 -5
  4. package/lib/commonjs/hooks/useAccount.js.map +1 -1
  5. package/lib/commonjs/hooks/useAppKit.js +41 -9
  6. package/lib/commonjs/hooks/useAppKit.js.map +1 -1
  7. package/lib/commonjs/hooks/useAppKitContext.js +46 -0
  8. package/lib/commonjs/hooks/useAppKitContext.js.map +1 -0
  9. package/lib/commonjs/hooks/useAppKitEvents.js +64 -4
  10. package/lib/commonjs/hooks/useAppKitEvents.js.map +1 -1
  11. package/lib/commonjs/hooks/useAppKitLogs.js +2 -8
  12. package/lib/commonjs/hooks/useAppKitLogs.js.map +1 -1
  13. package/lib/commonjs/hooks/useAppKitState.js +35 -2
  14. package/lib/commonjs/hooks/useAppKitState.js.map +1 -1
  15. package/lib/commonjs/hooks/useAppKitTheme.js +74 -0
  16. package/lib/commonjs/hooks/useAppKitTheme.js.map +1 -0
  17. package/lib/commonjs/hooks/useProvider.js +3 -4
  18. package/lib/commonjs/hooks/useProvider.js.map +1 -1
  19. package/lib/commonjs/hooks/useWalletInfo.js +33 -2
  20. package/lib/commonjs/hooks/useWalletInfo.js.map +1 -1
  21. package/lib/commonjs/index.js +7 -0
  22. package/lib/commonjs/index.js.map +1 -1
  23. package/lib/commonjs/modal/w3m-modal/styles.js +2 -1
  24. package/lib/commonjs/modal/w3m-modal/styles.js.map +1 -1
  25. package/lib/commonjs/partials/w3m-connecting-body/index.js +2 -0
  26. package/lib/commonjs/partials/w3m-connecting-body/index.js.map +1 -1
  27. package/lib/commonjs/partials/w3m-connecting-mobile/components/StoreLink.js +4 -0
  28. package/lib/commonjs/partials/w3m-connecting-mobile/components/StoreLink.js.map +1 -1
  29. package/lib/commonjs/partials/w3m-connecting-qrcode/index.js +5 -1
  30. package/lib/commonjs/partials/w3m-connecting-qrcode/index.js.map +1 -1
  31. package/lib/commonjs/partials/w3m-header/index.js +1 -0
  32. package/lib/commonjs/partials/w3m-header/index.js.map +1 -1
  33. package/lib/commonjs/partials/w3m-header/styles.js +3 -0
  34. package/lib/commonjs/partials/w3m-header/styles.js.map +1 -1
  35. package/lib/commonjs/partials/w3m-send-input-token/index.js +6 -3
  36. package/lib/commonjs/partials/w3m-send-input-token/index.js.map +1 -1
  37. package/lib/commonjs/partials/w3m-swap-input/index.js +6 -3
  38. package/lib/commonjs/partials/w3m-swap-input/index.js.map +1 -1
  39. package/lib/commonjs/views/w3m-account-default-view/index.js +2 -1
  40. package/lib/commonjs/views/w3m-account-default-view/index.js.map +1 -1
  41. package/lib/commonjs/views/w3m-connecting-external-view/index.js +4 -8
  42. package/lib/commonjs/views/w3m-connecting-external-view/index.js.map +1 -1
  43. package/lib/commonjs/views/w3m-connecting-view/index.js +17 -7
  44. package/lib/commonjs/views/w3m-connecting-view/index.js.map +1 -1
  45. package/lib/commonjs/views/w3m-onramp-settings-view/index.js +2 -0
  46. package/lib/commonjs/views/w3m-onramp-settings-view/index.js.map +1 -1
  47. package/lib/commonjs/views/w3m-onramp-view/index.js +3 -2
  48. package/lib/commonjs/views/w3m-onramp-view/index.js.map +1 -1
  49. package/lib/commonjs/views/w3m-swap-view/components/select-token-modal/index.js +2 -1
  50. package/lib/commonjs/views/w3m-swap-view/components/select-token-modal/index.js.map +1 -1
  51. package/lib/commonjs/views/w3m-swap-view/index.js +4 -2
  52. package/lib/commonjs/views/w3m-swap-view/index.js.map +1 -1
  53. package/lib/commonjs/views/w3m-wallet-send-view/index.js +2 -1
  54. package/lib/commonjs/views/w3m-wallet-send-view/index.js.map +1 -1
  55. package/lib/module/AppKit.js +20 -6
  56. package/lib/module/AppKit.js.map +1 -1
  57. package/lib/module/hooks/useAccount.js +69 -5
  58. package/lib/module/hooks/useAccount.js.map +1 -1
  59. package/lib/module/hooks/useAppKit.js +43 -10
  60. package/lib/module/hooks/useAppKit.js.map +1 -1
  61. package/lib/module/hooks/useAppKitContext.js +42 -0
  62. package/lib/module/hooks/useAppKitContext.js.map +1 -0
  63. package/lib/module/hooks/useAppKitEvents.js +65 -4
  64. package/lib/module/hooks/useAppKitEvents.js.map +1 -1
  65. package/lib/module/hooks/useAppKitLogs.js +3 -9
  66. package/lib/module/hooks/useAppKitLogs.js.map +1 -1
  67. package/lib/module/hooks/useAppKitState.js +36 -2
  68. package/lib/module/hooks/useAppKitState.js.map +1 -1
  69. package/lib/module/hooks/useAppKitTheme.js +71 -0
  70. package/lib/module/hooks/useAppKitTheme.js.map +1 -0
  71. package/lib/module/hooks/useProvider.js +3 -4
  72. package/lib/module/hooks/useProvider.js.map +1 -1
  73. package/lib/module/hooks/useWalletInfo.js +34 -2
  74. package/lib/module/hooks/useWalletInfo.js.map +1 -1
  75. package/lib/module/index.js +1 -0
  76. package/lib/module/index.js.map +1 -1
  77. package/lib/module/modal/w3m-modal/styles.js +2 -1
  78. package/lib/module/modal/w3m-modal/styles.js.map +1 -1
  79. package/lib/module/partials/w3m-connecting-body/index.js +2 -0
  80. package/lib/module/partials/w3m-connecting-body/index.js.map +1 -1
  81. package/lib/module/partials/w3m-connecting-mobile/components/StoreLink.js +4 -0
  82. package/lib/module/partials/w3m-connecting-mobile/components/StoreLink.js.map +1 -1
  83. package/lib/module/partials/w3m-connecting-qrcode/index.js +5 -1
  84. package/lib/module/partials/w3m-connecting-qrcode/index.js.map +1 -1
  85. package/lib/module/partials/w3m-header/index.js +1 -0
  86. package/lib/module/partials/w3m-header/index.js.map +1 -1
  87. package/lib/module/partials/w3m-header/styles.js +3 -0
  88. package/lib/module/partials/w3m-header/styles.js.map +1 -1
  89. package/lib/module/partials/w3m-send-input-token/index.js +6 -3
  90. package/lib/module/partials/w3m-send-input-token/index.js.map +1 -1
  91. package/lib/module/partials/w3m-swap-input/index.js +6 -3
  92. package/lib/module/partials/w3m-swap-input/index.js.map +1 -1
  93. package/lib/module/views/w3m-account-default-view/index.js +2 -1
  94. package/lib/module/views/w3m-account-default-view/index.js.map +1 -1
  95. package/lib/module/views/w3m-connecting-external-view/index.js +4 -8
  96. package/lib/module/views/w3m-connecting-external-view/index.js.map +1 -1
  97. package/lib/module/views/w3m-connecting-view/index.js +17 -7
  98. package/lib/module/views/w3m-connecting-view/index.js.map +1 -1
  99. package/lib/module/views/w3m-onramp-settings-view/index.js +2 -0
  100. package/lib/module/views/w3m-onramp-settings-view/index.js.map +1 -1
  101. package/lib/module/views/w3m-onramp-view/index.js +3 -2
  102. package/lib/module/views/w3m-onramp-view/index.js.map +1 -1
  103. package/lib/module/views/w3m-swap-view/components/select-token-modal/index.js +2 -1
  104. package/lib/module/views/w3m-swap-view/components/select-token-modal/index.js.map +1 -1
  105. package/lib/module/views/w3m-swap-view/index.js +4 -2
  106. package/lib/module/views/w3m-swap-view/index.js.map +1 -1
  107. package/lib/module/views/w3m-wallet-send-view/index.js +2 -1
  108. package/lib/module/views/w3m-wallet-send-view/index.js.map +1 -1
  109. package/lib/typescript/AppKit.d.ts +9 -2
  110. package/lib/typescript/AppKit.d.ts.map +1 -1
  111. package/lib/typescript/AppKitContext.d.ts +2 -2
  112. package/lib/typescript/AppKitContext.d.ts.map +1 -1
  113. package/lib/typescript/hooks/useAccount.d.ts +57 -33
  114. package/lib/typescript/hooks/useAccount.d.ts.map +1 -1
  115. package/lib/typescript/hooks/useAppKit.d.ts +42 -0
  116. package/lib/typescript/hooks/useAppKit.d.ts.map +1 -1
  117. package/lib/typescript/hooks/useAppKitContext.d.ts +27 -0
  118. package/lib/typescript/hooks/useAppKitContext.d.ts.map +1 -0
  119. package/lib/typescript/hooks/useAppKitEvents.d.ts +66 -0
  120. package/lib/typescript/hooks/useAppKitEvents.d.ts.map +1 -1
  121. package/lib/typescript/hooks/useAppKitLogs.d.ts.map +1 -1
  122. package/lib/typescript/hooks/useAppKitState.d.ts +32 -0
  123. package/lib/typescript/hooks/useAppKitState.d.ts.map +1 -1
  124. package/lib/typescript/hooks/useAppKitTheme.d.ts +59 -0
  125. package/lib/typescript/hooks/useAppKitTheme.d.ts.map +1 -0
  126. package/lib/typescript/hooks/useProvider.d.ts +1 -4
  127. package/lib/typescript/hooks/useProvider.d.ts.map +1 -1
  128. package/lib/typescript/hooks/useWalletInfo.d.ts +31 -0
  129. package/lib/typescript/hooks/useWalletInfo.d.ts.map +1 -1
  130. package/lib/typescript/index.d.ts +2 -1
  131. package/lib/typescript/index.d.ts.map +1 -1
  132. package/lib/typescript/modal/w3m-modal/styles.d.ts +1 -0
  133. package/lib/typescript/modal/w3m-modal/styles.d.ts.map +1 -1
  134. package/lib/typescript/partials/w3m-connecting-body/index.d.ts.map +1 -1
  135. package/lib/typescript/partials/w3m-connecting-qrcode/index.d.ts.map +1 -1
  136. package/lib/typescript/partials/w3m-header/index.d.ts.map +1 -1
  137. package/lib/typescript/partials/w3m-header/styles.d.ts +3 -0
  138. package/lib/typescript/partials/w3m-header/styles.d.ts.map +1 -1
  139. package/lib/typescript/partials/w3m-send-input-token/index.d.ts +2 -1
  140. package/lib/typescript/partials/w3m-send-input-token/index.d.ts.map +1 -1
  141. package/lib/typescript/partials/w3m-swap-input/index.d.ts +2 -1
  142. package/lib/typescript/partials/w3m-swap-input/index.d.ts.map +1 -1
  143. package/lib/typescript/views/w3m-account-default-view/index.d.ts.map +1 -1
  144. package/lib/typescript/views/w3m-connecting-external-view/index.d.ts.map +1 -1
  145. package/lib/typescript/views/w3m-connecting-view/index.d.ts.map +1 -1
  146. package/lib/typescript/views/w3m-onramp-settings-view/index.d.ts.map +1 -1
  147. package/lib/typescript/views/w3m-onramp-view/index.d.ts.map +1 -1
  148. package/lib/typescript/views/w3m-swap-view/index.d.ts.map +1 -1
  149. package/lib/typescript/views/w3m-wallet-send-view/index.d.ts.map +1 -1
  150. package/package.json +5 -4
  151. package/src/AppKit.ts +27 -7
  152. package/src/AppKitContext.tsx +1 -1
  153. package/src/hooks/useAccount.ts +93 -5
  154. package/src/hooks/useAppKit.ts +45 -12
  155. package/src/hooks/useAppKitContext.ts +43 -0
  156. package/src/hooks/useAppKitEvents.ts +63 -3
  157. package/src/hooks/useAppKitLogs.ts +3 -11
  158. package/src/hooks/useAppKitState.ts +35 -2
  159. package/src/hooks/useAppKitTheme.ts +81 -0
  160. package/src/hooks/useProvider.ts +3 -4
  161. package/src/hooks/useWalletInfo.ts +33 -2
  162. package/src/index.ts +2 -1
  163. package/src/modal/w3m-modal/styles.ts +2 -1
  164. package/src/partials/w3m-connecting-body/index.tsx +3 -1
  165. package/src/partials/w3m-connecting-mobile/components/StoreLink.tsx +4 -1
  166. package/src/partials/w3m-connecting-qrcode/index.tsx +10 -1
  167. package/src/partials/w3m-header/index.tsx +6 -1
  168. package/src/partials/w3m-header/styles.ts +3 -0
  169. package/src/partials/w3m-send-input-token/index.tsx +5 -1
  170. package/src/partials/w3m-swap-input/index.tsx +5 -1
  171. package/src/views/w3m-account-default-view/index.tsx +6 -1
  172. package/src/views/w3m-connecting-external-view/index.tsx +4 -8
  173. package/src/views/w3m-connecting-view/index.tsx +24 -8
  174. package/src/views/w3m-onramp-settings-view/index.tsx +7 -1
  175. package/src/views/w3m-onramp-view/index.tsx +3 -2
  176. package/src/views/w3m-swap-view/components/select-token-modal/index.tsx +1 -1
  177. package/src/views/w3m-swap-view/index.tsx +2 -0
  178. package/src/views/w3m-wallet-send-view/index.tsx +1 -0
@@ -1,27 +1,60 @@
1
- import { useContext, useMemo } from 'react';
1
+ import { useMemo } from 'react';
2
2
  import type { ChainNamespace } from '@reown/appkit-common-react-native';
3
3
 
4
4
  import type { AppKit } from '../AppKit';
5
- import { AppKitContext } from '../AppKitContext';
5
+ import { useAppKitContext } from './useAppKitContext';
6
6
 
7
+ /**
8
+ * Interface representing the return value of the useAppKit hook
9
+ */
7
10
  interface UseAppKitReturn {
11
+ /** Function to open the AppKit modal with optional view configuration */
8
12
  open: AppKit['open'];
13
+ /** Function to close the AppKit modal */
9
14
  close: AppKit['close'];
15
+ /** Function to disconnect the wallet, optionally scoped to a specific namespace */
10
16
  disconnect: (namespace?: ChainNamespace) => void;
17
+ /** Function to switch to a different network */
11
18
  switchNetwork: AppKit['switchNetwork'];
12
19
  }
13
20
 
21
+ /**
22
+ * Hook to access core AppKit functionality for controlling the modal
23
+ *
24
+ * @remarks
25
+ * This hook provides access to the main AppKit instance methods for opening/closing
26
+ * the modal, disconnecting wallets, and switching networks. All functions are memoized
27
+ * and properly bound to ensure stable references across renders.
28
+ *
29
+ * @returns {UseAppKitReturn} An object containing:
30
+ * - `open`: Opens the AppKit modal, optionally with a specific view
31
+ * - `close`: Closes the AppKit modal
32
+ * - `disconnect`: Disconnects the current wallet connection (optionally for a specific namespace)
33
+ * - `switchNetwork`: Switches to a different blockchain network
34
+ *
35
+ * @throws {Error} If used outside of an AppKitProvider
36
+ * @throws {Error} If AppKit instance is not available in context
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * function MyComponent() {
41
+ * const { open, close, disconnect, switchNetwork } = useAppKit();
42
+ *
43
+ * return (
44
+ * <View>
45
+ * <Button onPress={() => open()} title="Connect Wallet" />
46
+ * <Button onPress={() => disconnect()} title="Disconnect" />
47
+ * <Button
48
+ * onPress={() => switchNetwork('eip155:1')}
49
+ * title="Switch to Ethereum"
50
+ * />
51
+ * </View>
52
+ * );
53
+ * }
54
+ * ```
55
+ */
14
56
  export const useAppKit = (): UseAppKitReturn => {
15
- const context = useContext(AppKitContext);
16
-
17
- if (context === undefined) {
18
- throw new Error('useAppKit must be used within an AppKitProvider');
19
- }
20
-
21
- if (!context.appKit) {
22
- // This might happen if the provider is rendered before AppKit is initialized
23
- throw new Error('AppKit instance is not yet available in context.');
24
- }
57
+ const context = useAppKitContext();
25
58
 
26
59
  const stableFunctions = useMemo(() => {
27
60
  if (!context.appKit) {
@@ -0,0 +1,43 @@
1
+ import { useContext } from 'react';
2
+
3
+ import { AppKitContext, type AppKitContextType } from '../AppKitContext';
4
+
5
+ /**
6
+ * Hook to access the AppKit context
7
+ *
8
+ * @remarks
9
+ * This is an internal hook used by other AppKit hooks to ensure they're used within
10
+ * the AppKitProvider. You typically don't need to use this hook directly - use the
11
+ * higher-level hooks like `useAppKit`, `useAccount`, `useAppKitTheme`, etc. instead.
12
+ *
13
+ * @returns {AppKitContextType} The AppKit context containing the AppKit instance
14
+ *
15
+ * @throws {Error} If used outside of an AppKitProvider
16
+ * @throws {Error} If the AppKit instance is not yet available in context
17
+ *
18
+ * @internal
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * // This is typically used internally by other hooks
23
+ * function MyCustomHook() {
24
+ * const context = useAppKitContext();
25
+ * // Use context.appKit...
26
+ * }
27
+ * ```
28
+ */
29
+
30
+ export const useAppKitContext = (): AppKitContextType => {
31
+ const context = useContext(AppKitContext);
32
+
33
+ if (context === undefined) {
34
+ throw new Error('useAppKitContext must be used within an AppKitProvider');
35
+ }
36
+
37
+ if (!context.appKit) {
38
+ // This might happen if the provider is rendered before AppKit is initialized
39
+ throw new Error('AppKit instance is not yet available in context.');
40
+ }
41
+
42
+ return context;
43
+ };
@@ -2,10 +2,42 @@ import { useEffect } from 'react';
2
2
  import { useSnapshot } from 'valtio';
3
3
  import { EventsController, type EventsControllerState } from '@reown/appkit-core-react-native';
4
4
  import { type EventName } from '@reown/appkit-common-react-native';
5
- import { useAppKit } from './useAppKit';
5
+ import { useAppKitContext } from './useAppKitContext';
6
6
 
7
+ /**
8
+ * Hook to subscribe to all AppKit events
9
+ *
10
+ * @remarks
11
+ * This hook provides reactive access to AppKit's event system, allowing you to
12
+ * monitor all events that occur within the AppKit lifecycle (connections, disconnections,
13
+ * network changes, etc.). The callback is invoked whenever a new event is emitted.
14
+ *
15
+ * @param callback - Optional callback function invoked when any event occurs
16
+ *
17
+ * @returns An object containing:
18
+ * - `data`: The most recent event data
19
+ * - `timestamp`: The timestamp of the most recent event
20
+ *
21
+ * @throws {Error} If used outside of an AppKitProvider
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * function MyComponent() {
26
+ * const { data, timestamp } = useAppKitEvents((event) => {
27
+ * console.log('Event occurred:', event.data.event);
28
+ * });
29
+ *
30
+ * return (
31
+ * <View>
32
+ * <Text>Last event: {data?.event}</Text>
33
+ * <Text>Time: {timestamp}</Text>
34
+ * </View>
35
+ * );
36
+ * }
37
+ * ```
38
+ */
7
39
  export function useAppKitEvents(callback?: (newEvent: EventsControllerState) => void) {
8
- useAppKit(); // Use the hook for checks
40
+ useAppKitContext();
9
41
  const { data, timestamp } = useSnapshot(EventsController.state);
10
42
 
11
43
  useEffect(() => {
@@ -21,11 +53,39 @@ export function useAppKitEvents(callback?: (newEvent: EventsControllerState) =>
21
53
  return { data, timestamp };
22
54
  }
23
55
 
56
+ /**
57
+ * Hook to subscribe to a specific AppKit event
58
+ *
59
+ * @remarks
60
+ * This hook allows you to listen for a specific event type rather than all events.
61
+ * It's more efficient than `useAppKitEvents` when you only care about a particular event.
62
+ *
63
+ * @param event - The specific event name to subscribe to (e.g., 'MODAL_OPEN', 'CONNECT_SUCCESS')
64
+ * @param callback - Callback function invoked when the specified event occurs
65
+ *
66
+ * @throws {Error} If used outside of an AppKitProvider
67
+ *
68
+ * @example
69
+ * ```tsx
70
+ * function MyComponent() {
71
+ * useAppKitEventSubscription('CONNECT_SUCCESS', (event) => {
72
+ * console.log('Wallet connected!', event.data);
73
+ * });
74
+ *
75
+ * useAppKitEventSubscription('DISCONNECT_SUCCESS', (event) => {
76
+ * console.log('Wallet disconnected!', event.data);
77
+ * });
78
+ *
79
+ * return <View>{/ Your component /}</View>;
80
+ * }
81
+ * ```
82
+ */
83
+
24
84
  export function useAppKitEventSubscription(
25
85
  event: EventName,
26
86
  callback: (newEvent: EventsControllerState) => void
27
87
  ) {
28
- useAppKit(); // Use the hook for checks
88
+ useAppKitContext();
29
89
 
30
90
  useEffect(() => {
31
91
  const unsubscribe = EventsController?.subscribeEvent(event, callback);
@@ -1,7 +1,7 @@
1
- import { useContext, useMemo } from 'react';
1
+ import { useMemo } from 'react';
2
2
  import { useSnapshot } from 'valtio';
3
3
  import { LogController, type LogEntry, type LogLevel } from '@reown/appkit-core-react-native';
4
- import { AppKitContext } from '../AppKitContext';
4
+ import { useAppKitContext } from './useAppKitContext';
5
5
 
6
6
  export interface UseAppKitLogsReturn {
7
7
  /**
@@ -65,15 +65,7 @@ export interface UseAppKitLogsReturn {
65
65
  * ```
66
66
  */
67
67
  export const useAppKitLogs = (): UseAppKitLogsReturn => {
68
- const context = useContext(AppKitContext);
69
-
70
- if (context === undefined) {
71
- throw new Error('useAppKitLogs must be used within an AppKitProvider');
72
- }
73
-
74
- if (!context.appKit) {
75
- throw new Error('AppKit instance is not yet available in context.');
76
- }
68
+ useAppKitContext();
77
69
 
78
70
  const { logs } = useSnapshot(LogController.state);
79
71
 
@@ -2,10 +2,43 @@
2
2
  import { useMemo } from 'react';
3
3
  import { useSnapshot } from 'valtio';
4
4
  import { ConnectionsController, ModalController } from '@reown/appkit-core-react-native';
5
- import { useAppKit } from './useAppKit';
5
+ import { useAppKitContext } from './useAppKitContext';
6
+
7
+ /**
8
+ * Hook to access the overall state of the AppKit modal and connection
9
+ *
10
+ * @remarks
11
+ * This hook provides a high-level view of the AppKit's current state, including
12
+ * whether the modal is open, if it's loading, connection status, and the active chain.
13
+ * It's useful for coordinating UI elements with the AppKit's state.
14
+ *
15
+ * @returns An object containing:
16
+ * - `isOpen`: Whether the AppKit modal is currently open
17
+ * - `isLoading`: Whether the AppKit is in a loading state
18
+ * - `isConnected`: Whether a wallet is currently connected
19
+ * - `chain`: The currently active blockchain network
20
+ *
21
+ * @throws {Error} If used outside of an AppKitProvider
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * function MyComponent() {
26
+ * const { isOpen, isLoading, isConnected, chain } = useAppKitState();
27
+ *
28
+ * return (
29
+ * <View>
30
+ * <Text>Modal: {isOpen ? 'Open' : 'Closed'}</Text>
31
+ * <Text>Loading: {isLoading ? 'Yes' : 'No'}</Text>
32
+ * <Text>Connected: {isConnected ? 'Yes' : 'No'}</Text>
33
+ * {chain && <Text>Chain: {chain.name}</Text>}
34
+ * </View>
35
+ * );
36
+ * }
37
+ * ```
38
+ */
6
39
 
7
40
  export function useAppKitState() {
8
- useAppKit(); // Use the hook for checks
41
+ useAppKitContext();
9
42
  const { activeAddress: address, connection, networks } = useSnapshot(ConnectionsController.state);
10
43
  const { open, loading } = useSnapshot(ModalController.state);
11
44
 
@@ -0,0 +1,81 @@
1
+ import { useMemo } from 'react';
2
+ import { useSnapshot } from 'valtio';
3
+ import type { ThemeMode, ThemeVariables } from '@reown/appkit-common-react-native';
4
+ import { ThemeController } from '@reown/appkit-core-react-native';
5
+ import { useAppKitContext } from './useAppKitContext';
6
+
7
+ /**
8
+ * Interface representing the result of the useAppKitTheme hook
9
+ */
10
+ export interface UseAppKitThemeReturn {
11
+ /** The current theme mode ('dark' or 'light'), or undefined if using system default */
12
+ themeMode?: ThemeMode;
13
+ /** The current theme variables, currently only supports 'accent' color */
14
+ themeVariables: ThemeVariables;
15
+ /** Function to set the theme mode */
16
+ setThemeMode: (themeMode: ThemeMode | undefined) => void;
17
+ /** Function to set theme variables */
18
+ setThemeVariables: (themeVariables: ThemeVariables | undefined) => void;
19
+ }
20
+
21
+ /**
22
+ * Hook to control the visual appearance of the AppKit modal
23
+ *
24
+ * @remarks
25
+ * This hook provides access to the theme mode and theme variables, allowing you to
26
+ * customize the modal's appearance. Use this hook when you need to implement dark/light
27
+ * mode or match the modal's appearance with your application's theme.
28
+ *
29
+ * Currently, the only supported theme variable is `accent`, which controls the primary
30
+ * accent color used throughout the modal interface.
31
+ *
32
+ * @returns {UseAppKitThemeReturn} An object containing:
33
+ * - `themeMode`: The current theme mode ('dark' or 'light')
34
+ * - `themeVariables`: The current theme variables (only 'accent' is supported)
35
+ * - `setThemeMode`: Function to change the theme mode
36
+ * - `setThemeVariables`: Function to update theme variables
37
+ *
38
+ * @throws {Error} If used outside of an AppKitProvider
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import { useAppKitTheme } from '@reown/appkit-react-native';
43
+ *
44
+ * function MyComponent() {
45
+ * const { themeMode, themeVariables, setThemeMode, setThemeVariables } = useAppKitTheme();
46
+ *
47
+ * // Set theme to dark mode
48
+ * setThemeMode('dark');
49
+ *
50
+ * // Customize the accent color
51
+ * setThemeVariables({
52
+ * accent: '#00BB7F'
53
+ * });
54
+ *
55
+ * return (
56
+ * <View>
57
+ * <Text>Current theme: {themeMode}</Text>
58
+ * <Text>Accent color: {themeVariables?.accent}</Text>
59
+ * </View>
60
+ * );
61
+ * }
62
+ * ```
63
+ */
64
+ export function useAppKitTheme(): UseAppKitThemeReturn {
65
+ useAppKitContext();
66
+ const { themeMode, themeVariables } = useSnapshot(ThemeController.state);
67
+
68
+ const stableFunctions = useMemo(
69
+ () => ({
70
+ setThemeMode: ThemeController.setThemeMode.bind(ThemeController),
71
+ setThemeVariables: ThemeController.setThemeVariables.bind(ThemeController)
72
+ }),
73
+ []
74
+ );
75
+
76
+ return {
77
+ themeMode,
78
+ themeVariables,
79
+ ...stableFunctions
80
+ };
81
+ }
@@ -3,6 +3,7 @@ import { useMemo } from 'react';
3
3
  import { useSnapshot } from 'valtio';
4
4
  import { ConnectionsController, LogController } from '@reown/appkit-core-react-native';
5
5
  import type { Provider, ChainNamespace } from '@reown/appkit-common-react-native';
6
+ import { useAppKitContext } from './useAppKitContext';
6
7
 
7
8
  /**
8
9
  * Interface representing the result of the useProvider hook
@@ -29,14 +30,12 @@ interface ProviderResult {
29
30
  *
30
31
  * if (provider) {
31
32
  * // Use the provider for blockchain operations
32
- * const balance = await provider.request({
33
- * method: 'eth_getBalance',
34
- * params: [address, 'latest']
35
- * });
33
+ * const balance = await provider.request({...});
36
34
  * }
37
35
  * ```
38
36
  */
39
37
  export function useProvider(): ProviderResult {
38
+ useAppKitContext();
40
39
  const { connection } = useSnapshot(ConnectionsController.state);
41
40
 
42
41
  const returnValue = useMemo(() => {
@@ -1,10 +1,41 @@
1
1
  import { useMemo } from 'react';
2
2
  import { useSnapshot } from 'valtio';
3
3
  import { ConnectionsController } from '@reown/appkit-core-react-native';
4
- import { useAppKit } from './useAppKit';
4
+ import { useAppKitContext } from './useAppKitContext';
5
5
 
6
+ /**
7
+ * Hook to access information about the currently connected wallet
8
+ *
9
+ * @remarks
10
+ * This hook provides access to metadata about the connected wallet, such as its name,
11
+ * icon, and other identifying information. It automatically subscribes to wallet info
12
+ * changes via valtio.
13
+ *
14
+ * @returns An object containing:
15
+ * - `walletInfo`: Metadata about the currently connected wallet (name, icon, etc.)
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * function MyComponent() {
20
+ * const { walletInfo } = useWalletInfo();
21
+ *
22
+ * return (
23
+ * <View>
24
+ * {walletInfo && (
25
+ * <>
26
+ * <Image source={{ uri: walletInfo.icon }} />
27
+ * <Text>{walletInfo.name}</Text>
28
+ * </>
29
+ * )}
30
+ * </View>
31
+ * );
32
+ * }
33
+ * ```
34
+ *
35
+ * @throws {Error} If used outside of an AppKitProvider
36
+ */
6
37
  export function useWalletInfo() {
7
- useAppKit(); // Use the hook for checks
38
+ useAppKitContext();
8
39
  const { walletInfo: walletInfoSnapshot } = useSnapshot(ConnectionsController.state);
9
40
 
10
41
  const walletInfo = useMemo(() => ({ walletInfo: walletInfoSnapshot }), [walletInfoSnapshot]);
package/src/index.ts CHANGED
@@ -31,7 +31,8 @@ export type { AppKitConfig } from './types';
31
31
  /****** Hooks *******/
32
32
  export { useAppKit } from './hooks/useAppKit';
33
33
  export { useProvider } from './hooks/useProvider';
34
- export { useAccount } from './hooks/useAccount';
34
+ export { useAccount, type Account as UseAccountReturn } from './hooks/useAccount';
35
+ export { useAppKitTheme, type UseAppKitThemeReturn } from './hooks/useAppKitTheme';
35
36
  export { useWalletInfo } from './hooks/useWalletInfo';
36
37
  export { useAppKitEvents, useAppKitEventSubscription } from './hooks/useAppKitEvents';
37
38
  export { useAppKitState } from './hooks/useAppKitState';
@@ -3,6 +3,7 @@ import { StyleSheet } from 'react-native';
3
3
  export default StyleSheet.create({
4
4
  card: {
5
5
  borderBottomLeftRadius: 0,
6
- borderBottomRightRadius: 0
6
+ borderBottomRightRadius: 0,
7
+ borderWidth: 0
7
8
  }
8
9
  });
@@ -11,7 +11,9 @@ export interface ConnectingBodyProps {
11
11
  export function ConnectingBody({ title, description }: ConnectingBodyProps) {
12
12
  return (
13
13
  <FlexView padding={['3xs', '2xl', '0', '2xl']} alignItems="center" style={styles.textContainer}>
14
- <Text variant="paragraph-500">{title}</Text>
14
+ <Text center numberOfLines={1} variant="paragraph-500">
15
+ {title}
16
+ </Text>
15
17
  {description ? (
16
18
  <Text center variant="small-400" color="fg-200" style={styles.descriptionText}>
17
19
  {description}
@@ -12,7 +12,7 @@ export function StoreLink({ visible, walletName = 'Wallet', onPress }: StoreLink
12
12
 
13
13
  return (
14
14
  <ActionEntry style={styles.storeButton}>
15
- <Text numberOfLines={1} variant="paragraph-500" color="fg-200">
15
+ <Text numberOfLines={1} style={styles.storeText} variant="paragraph-500" color="fg-200">
16
16
  {`Don't have ${walletName}?`}
17
17
  </Text>
18
18
  <Button
@@ -34,5 +34,8 @@ const styles = StyleSheet.create({
34
34
  paddingHorizontal: Spacing.l,
35
35
  marginHorizontal: Spacing.xl,
36
36
  marginTop: Spacing.l
37
+ },
38
+ storeText: {
39
+ flexShrink: 1
37
40
  }
38
41
  });
@@ -20,6 +20,9 @@ import styles from './styles';
20
20
  import { ReownButton } from './components/ReownButton';
21
21
  import { useWindowDimensions } from 'react-native';
22
22
 
23
+ const LOGO_SIZE = 60;
24
+ const LOGO_BORDER_RADIUS = 10;
25
+
23
26
  export function ConnectingQrCode() {
24
27
  const { height, width } = useWindowDimensions();
25
28
  const windowSize = Math.min(height, width);
@@ -65,7 +68,13 @@ export function ConnectingQrCode() {
65
68
  flexDirection={isPortrait ? 'column' : 'row'}
66
69
  padding={['xl', 'xl', 'xs', 'xl']}
67
70
  >
68
- <QrCode size={qrSize} uri={wcUri} testID="qr-code" />
71
+ <QrCode
72
+ size={qrSize}
73
+ uri={wcUri}
74
+ testID="qr-code"
75
+ logoBorderRadius={LOGO_BORDER_RADIUS}
76
+ logoSize={LOGO_SIZE}
77
+ />
69
78
  <FlexView alignItems="center" margin="m">
70
79
  <Text variant="paragraph-500">Scan this QR code with your phone</Text>
71
80
  {showCopy ? (
@@ -100,7 +100,12 @@ export function Header() {
100
100
  padding={['l', 'xl', bottomPadding, 'xl']}
101
101
  >
102
102
  {dynamicButtonTemplate()}
103
- <Text variant="paragraph-600" numberOfLines={1} testID="header-text">
103
+ <Text
104
+ variant="paragraph-600"
105
+ numberOfLines={1}
106
+ style={styles.headerText}
107
+ testID="header-text"
108
+ >
104
109
  {header}
105
110
  </Text>
106
111
  {showClose ? (
@@ -4,5 +4,8 @@ export default StyleSheet.create({
4
4
  iconPlaceholder: {
5
5
  height: 32,
6
6
  width: 32
7
+ },
8
+ headerText: {
9
+ flexShrink: 1
7
10
  }
8
11
  });
@@ -20,6 +20,7 @@ export interface SendInputTokenProps {
20
20
  style?: StyleProp<ViewStyle>;
21
21
  onTokenPress?: () => void;
22
22
  loading?: boolean;
23
+ testID?: string;
23
24
  }
24
25
 
25
26
  export function SendInputToken({
@@ -27,7 +28,8 @@ export function SendInputToken({
27
28
  sendTokenAmount,
28
29
  style,
29
30
  onTokenPress,
30
- loading
31
+ loading,
32
+ testID
31
33
  }: SendInputTokenProps) {
32
34
  const Theme = useTheme();
33
35
  const valueInputRef = useRef<TextInput | null>(null);
@@ -86,12 +88,14 @@ export function SendInputToken({
86
88
  selectTextOnFocus={false}
87
89
  numberOfLines={1}
88
90
  autoFocus={!!token}
91
+ testID={testID}
89
92
  />
90
93
  <TokenButton
91
94
  imageUrl={token?.iconUrl}
92
95
  text={token?.symbol}
93
96
  onPress={onTokenPress}
94
97
  chevron
98
+ testID={testID ? `${testID}-button` : undefined}
95
99
  />
96
100
  </FlexView>
97
101
  {token ? (
@@ -28,6 +28,7 @@ export interface SwapInputProps {
28
28
  marketValue?: number;
29
29
  editable?: boolean;
30
30
  autoFocus?: boolean;
31
+ testID?: string;
31
32
  }
32
33
 
33
34
  const MINIMUM_USD_VALUE_TO_CONVERT = 0.00005;
@@ -43,7 +44,8 @@ export function SwapInput({
43
44
  onChange,
44
45
  marketValue,
45
46
  editable,
46
- autoFocus
47
+ autoFocus,
48
+ testID
47
49
  }: SwapInputProps) {
48
50
  const Theme = useTheme();
49
51
  const valueInputRef = useRef<TextInput | null>(null);
@@ -118,6 +120,7 @@ export function SwapInput({
118
120
  numberOfLines={1}
119
121
  editable={editable}
120
122
  autoFocus={autoFocus}
123
+ testID={testID}
121
124
  />
122
125
  )}
123
126
  <TokenButton
@@ -125,6 +128,7 @@ export function SwapInput({
125
128
  imageUrl={token?.logoUri}
126
129
  onPress={onTokenPress}
127
130
  chevron
131
+ testID={testID ? `${testID}-button` : undefined}
128
132
  />
129
133
  </FlexView>
130
134
  {loadingValues ? (
@@ -186,7 +186,12 @@ export function AccountDefaultView() {
186
186
  return (
187
187
  <>
188
188
  {showBack ? (
189
- <IconLink icon="chevronLeft" style={styles.backIcon} onPress={RouterController.goBack} />
189
+ <IconLink
190
+ icon="chevronLeft"
191
+ style={styles.backIcon}
192
+ onPress={RouterController.goBack}
193
+ testID="header-back"
194
+ />
190
195
  ) : null}
191
196
  <IconLink
192
197
  icon="close"
@@ -26,6 +26,7 @@ import styles from './styles';
26
26
  import { useInternalAppKit } from '../../AppKitContext';
27
27
  import { StoreLink } from '../../partials/w3m-connecting-mobile/components/StoreLink';
28
28
  import { WcHelpersUtil } from '../../utils/HelpersUtil';
29
+ import { ErrorUtil } from '@reown/appkit-common-react-native';
29
30
 
30
31
  export function ConnectingExternalView() {
31
32
  const { data } = useSnapshot(RouterController.state);
@@ -94,16 +95,11 @@ export function ConnectingExternalView() {
94
95
  }
95
96
  } catch (error) {
96
97
  LogController.sendError(error, 'ConnectingExternalView.tsx', 'onConnect');
97
- if (/(Wallet not found)/i.test((error as Error).message)) {
98
- setErrorType('not_installed');
99
- } else if (/(rejected)/i.test((error as Error).message)) {
100
- setErrorType('declined');
101
- } else {
102
- setErrorType('default');
103
- }
98
+ const type = ErrorUtil.categorizeConnectionError(error);
99
+ setErrorType(type);
104
100
  EventsController.sendEvent({
105
101
  type: 'track',
106
- event: 'CONNECT_ERROR',
102
+ event: type === 'declined' ? 'USER_REJECTED' : 'CONNECT_ERROR',
107
103
  properties: { message: (error as Error)?.message ?? 'Unknown' }
108
104
  });
109
105
  }