@reown/appkit-react-native 0.0.0-develop-20251030154825 → 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 (121) hide show
  1. package/lib/commonjs/hooks/useAccount.js +4 -4
  2. package/lib/commonjs/hooks/useAccount.js.map +1 -1
  3. package/lib/commonjs/hooks/useAppKit.js +41 -9
  4. package/lib/commonjs/hooks/useAppKit.js.map +1 -1
  5. package/lib/commonjs/hooks/useAppKitContext.js +46 -0
  6. package/lib/commonjs/hooks/useAppKitContext.js.map +1 -0
  7. package/lib/commonjs/hooks/useAppKitEvents.js +64 -4
  8. package/lib/commonjs/hooks/useAppKitEvents.js.map +1 -1
  9. package/lib/commonjs/hooks/useAppKitLogs.js +2 -8
  10. package/lib/commonjs/hooks/useAppKitLogs.js.map +1 -1
  11. package/lib/commonjs/hooks/useAppKitState.js +35 -2
  12. package/lib/commonjs/hooks/useAppKitState.js.map +1 -1
  13. package/lib/commonjs/hooks/useAppKitTheme.js +74 -0
  14. package/lib/commonjs/hooks/useAppKitTheme.js.map +1 -0
  15. package/lib/commonjs/hooks/useProvider.js +3 -4
  16. package/lib/commonjs/hooks/useProvider.js.map +1 -1
  17. package/lib/commonjs/hooks/useWalletInfo.js +33 -2
  18. package/lib/commonjs/hooks/useWalletInfo.js.map +1 -1
  19. package/lib/commonjs/index.js +7 -0
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/modal/w3m-modal/styles.js +2 -1
  22. package/lib/commonjs/modal/w3m-modal/styles.js.map +1 -1
  23. package/lib/commonjs/partials/w3m-connecting-body/index.js +2 -0
  24. package/lib/commonjs/partials/w3m-connecting-body/index.js.map +1 -1
  25. package/lib/commonjs/partials/w3m-connecting-mobile/components/StoreLink.js +4 -0
  26. package/lib/commonjs/partials/w3m-connecting-mobile/components/StoreLink.js.map +1 -1
  27. package/lib/commonjs/partials/w3m-connecting-qrcode/index.js +5 -1
  28. package/lib/commonjs/partials/w3m-connecting-qrcode/index.js.map +1 -1
  29. package/lib/commonjs/partials/w3m-header/index.js +1 -0
  30. package/lib/commonjs/partials/w3m-header/index.js.map +1 -1
  31. package/lib/commonjs/partials/w3m-header/styles.js +3 -0
  32. package/lib/commonjs/partials/w3m-header/styles.js.map +1 -1
  33. package/lib/commonjs/views/w3m-connecting-external-view/index.js +4 -8
  34. package/lib/commonjs/views/w3m-connecting-external-view/index.js.map +1 -1
  35. package/lib/commonjs/views/w3m-connecting-view/index.js +17 -7
  36. package/lib/commonjs/views/w3m-connecting-view/index.js.map +1 -1
  37. package/lib/module/hooks/useAccount.js +4 -4
  38. package/lib/module/hooks/useAccount.js.map +1 -1
  39. package/lib/module/hooks/useAppKit.js +43 -10
  40. package/lib/module/hooks/useAppKit.js.map +1 -1
  41. package/lib/module/hooks/useAppKitContext.js +42 -0
  42. package/lib/module/hooks/useAppKitContext.js.map +1 -0
  43. package/lib/module/hooks/useAppKitEvents.js +65 -4
  44. package/lib/module/hooks/useAppKitEvents.js.map +1 -1
  45. package/lib/module/hooks/useAppKitLogs.js +3 -9
  46. package/lib/module/hooks/useAppKitLogs.js.map +1 -1
  47. package/lib/module/hooks/useAppKitState.js +36 -2
  48. package/lib/module/hooks/useAppKitState.js.map +1 -1
  49. package/lib/module/hooks/useAppKitTheme.js +71 -0
  50. package/lib/module/hooks/useAppKitTheme.js.map +1 -0
  51. package/lib/module/hooks/useProvider.js +3 -4
  52. package/lib/module/hooks/useProvider.js.map +1 -1
  53. package/lib/module/hooks/useWalletInfo.js +34 -2
  54. package/lib/module/hooks/useWalletInfo.js.map +1 -1
  55. package/lib/module/index.js +1 -0
  56. package/lib/module/index.js.map +1 -1
  57. package/lib/module/modal/w3m-modal/styles.js +2 -1
  58. package/lib/module/modal/w3m-modal/styles.js.map +1 -1
  59. package/lib/module/partials/w3m-connecting-body/index.js +2 -0
  60. package/lib/module/partials/w3m-connecting-body/index.js.map +1 -1
  61. package/lib/module/partials/w3m-connecting-mobile/components/StoreLink.js +4 -0
  62. package/lib/module/partials/w3m-connecting-mobile/components/StoreLink.js.map +1 -1
  63. package/lib/module/partials/w3m-connecting-qrcode/index.js +5 -1
  64. package/lib/module/partials/w3m-connecting-qrcode/index.js.map +1 -1
  65. package/lib/module/partials/w3m-header/index.js +1 -0
  66. package/lib/module/partials/w3m-header/index.js.map +1 -1
  67. package/lib/module/partials/w3m-header/styles.js +3 -0
  68. package/lib/module/partials/w3m-header/styles.js.map +1 -1
  69. package/lib/module/views/w3m-connecting-external-view/index.js +4 -8
  70. package/lib/module/views/w3m-connecting-external-view/index.js.map +1 -1
  71. package/lib/module/views/w3m-connecting-view/index.js +17 -7
  72. package/lib/module/views/w3m-connecting-view/index.js.map +1 -1
  73. package/lib/typescript/AppKitContext.d.ts +1 -1
  74. package/lib/typescript/AppKitContext.d.ts.map +1 -1
  75. package/lib/typescript/hooks/useAccount.d.ts.map +1 -1
  76. package/lib/typescript/hooks/useAppKit.d.ts +42 -0
  77. package/lib/typescript/hooks/useAppKit.d.ts.map +1 -1
  78. package/lib/typescript/hooks/useAppKitContext.d.ts +27 -0
  79. package/lib/typescript/hooks/useAppKitContext.d.ts.map +1 -0
  80. package/lib/typescript/hooks/useAppKitEvents.d.ts +66 -0
  81. package/lib/typescript/hooks/useAppKitEvents.d.ts.map +1 -1
  82. package/lib/typescript/hooks/useAppKitLogs.d.ts.map +1 -1
  83. package/lib/typescript/hooks/useAppKitState.d.ts +32 -0
  84. package/lib/typescript/hooks/useAppKitState.d.ts.map +1 -1
  85. package/lib/typescript/hooks/useAppKitTheme.d.ts +59 -0
  86. package/lib/typescript/hooks/useAppKitTheme.d.ts.map +1 -0
  87. package/lib/typescript/hooks/useProvider.d.ts +1 -4
  88. package/lib/typescript/hooks/useProvider.d.ts.map +1 -1
  89. package/lib/typescript/hooks/useWalletInfo.d.ts +31 -0
  90. package/lib/typescript/hooks/useWalletInfo.d.ts.map +1 -1
  91. package/lib/typescript/index.d.ts +1 -0
  92. package/lib/typescript/index.d.ts.map +1 -1
  93. package/lib/typescript/modal/w3m-modal/styles.d.ts +1 -0
  94. package/lib/typescript/modal/w3m-modal/styles.d.ts.map +1 -1
  95. package/lib/typescript/partials/w3m-connecting-body/index.d.ts.map +1 -1
  96. package/lib/typescript/partials/w3m-connecting-qrcode/index.d.ts.map +1 -1
  97. package/lib/typescript/partials/w3m-header/index.d.ts.map +1 -1
  98. package/lib/typescript/partials/w3m-header/styles.d.ts +3 -0
  99. package/lib/typescript/partials/w3m-header/styles.d.ts.map +1 -1
  100. package/lib/typescript/views/w3m-connecting-external-view/index.d.ts.map +1 -1
  101. package/lib/typescript/views/w3m-connecting-view/index.d.ts.map +1 -1
  102. package/package.json +5 -4
  103. package/src/AppKitContext.tsx +1 -1
  104. package/src/hooks/useAccount.ts +5 -3
  105. package/src/hooks/useAppKit.ts +45 -12
  106. package/src/hooks/useAppKitContext.ts +43 -0
  107. package/src/hooks/useAppKitEvents.ts +63 -3
  108. package/src/hooks/useAppKitLogs.ts +3 -11
  109. package/src/hooks/useAppKitState.ts +35 -2
  110. package/src/hooks/useAppKitTheme.ts +81 -0
  111. package/src/hooks/useProvider.ts +3 -4
  112. package/src/hooks/useWalletInfo.ts +33 -2
  113. package/src/index.ts +1 -0
  114. package/src/modal/w3m-modal/styles.ts +2 -1
  115. package/src/partials/w3m-connecting-body/index.tsx +3 -1
  116. package/src/partials/w3m-connecting-mobile/components/StoreLink.tsx +4 -1
  117. package/src/partials/w3m-connecting-qrcode/index.tsx +10 -1
  118. package/src/partials/w3m-header/index.tsx +6 -1
  119. package/src/partials/w3m-header/styles.ts +3 -0
  120. package/src/views/w3m-connecting-external-view/index.tsx +4 -8
  121. package/src/views/w3m-connecting-view/index.tsx +24 -8
@@ -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
@@ -32,6 +32,7 @@ export type { AppKitConfig } from './types';
32
32
  export { useAppKit } from './hooks/useAppKit';
33
33
  export { useProvider } from './hooks/useProvider';
34
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
  });
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  import { useSnapshot } from 'valtio';
2
2
  import { useEffect, useLayoutEffect, useState } from 'react';
3
- import { type Platform } from '@reown/appkit-common-react-native';
3
+ import { ErrorUtil, type Platform } from '@reown/appkit-common-react-native';
4
4
  import {
5
5
  WcController,
6
6
  ConstantsUtil,
@@ -39,30 +39,46 @@ export function ConnectingView() {
39
39
  }
40
40
  };
41
41
 
42
- const initializeConnection = async (retry = false) => {
42
+ const initializeConnection = async (retry = false, retryTimestamp?: number) => {
43
43
  try {
44
44
  const { wcPairingExpiry } = WcController.state;
45
45
  const { data: routeData } = RouterController.state;
46
- if (retry || CoreHelperUtil.isPairingExpired(wcPairingExpiry)) {
46
+ const isPairingExpired = CoreHelperUtil.isPairingExpired(wcPairingExpiry);
47
+ if (retry || isPairingExpired) {
47
48
  WcController.setWcError(false);
48
49
 
49
50
  const connectPromise = connect({
50
51
  wallet: routeData?.wallet
51
52
  });
52
53
  WcController.setWcPromise(connectPromise);
54
+ await connectPromise;
53
55
  }
54
56
  } catch (error) {
55
57
  LogController.sendError(error, 'ConnectingView.tsx', 'initializeConnection');
56
58
  WcController.setWcError(true);
57
59
  WcController.clearUri();
58
- SnackController.showError('Declined');
59
- if (isQr && CoreHelperUtil.isAllowedRetry(lastRetry)) {
60
- setLastRetry(Date.now());
61
- initializeConnection(true);
60
+
61
+ const currentRetryTime = retryTimestamp ?? lastRetry;
62
+
63
+ if (isQr && CoreHelperUtil.isAllowedRetry(currentRetryTime)) {
64
+ const newRetryTime = Date.now();
65
+ setLastRetry(newRetryTime);
66
+ initializeConnection(true, newRetryTime);
67
+
68
+ return;
62
69
  }
70
+
71
+ const isUserRejected = ErrorUtil.isUserRejectedRequestError(error);
72
+ const isProposalExpired = ErrorUtil.isProposalExpiredError(error);
73
+ if (!isProposalExpired) {
74
+ SnackController.showError(
75
+ isUserRejected ? 'User rejected the request' : 'Something went wrong'
76
+ );
77
+ }
78
+
63
79
  EventsController.sendEvent({
64
80
  type: 'track',
65
- event: 'CONNECT_ERROR',
81
+ event: isUserRejected ? 'USER_REJECTED' : 'CONNECT_ERROR',
66
82
  properties: {
67
83
  message: (error as Error)?.message ?? 'Unknown'
68
84
  }