@reown/appkit-react-native 0.0.0-chore-examples-20251009175707 → 0.0.0-chore-use-theme-hook-20251105184714

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 (89) 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 +66 -2
  4. package/lib/commonjs/hooks/useAccount.js.map +1 -1
  5. package/lib/commonjs/hooks/useAppKitTheme.js +74 -0
  6. package/lib/commonjs/hooks/useAppKitTheme.js.map +1 -0
  7. package/lib/commonjs/modal/w3m-modal/styles.js +2 -1
  8. package/lib/commonjs/modal/w3m-modal/styles.js.map +1 -1
  9. package/lib/commonjs/partials/w3m-connecting-qrcode/index.js +5 -1
  10. package/lib/commonjs/partials/w3m-connecting-qrcode/index.js.map +1 -1
  11. package/lib/commonjs/partials/w3m-send-input-token/index.js +6 -3
  12. package/lib/commonjs/partials/w3m-send-input-token/index.js.map +1 -1
  13. package/lib/commonjs/partials/w3m-swap-input/index.js +6 -3
  14. package/lib/commonjs/partials/w3m-swap-input/index.js.map +1 -1
  15. package/lib/commonjs/views/w3m-account-default-view/index.js +2 -1
  16. package/lib/commonjs/views/w3m-account-default-view/index.js.map +1 -1
  17. package/lib/commonjs/views/w3m-onramp-settings-view/index.js +2 -0
  18. package/lib/commonjs/views/w3m-onramp-settings-view/index.js.map +1 -1
  19. package/lib/commonjs/views/w3m-onramp-view/index.js +3 -2
  20. package/lib/commonjs/views/w3m-onramp-view/index.js.map +1 -1
  21. package/lib/commonjs/views/w3m-swap-view/components/select-token-modal/index.js +2 -1
  22. package/lib/commonjs/views/w3m-swap-view/components/select-token-modal/index.js.map +1 -1
  23. package/lib/commonjs/views/w3m-swap-view/index.js +4 -2
  24. package/lib/commonjs/views/w3m-swap-view/index.js.map +1 -1
  25. package/lib/commonjs/views/w3m-wallet-send-view/index.js +2 -1
  26. package/lib/commonjs/views/w3m-wallet-send-view/index.js.map +1 -1
  27. package/lib/module/AppKit.js +20 -6
  28. package/lib/module/AppKit.js.map +1 -1
  29. package/lib/module/hooks/useAccount.js +67 -2
  30. package/lib/module/hooks/useAccount.js.map +1 -1
  31. package/lib/module/hooks/useAppKitTheme.js +71 -0
  32. package/lib/module/hooks/useAppKitTheme.js.map +1 -0
  33. package/lib/module/index.js.map +1 -1
  34. package/lib/module/modal/w3m-modal/styles.js +2 -1
  35. package/lib/module/modal/w3m-modal/styles.js.map +1 -1
  36. package/lib/module/partials/w3m-connecting-qrcode/index.js +5 -1
  37. package/lib/module/partials/w3m-connecting-qrcode/index.js.map +1 -1
  38. package/lib/module/partials/w3m-send-input-token/index.js +6 -3
  39. package/lib/module/partials/w3m-send-input-token/index.js.map +1 -1
  40. package/lib/module/partials/w3m-swap-input/index.js +6 -3
  41. package/lib/module/partials/w3m-swap-input/index.js.map +1 -1
  42. package/lib/module/views/w3m-account-default-view/index.js +2 -1
  43. package/lib/module/views/w3m-account-default-view/index.js.map +1 -1
  44. package/lib/module/views/w3m-onramp-settings-view/index.js +2 -0
  45. package/lib/module/views/w3m-onramp-settings-view/index.js.map +1 -1
  46. package/lib/module/views/w3m-onramp-view/index.js +3 -2
  47. package/lib/module/views/w3m-onramp-view/index.js.map +1 -1
  48. package/lib/module/views/w3m-swap-view/components/select-token-modal/index.js +2 -1
  49. package/lib/module/views/w3m-swap-view/components/select-token-modal/index.js.map +1 -1
  50. package/lib/module/views/w3m-swap-view/index.js +4 -2
  51. package/lib/module/views/w3m-swap-view/index.js.map +1 -1
  52. package/lib/module/views/w3m-wallet-send-view/index.js +2 -1
  53. package/lib/module/views/w3m-wallet-send-view/index.js.map +1 -1
  54. package/lib/typescript/AppKit.d.ts +9 -2
  55. package/lib/typescript/AppKit.d.ts.map +1 -1
  56. package/lib/typescript/AppKitContext.d.ts +1 -1
  57. package/lib/typescript/hooks/useAccount.d.ts +57 -33
  58. package/lib/typescript/hooks/useAccount.d.ts.map +1 -1
  59. package/lib/typescript/hooks/useAppKitTheme.d.ts +60 -0
  60. package/lib/typescript/hooks/useAppKitTheme.d.ts.map +1 -0
  61. package/lib/typescript/index.d.ts +1 -1
  62. package/lib/typescript/index.d.ts.map +1 -1
  63. package/lib/typescript/modal/w3m-modal/styles.d.ts +1 -0
  64. package/lib/typescript/modal/w3m-modal/styles.d.ts.map +1 -1
  65. package/lib/typescript/partials/w3m-connecting-qrcode/index.d.ts.map +1 -1
  66. package/lib/typescript/partials/w3m-send-input-token/index.d.ts +2 -1
  67. package/lib/typescript/partials/w3m-send-input-token/index.d.ts.map +1 -1
  68. package/lib/typescript/partials/w3m-swap-input/index.d.ts +2 -1
  69. package/lib/typescript/partials/w3m-swap-input/index.d.ts.map +1 -1
  70. package/lib/typescript/views/w3m-account-default-view/index.d.ts.map +1 -1
  71. package/lib/typescript/views/w3m-onramp-settings-view/index.d.ts.map +1 -1
  72. package/lib/typescript/views/w3m-onramp-view/index.d.ts.map +1 -1
  73. package/lib/typescript/views/w3m-swap-view/index.d.ts.map +1 -1
  74. package/lib/typescript/views/w3m-wallet-send-view/index.d.ts.map +1 -1
  75. package/package.json +4 -4
  76. package/src/AppKit.ts +27 -7
  77. package/src/hooks/useAccount.ts +91 -3
  78. package/src/hooks/useAppKitTheme.ts +81 -0
  79. package/src/index.ts +1 -1
  80. package/src/modal/w3m-modal/styles.ts +2 -1
  81. package/src/partials/w3m-connecting-qrcode/index.tsx +10 -1
  82. package/src/partials/w3m-send-input-token/index.tsx +5 -1
  83. package/src/partials/w3m-swap-input/index.tsx +5 -1
  84. package/src/views/w3m-account-default-view/index.tsx +6 -1
  85. package/src/views/w3m-onramp-settings-view/index.tsx +7 -1
  86. package/src/views/w3m-onramp-view/index.tsx +3 -2
  87. package/src/views/w3m-swap-view/components/select-token-modal/index.tsx +1 -1
  88. package/src/views/w3m-swap-view/index.tsx +2 -0
  89. package/src/views/w3m-wallet-send-view/index.tsx +1 -0
@@ -1,9 +1,68 @@
1
1
  /* eslint-disable valtio/state-snapshot-rule */
2
+ import {
3
+ ConnectionsController,
4
+ CoreHelperUtil,
5
+ LogController
6
+ } from '@reown/appkit-core-react-native';
2
7
  import { useMemo } from 'react';
3
8
  import { useSnapshot } from 'valtio';
4
- import { ConnectionsController, CoreHelperUtil } from '@reown/appkit-core-react-native';
5
9
  import { useAppKit } from './useAppKit';
10
+ import type { AccountType, AppKitNetwork } from '@reown/appkit-common-react-native';
6
11
 
12
+ /**
13
+ * Represents a blockchain account with its associated metadata
14
+ */
15
+ export interface Account {
16
+ /** The blockchain address of the account */
17
+ address: string;
18
+ /** The blockchain namespace (e.g., 'eip155' for Ethereum, 'solana' for Solana) */
19
+ namespace: string;
20
+ /** The chain ID where this account is active */
21
+ chainId: string;
22
+ /** Optional account type (e.g. 'eoa' or 'smartAccount') */
23
+ type?: AccountType;
24
+ }
25
+
26
+ /**
27
+ * Hook to access the current account state and connection information
28
+ *
29
+ * @remarks
30
+ * This hook provides access to all connected accounts, the currently active account,
31
+ * connection status, and active chain information. It automatically subscribes to
32
+ * connection state changes via valtio.
33
+ *
34
+ * The hook parses account data from CAIP-10 format (namespace:chainId:address)
35
+ * and provides a normalized structure.
36
+ *
37
+ * @returns An object containing:
38
+ * - `allAccounts` - Array of all connected accounts across all connections
39
+ * - `address` - The plain address of the currently active account (without namespace or chain prefix)
40
+ * - `isConnected` - Boolean indicating if a wallet is currently connected
41
+ * - `chainId` - The ID of the currently active chain
42
+ * - `chain` - The full chain/network object of the currently active chain
43
+ * - `namespace` - The namespace of the currently active account (e.g. 'eip155', 'solana' or 'bip122')
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * function MyComponent() {
48
+ * const { address, isConnected, chainId, allAccounts } = useAccount();
49
+ *
50
+ * if (!isConnected) {
51
+ * return <Text>Not connected</Text>;
52
+ * }
53
+ *
54
+ * return (
55
+ * <View>
56
+ * <Text>Connected: {address}</Text>
57
+ * <Text>Chain: {chainId}</Text>
58
+ * <Text>Total accounts: {allAccounts.length}</Text>
59
+ * </View>
60
+ * );
61
+ * }
62
+ * ```
63
+ *
64
+ * @throws Will log errors via LogController if account parsing fails
65
+ */
7
66
  export function useAccount() {
8
67
  useAppKit(); // Use the hook for checks
9
68
 
@@ -11,9 +70,37 @@ export function useAccount() {
11
70
  activeAddress: address,
12
71
  activeNamespace,
13
72
  connection,
73
+ connections,
14
74
  networks
15
75
  } = useSnapshot(ConnectionsController.state);
16
76
 
77
+ const allAccounts: Account[] = useMemo(() => {
78
+ if (!address) return [];
79
+
80
+ return Array.from(connections.values()).flatMap(
81
+ _connection =>
82
+ _connection.accounts
83
+ .map(account => {
84
+ const [namespace, chainId, plainAddress] = account.split(':');
85
+ if (!plainAddress || !namespace || !chainId) {
86
+ LogController.sendError('Invalid account', 'useAccount.ts', 'useAccount', {
87
+ account
88
+ });
89
+
90
+ return undefined;
91
+ }
92
+
93
+ return {
94
+ address: plainAddress,
95
+ namespace,
96
+ chainId,
97
+ type: _connection.type
98
+ };
99
+ })
100
+ .filter(account => account !== undefined) as Account[]
101
+ );
102
+ }, [connections, address]);
103
+
17
104
  const activeChain = useMemo(
18
105
  () =>
19
106
  connection?.caipNetwork
@@ -23,10 +110,11 @@ export function useAccount() {
23
110
  );
24
111
 
25
112
  return {
113
+ allAccounts,
26
114
  address: CoreHelperUtil.getPlainAddress(address),
27
115
  isConnected: !!address,
28
- chainId: activeChain?.id,
29
- chain: activeChain,
116
+ chainId: activeChain?.id !== undefined ? String(activeChain.id) : undefined,
117
+ chain: activeChain as AppKitNetwork | undefined,
30
118
  namespace: activeNamespace
31
119
  };
32
120
  }
@@ -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 { useAppKit } from './useAppKit';
6
+
7
+ /**
8
+ * Interface representing the result of the useAppKitTheme hook
9
+ */
10
+ interface UseAppKitThemeReturn {
11
+ /** The current theme mode ('dark' or 'light'), or undefined if using system default */
12
+ themeMode: ThemeMode | undefined;
13
+ /** The current theme variables, currently only supports 'accent' color */
14
+ themeVariables: ThemeVariables | undefined;
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
+ useAppKit(); // Use the hook for checks
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
+ }
package/src/index.ts CHANGED
@@ -31,7 +31,7 @@ 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
35
  export { useWalletInfo } from './hooks/useWalletInfo';
36
36
  export { useAppKitEvents, useAppKitEventSubscription } from './hooks/useAppKitEvents';
37
37
  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
  });
@@ -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 = 20;
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 ? (
@@ -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"
@@ -90,6 +90,7 @@ export function OnRampSettingsView() {
90
90
  chevron
91
91
  style={styles.firstItem}
92
92
  contentStyle={styles.listItem}
93
+ testID="button-select-country"
93
94
  >
94
95
  <FlexView
95
96
  alignItems="center"
@@ -111,7 +112,12 @@ export function OnRampSettingsView() {
111
112
  ) : null}
112
113
  </FlexView>
113
114
  </ListItem>
114
- <ListItem onPress={onPaymentCurrencyPress} chevron contentStyle={styles.listItem}>
115
+ <ListItem
116
+ onPress={onPaymentCurrencyPress}
117
+ chevron
118
+ contentStyle={styles.listItem}
119
+ testID="button-select-currency"
120
+ >
115
121
  <FlexView
116
122
  alignItems="center"
117
123
  justifyContent="center"
@@ -61,6 +61,7 @@ export function OnRampView() {
61
61
  const purchaseCurrencyCode =
62
62
  purchaseCurrency?.currencyCode?.split('_')[0] ?? purchaseCurrency?.currencyCode;
63
63
  const networkImage = AssetUtil.getNetworkImage(activeNetwork, networkImages);
64
+ const isContinueDisabled = quotesLoading || loading || !selectedQuote;
64
65
 
65
66
  const getQuotes = useCallback(() => {
66
67
  if (OnRampController.canGenerateQuote()) {
@@ -240,8 +241,8 @@ export function OnRampView() {
240
241
  <Button
241
242
  style={styles.continueButton}
242
243
  onPress={handleContinue}
243
- disabled={quotesLoading || loading || !selectedQuote}
244
- testID="button-continue"
244
+ disabled={isContinueDisabled}
245
+ testID={`button-continue${isContinueDisabled ? '-disabled' : '-enabled'}`}
245
246
  >
246
247
  Continue
247
248
  </Button>
@@ -98,7 +98,7 @@ export function SwapSelectTokenModal({ onClose, type, style, visible }: Props) {
98
98
  alignItems="center"
99
99
  padding={['0', 'm', 'm', 'm']}
100
100
  >
101
- <IconLink icon="chevronLeft" size="md" onPress={onClose} />
101
+ <IconLink icon="chevronLeft" size="md" onPress={onClose} testID="button-back" />
102
102
  <Text variant="paragraph-600">Select token</Text>
103
103
  <View style={styles.iconPlaceholder} />
104
104
  </FlexView>
@@ -174,6 +174,7 @@ export function SwapView() {
174
174
  onChange={onSourceTokenChange}
175
175
  onTokenPress={() => setShowModal('sourceToken')}
176
176
  onMaxPress={onSourceMaxPress}
177
+ testID="swap-input-source"
177
178
  />
178
179
  <FlexView alignItems="center" justifyContent="center" style={styles.bottomInputContainer}>
179
180
  <SwapInput
@@ -186,6 +187,7 @@ export function SwapView() {
186
187
  onChange={onToTokenChange}
187
188
  onTokenPress={() => setShowModal('toToken')}
188
189
  editable={false}
190
+ testID="swap-input-to"
189
191
  />
190
192
  {showSwitch ? (
191
193
  <IconLink
@@ -92,6 +92,7 @@ export function WalletSendView() {
92
92
  style={styles.tokenInput}
93
93
  onTokenPress={() => RouterController.push('WalletSendSelectToken')}
94
94
  loading={isBalanceLoading}
95
+ testID="send-input-token"
95
96
  />
96
97
  <FlexView alignItems="center" justifyContent="center" style={styles.addressContainer}>
97
98
  <SendInputAddress value={receiverProfileName || receiverAddress} />