@spacesops/wdk-react-native-core 1.0.0-beta.40

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 (275) hide show
  1. package/README.md +551 -0
  2. package/dist/__mocks__/react.d.ts +40 -0
  3. package/dist/__mocks__/react.js +33 -0
  4. package/dist/__mocks__/react.js.map +1 -0
  5. package/dist/__mocks__/secureStorage.d.ts +26 -0
  6. package/dist/__mocks__/secureStorage.js +80 -0
  7. package/dist/__mocks__/secureStorage.js.map +1 -0
  8. package/dist/__tests__/hooks/useBalance.test.d.ts +6 -0
  9. package/dist/__tests__/hooks/useBalance.test.js +217 -0
  10. package/dist/__tests__/hooks/useBalance.test.js.map +1 -0
  11. package/dist/__tests__/hooks/useWallet.test.d.ts +6 -0
  12. package/dist/__tests__/hooks/useWallet.test.js +105 -0
  13. package/dist/__tests__/hooks/useWallet.test.js.map +1 -0
  14. package/dist/__tests__/hooks/useWalletManager.test.d.ts +6 -0
  15. package/dist/__tests__/hooks/useWalletManager.test.js +193 -0
  16. package/dist/__tests__/hooks/useWalletManager.test.js.map +1 -0
  17. package/dist/__tests__/hooks/useWdkApp.test.d.ts +6 -0
  18. package/dist/__tests__/hooks/useWdkApp.test.js +55 -0
  19. package/dist/__tests__/hooks/useWdkApp.test.js.map +1 -0
  20. package/dist/__tests__/hooks/useWorklet.test.d.ts +6 -0
  21. package/dist/__tests__/hooks/useWorklet.test.js +168 -0
  22. package/dist/__tests__/hooks/useWorklet.test.js.map +1 -0
  23. package/dist/__tests__/provider/WdkAppProvider.test.d.ts +6 -0
  24. package/dist/__tests__/provider/WdkAppProvider.test.js +57 -0
  25. package/dist/__tests__/provider/WdkAppProvider.test.js.map +1 -0
  26. package/dist/__tests__/services/accountService.test.d.ts +6 -0
  27. package/dist/__tests__/services/accountService.test.js +216 -0
  28. package/dist/__tests__/services/accountService.test.js.map +1 -0
  29. package/dist/__tests__/services/addressService.test.d.ts +6 -0
  30. package/dist/__tests__/services/addressService.test.js +246 -0
  31. package/dist/__tests__/services/addressService.test.js.map +1 -0
  32. package/dist/__tests__/services/balanceService.test.d.ts +6 -0
  33. package/dist/__tests__/services/balanceService.test.js +333 -0
  34. package/dist/__tests__/services/balanceService.test.js.map +1 -0
  35. package/dist/__tests__/services/walletSetupService.test.d.ts +6 -0
  36. package/dist/__tests__/services/walletSetupService.test.js +304 -0
  37. package/dist/__tests__/services/walletSetupService.test.js.map +1 -0
  38. package/dist/__tests__/services/walletSwitchingService.test.d.ts +6 -0
  39. package/dist/__tests__/services/walletSwitchingService.test.js +209 -0
  40. package/dist/__tests__/services/walletSwitchingService.test.js.map +1 -0
  41. package/dist/__tests__/services/workletLifecycleService.test.d.ts +6 -0
  42. package/dist/__tests__/services/workletLifecycleService.test.js +451 -0
  43. package/dist/__tests__/services/workletLifecycleService.test.js.map +1 -0
  44. package/dist/__tests__/setup.d.ts +7 -0
  45. package/dist/__tests__/setup.js +49 -0
  46. package/dist/__tests__/setup.js.map +1 -0
  47. package/dist/__tests__/storage/mmkvStorage.test.d.ts +6 -0
  48. package/dist/__tests__/storage/mmkvStorage.test.js +213 -0
  49. package/dist/__tests__/storage/mmkvStorage.test.js.map +1 -0
  50. package/dist/__tests__/store/walletStore.test.d.ts +4 -0
  51. package/dist/__tests__/store/walletStore.test.js +86 -0
  52. package/dist/__tests__/store/walletStore.test.js.map +1 -0
  53. package/dist/__tests__/store/workletStore.test.d.ts +4 -0
  54. package/dist/__tests__/store/workletStore.test.js +255 -0
  55. package/dist/__tests__/store/workletStore.test.js.map +1 -0
  56. package/dist/__tests__/types/hrpc.test.d.ts +4 -0
  57. package/dist/__tests__/types/hrpc.test.js +99 -0
  58. package/dist/__tests__/types/hrpc.test.js.map +1 -0
  59. package/dist/__tests__/utils/balanceUtils.test.d.ts +4 -0
  60. package/dist/__tests__/utils/balanceUtils.test.js +133 -0
  61. package/dist/__tests__/utils/balanceUtils.test.js.map +1 -0
  62. package/dist/__tests__/utils/errorHandling.test.d.ts +6 -0
  63. package/dist/__tests__/utils/errorHandling.test.js +119 -0
  64. package/dist/__tests__/utils/errorHandling.test.js.map +1 -0
  65. package/dist/__tests__/utils/errorUtils.test.d.ts +4 -0
  66. package/dist/__tests__/utils/errorUtils.test.js +133 -0
  67. package/dist/__tests__/utils/errorUtils.test.js.map +1 -0
  68. package/dist/__tests__/utils/initializationState.test.d.ts +6 -0
  69. package/dist/__tests__/utils/initializationState.test.js +243 -0
  70. package/dist/__tests__/utils/initializationState.test.js.map +1 -0
  71. package/dist/__tests__/utils/jsonUtils.test.d.ts +4 -0
  72. package/dist/__tests__/utils/jsonUtils.test.js +118 -0
  73. package/dist/__tests__/utils/jsonUtils.test.js.map +1 -0
  74. package/dist/__tests__/utils/mmkvKeyManager.test.d.ts +6 -0
  75. package/dist/__tests__/utils/mmkvKeyManager.test.js +158 -0
  76. package/dist/__tests__/utils/mmkvKeyManager.test.js.map +1 -0
  77. package/dist/__tests__/utils/mnemonicUtils.test.d.ts +4 -0
  78. package/dist/__tests__/utils/mnemonicUtils.test.js +40 -0
  79. package/dist/__tests__/utils/mnemonicUtils.test.js.map +1 -0
  80. package/dist/__tests__/utils/raceConditions.test.d.ts +6 -0
  81. package/dist/__tests__/utils/raceConditions.test.js +239 -0
  82. package/dist/__tests__/utils/raceConditions.test.js.map +1 -0
  83. package/dist/__tests__/utils/result.test.d.ts +4 -0
  84. package/dist/__tests__/utils/result.test.js +66 -0
  85. package/dist/__tests__/utils/result.test.js.map +1 -0
  86. package/dist/__tests__/utils/schemas.test.d.ts +4 -0
  87. package/dist/__tests__/utils/schemas.test.js +66 -0
  88. package/dist/__tests__/utils/schemas.test.js.map +1 -0
  89. package/dist/__tests__/utils/storeHelpers.test.d.ts +4 -0
  90. package/dist/__tests__/utils/storeHelpers.test.js +227 -0
  91. package/dist/__tests__/utils/storeHelpers.test.js.map +1 -0
  92. package/dist/__tests__/utils/typeGuards.test.d.ts +4 -0
  93. package/dist/__tests__/utils/typeGuards.test.js +175 -0
  94. package/dist/__tests__/utils/typeGuards.test.js.map +1 -0
  95. package/dist/__tests__/utils/validation.test.d.ts +4 -0
  96. package/dist/__tests__/utils/validation.test.js +126 -0
  97. package/dist/__tests__/utils/validation.test.js.map +1 -0
  98. package/dist/__tests__/utils/walletUtils.test.d.ts +4 -0
  99. package/dist/__tests__/utils/walletUtils.test.js +156 -0
  100. package/dist/__tests__/utils/walletUtils.test.js.map +1 -0
  101. package/dist/hooks/useBalance.d.ts +170 -0
  102. package/dist/hooks/useBalance.js +442 -0
  103. package/dist/hooks/useBalance.js.map +1 -0
  104. package/dist/hooks/useWallet.d.ts +43 -0
  105. package/dist/hooks/useWallet.js +193 -0
  106. package/dist/hooks/useWallet.js.map +1 -0
  107. package/dist/hooks/useWalletManager.d.ts +100 -0
  108. package/dist/hooks/useWalletManager.js +526 -0
  109. package/dist/hooks/useWalletManager.js.map +1 -0
  110. package/dist/hooks/useWdkApp.d.ts +66 -0
  111. package/dist/hooks/useWdkApp.js +74 -0
  112. package/dist/hooks/useWdkApp.js.map +1 -0
  113. package/dist/hooks/useWorklet.d.ts +66 -0
  114. package/dist/hooks/useWorklet.js +42 -0
  115. package/dist/hooks/useWorklet.js.map +1 -0
  116. package/dist/index.d.ts +33 -0
  117. package/dist/index.js +36 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/provider/WdkAppProvider.d.ts +112 -0
  120. package/dist/provider/WdkAppProvider.js +558 -0
  121. package/dist/provider/WdkAppProvider.js.map +1 -0
  122. package/dist/services/accountService.d.ts +52 -0
  123. package/dist/services/accountService.js +119 -0
  124. package/dist/services/accountService.js.map +1 -0
  125. package/dist/services/addressService.d.ts +22 -0
  126. package/dist/services/addressService.js +110 -0
  127. package/dist/services/addressService.js.map +1 -0
  128. package/dist/services/balanceService.d.ts +114 -0
  129. package/dist/services/balanceService.js +208 -0
  130. package/dist/services/balanceService.js.map +1 -0
  131. package/dist/services/walletSetupService.d.ts +217 -0
  132. package/dist/services/walletSetupService.js +535 -0
  133. package/dist/services/walletSetupService.js.map +1 -0
  134. package/dist/services/walletSwitchingService.d.ts +48 -0
  135. package/dist/services/walletSwitchingService.js +143 -0
  136. package/dist/services/walletSwitchingService.js.map +1 -0
  137. package/dist/services/workletLifecycleService.d.ts +117 -0
  138. package/dist/services/workletLifecycleService.js +433 -0
  139. package/dist/services/workletLifecycleService.js.map +1 -0
  140. package/dist/storage/mmkvStorage.d.ts +44 -0
  141. package/dist/storage/mmkvStorage.js +348 -0
  142. package/dist/storage/mmkvStorage.js.map +1 -0
  143. package/dist/store/walletStore.d.ts +130 -0
  144. package/dist/store/walletStore.js +204 -0
  145. package/dist/store/walletStore.js.map +1 -0
  146. package/dist/store/workletStore.d.ts +121 -0
  147. package/dist/store/workletStore.js +256 -0
  148. package/dist/store/workletStore.js.map +1 -0
  149. package/dist/types/hrpc.d.ts +60 -0
  150. package/dist/types/hrpc.js +26 -0
  151. package/dist/types/hrpc.js.map +1 -0
  152. package/dist/types.d.ts +168 -0
  153. package/dist/types.js +7 -0
  154. package/dist/types.js.map +1 -0
  155. package/dist/utils/balanceUtils.d.ts +30 -0
  156. package/dist/utils/balanceUtils.js +86 -0
  157. package/dist/utils/balanceUtils.js.map +1 -0
  158. package/dist/utils/constants.d.ts +66 -0
  159. package/dist/utils/constants.js +73 -0
  160. package/dist/utils/constants.js.map +1 -0
  161. package/dist/utils/errorHandling.d.ts +47 -0
  162. package/dist/utils/errorHandling.js +54 -0
  163. package/dist/utils/errorHandling.js.map +1 -0
  164. package/dist/utils/errorUtils.d.ts +89 -0
  165. package/dist/utils/errorUtils.js +264 -0
  166. package/dist/utils/errorUtils.js.map +1 -0
  167. package/dist/utils/initializationState.d.ts +129 -0
  168. package/dist/utils/initializationState.js +220 -0
  169. package/dist/utils/initializationState.js.map +1 -0
  170. package/dist/utils/jsonUtils.d.ts +21 -0
  171. package/dist/utils/jsonUtils.js +67 -0
  172. package/dist/utils/jsonUtils.js.map +1 -0
  173. package/dist/utils/logger.d.ts +27 -0
  174. package/dist/utils/logger.js +50 -0
  175. package/dist/utils/logger.js.map +1 -0
  176. package/dist/utils/mmkvKeyManager.d.ts +57 -0
  177. package/dist/utils/mmkvKeyManager.js +214 -0
  178. package/dist/utils/mmkvKeyManager.js.map +1 -0
  179. package/dist/utils/mnemonicUtils.d.ts +17 -0
  180. package/dist/utils/mnemonicUtils.js +28 -0
  181. package/dist/utils/mnemonicUtils.js.map +1 -0
  182. package/dist/utils/operationMutex.d.ts +69 -0
  183. package/dist/utils/operationMutex.js +150 -0
  184. package/dist/utils/operationMutex.js.map +1 -0
  185. package/dist/utils/result.d.ts +34 -0
  186. package/dist/utils/result.js +43 -0
  187. package/dist/utils/result.js.map +1 -0
  188. package/dist/utils/schemas.d.ts +365 -0
  189. package/dist/utils/schemas.js +152 -0
  190. package/dist/utils/schemas.js.map +1 -0
  191. package/dist/utils/storeHelpers.d.ts +112 -0
  192. package/dist/utils/storeHelpers.js +198 -0
  193. package/dist/utils/storeHelpers.js.map +1 -0
  194. package/dist/utils/typeGuards.d.ts +70 -0
  195. package/dist/utils/typeGuards.js +95 -0
  196. package/dist/utils/typeGuards.js.map +1 -0
  197. package/dist/utils/validation.d.ts +53 -0
  198. package/dist/utils/validation.js +152 -0
  199. package/dist/utils/validation.js.map +1 -0
  200. package/dist/utils/walletStateHelpers.d.ts +62 -0
  201. package/dist/utils/walletStateHelpers.js +81 -0
  202. package/dist/utils/walletStateHelpers.js.map +1 -0
  203. package/dist/utils/walletUtils.d.ts +38 -0
  204. package/dist/utils/walletUtils.js +87 -0
  205. package/dist/utils/walletUtils.js.map +1 -0
  206. package/package.json +79 -0
  207. package/src/__mocks__/react.ts +34 -0
  208. package/src/__mocks__/secureStorage.ts +87 -0
  209. package/src/__tests__/hooks/useBalance.test.ts +286 -0
  210. package/src/__tests__/hooks/useWallet.test.ts +122 -0
  211. package/src/__tests__/hooks/useWalletManager.test.ts +271 -0
  212. package/src/__tests__/hooks/useWdkApp.test.tsx +59 -0
  213. package/src/__tests__/hooks/useWorklet.test.ts +195 -0
  214. package/src/__tests__/provider/WdkAppProvider.test.tsx +67 -0
  215. package/src/__tests__/services/accountService.test.ts +337 -0
  216. package/src/__tests__/services/addressService.test.ts +312 -0
  217. package/src/__tests__/services/balanceService.test.ts +411 -0
  218. package/src/__tests__/services/walletSetupService.test.ts +463 -0
  219. package/src/__tests__/services/walletSwitchingService.test.ts +258 -0
  220. package/src/__tests__/services/workletLifecycleService.test.ts +514 -0
  221. package/src/__tests__/setup.ts +54 -0
  222. package/src/__tests__/storage/mmkvStorage.test.ts +325 -0
  223. package/src/__tests__/store/walletStore.test.ts +101 -0
  224. package/src/__tests__/store/workletStore.test.ts +329 -0
  225. package/src/__tests__/types/hrpc.test.ts +125 -0
  226. package/src/__tests__/utils/balanceUtils.test.ts +151 -0
  227. package/src/__tests__/utils/errorHandling.test.ts +147 -0
  228. package/src/__tests__/utils/errorUtils.test.ts +170 -0
  229. package/src/__tests__/utils/initializationState.test.ts +337 -0
  230. package/src/__tests__/utils/jsonUtils.test.ts +131 -0
  231. package/src/__tests__/utils/mmkvKeyManager.test.ts +205 -0
  232. package/src/__tests__/utils/mnemonicUtils.test.ts +48 -0
  233. package/src/__tests__/utils/raceConditions.test.ts +292 -0
  234. package/src/__tests__/utils/result.test.ts +73 -0
  235. package/src/__tests__/utils/schemas.test.ts +82 -0
  236. package/src/__tests__/utils/storeHelpers.test.ts +323 -0
  237. package/src/__tests__/utils/typeGuards.test.ts +209 -0
  238. package/src/__tests__/utils/validation.test.ts +152 -0
  239. package/src/__tests__/utils/walletUtils.test.ts +195 -0
  240. package/src/hooks/useBalance.ts +597 -0
  241. package/src/hooks/useWallet.ts +288 -0
  242. package/src/hooks/useWalletManager.ts +654 -0
  243. package/src/hooks/useWdkApp.ts +78 -0
  244. package/src/hooks/useWorklet.ts +109 -0
  245. package/src/index.ts +112 -0
  246. package/src/provider/WdkAppProvider.tsx +764 -0
  247. package/src/services/accountService.ts +134 -0
  248. package/src/services/addressService.ts +125 -0
  249. package/src/services/balanceService.ts +291 -0
  250. package/src/services/walletSetupService.ts +695 -0
  251. package/src/services/walletSwitchingService.ts +157 -0
  252. package/src/services/workletLifecycleService.ts +561 -0
  253. package/src/storage/mmkvStorage.ts +417 -0
  254. package/src/store/walletStore.ts +301 -0
  255. package/src/store/workletStore.ts +340 -0
  256. package/src/types/hrpc.ts +78 -0
  257. package/src/types.ts +188 -0
  258. package/src/utils/balanceUtils.ts +96 -0
  259. package/src/utils/constants.ts +84 -0
  260. package/src/utils/errorHandling.md +163 -0
  261. package/src/utils/errorHandling.ts +61 -0
  262. package/src/utils/errorUtils.ts +300 -0
  263. package/src/utils/initializationState.ts +242 -0
  264. package/src/utils/jsonUtils.ts +75 -0
  265. package/src/utils/logger.ts +54 -0
  266. package/src/utils/mmkvKeyManager.ts +256 -0
  267. package/src/utils/mnemonicUtils.ts +35 -0
  268. package/src/utils/operationMutex.ts +181 -0
  269. package/src/utils/result.ts +57 -0
  270. package/src/utils/schemas.ts +190 -0
  271. package/src/utils/storeHelpers.ts +236 -0
  272. package/src/utils/typeGuards.ts +129 -0
  273. package/src/utils/validation.ts +174 -0
  274. package/src/utils/walletStateHelpers.ts +104 -0
  275. package/src/utils/walletUtils.ts +107 -0
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Validation utilities for WDK provider props and inputs
3
+ *
4
+ * These functions throw errors for invalid inputs.
5
+ * Uses Zod schemas for validation with better error messages.
6
+ * For type guards (boolean returns), see typeGuards.ts
7
+ */
8
+ import type { NetworkConfigs, TokenConfigs } from '../types';
9
+ /**
10
+ * Validate network configuration
11
+ */
12
+ export declare function validateNetworkConfigs(networkConfigs: NetworkConfigs): void;
13
+ /**
14
+ * Validate token configuration
15
+ */
16
+ export declare function validateTokenConfigs(tokenConfigs: TokenConfigs): void;
17
+ /**
18
+ * Validate balance refresh interval
19
+ */
20
+ export declare function validateBalanceRefreshInterval(interval: number | undefined): void;
21
+ /**
22
+ * Validate that an object has required methods
23
+ *
24
+ * @param obj - Object to validate
25
+ * @param requiredMethods - Array of required method names
26
+ * @param objectName - Name of the object for error messages
27
+ */
28
+ export declare function validateRequiredMethods(obj: unknown, requiredMethods: string[], objectName: string): void;
29
+ /**
30
+ * Validate account index
31
+ */
32
+ export declare function validateAccountIndex(accountIndex: number): void;
33
+ /**
34
+ * Validate network name
35
+ */
36
+ export declare function validateNetworkName(network: string): void;
37
+ /**
38
+ * Validate token address (can be null for native tokens)
39
+ */
40
+ export declare function validateTokenAddress(tokenAddress: string | null): void;
41
+ /**
42
+ * Validate balance string
43
+ */
44
+ export declare function validateBalance(balance: string): void;
45
+ /**
46
+ * Validate wallet parameters (network, accountIndex, optional tokenAddress)
47
+ * Convenience function to validate common wallet operation parameters
48
+ *
49
+ * @param network - Network name
50
+ * @param accountIndex - Account index
51
+ * @param tokenAddress - Optional token address (null for native tokens)
52
+ */
53
+ export declare function validateWalletParams(network: string, accountIndex: number, tokenAddress?: string | null): void;
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Validation utilities for WDK provider props and inputs
3
+ *
4
+ * These functions throw errors for invalid inputs.
5
+ * Uses Zod schemas for validation with better error messages.
6
+ * For type guards (boolean returns), see typeGuards.ts
7
+ */
8
+ import { z } from 'zod';
9
+ import { networkConfigsSchema, tokenConfigsSchema, accountIndexSchema, networkNameSchema, balanceStringSchema, ethereumAddressSchema, } from './schemas';
10
+ /**
11
+ * Extract error message from Zod error
12
+ */
13
+ function getZodErrorMessage(error) {
14
+ if (error instanceof z.ZodError) {
15
+ // Get the first error message for simplicity
16
+ const firstIssue = error.issues[0];
17
+ if (firstIssue) {
18
+ return firstIssue.message;
19
+ }
20
+ return 'Validation failed';
21
+ }
22
+ if (error instanceof Error) {
23
+ return error.message;
24
+ }
25
+ return String(error);
26
+ }
27
+ /**
28
+ * Validate network configuration
29
+ */
30
+ export function validateNetworkConfigs(networkConfigs) {
31
+ try {
32
+ networkConfigsSchema.parse(networkConfigs);
33
+ }
34
+ catch (error) {
35
+ throw new Error(`Invalid networkConfigs: ${getZodErrorMessage(error)}`);
36
+ }
37
+ }
38
+ /**
39
+ * Validate token configuration
40
+ */
41
+ export function validateTokenConfigs(tokenConfigs) {
42
+ try {
43
+ tokenConfigsSchema.parse(tokenConfigs);
44
+ }
45
+ catch (error) {
46
+ throw new Error(`Invalid tokenConfigs: ${getZodErrorMessage(error)}`);
47
+ }
48
+ }
49
+ /**
50
+ * Validate balance refresh interval
51
+ */
52
+ export function validateBalanceRefreshInterval(interval) {
53
+ if (interval !== undefined) {
54
+ if (typeof interval !== 'number') {
55
+ throw new Error('balanceRefreshInterval must be a number');
56
+ }
57
+ if (interval < 0) {
58
+ throw new Error('balanceRefreshInterval must be a non-negative number');
59
+ }
60
+ if (!Number.isFinite(interval)) {
61
+ throw new Error('balanceRefreshInterval must be a finite number');
62
+ }
63
+ }
64
+ }
65
+ /**
66
+ * Validate that an object has required methods
67
+ *
68
+ * @param obj - Object to validate
69
+ * @param requiredMethods - Array of required method names
70
+ * @param objectName - Name of the object for error messages
71
+ */
72
+ export function validateRequiredMethods(obj, requiredMethods, objectName) {
73
+ if (!obj || typeof obj !== 'object') {
74
+ throw new Error(`${objectName} must be an object`);
75
+ }
76
+ for (const methodName of requiredMethods) {
77
+ if (typeof obj[methodName] !== 'function') {
78
+ throw new Error(`${objectName} must have a ${methodName} method`);
79
+ }
80
+ }
81
+ }
82
+ /**
83
+ * Validate account index
84
+ */
85
+ export function validateAccountIndex(accountIndex) {
86
+ try {
87
+ accountIndexSchema.parse(accountIndex);
88
+ }
89
+ catch (error) {
90
+ const message = getZodErrorMessage(error);
91
+ throw new Error(`Invalid accountIndex: ${message}`);
92
+ }
93
+ }
94
+ /**
95
+ * Validate network name
96
+ */
97
+ export function validateNetworkName(network) {
98
+ try {
99
+ networkNameSchema.parse(network);
100
+ }
101
+ catch (error) {
102
+ const message = getZodErrorMessage(error);
103
+ // Provide a fallback message if Zod error doesn't have a clear message
104
+ if (message === 'Validation failed' || !message) {
105
+ throw new Error('network must be a non-empty string containing only alphanumeric characters, hyphens, and underscores');
106
+ }
107
+ throw new Error(`Invalid network name: ${message}`);
108
+ }
109
+ }
110
+ /**
111
+ * Validate token address (can be null for native tokens)
112
+ */
113
+ export function validateTokenAddress(tokenAddress) {
114
+ if (tokenAddress === null) {
115
+ return;
116
+ }
117
+ try {
118
+ ethereumAddressSchema.parse(tokenAddress);
119
+ }
120
+ catch (error) {
121
+ const message = getZodErrorMessage(error);
122
+ throw new Error(`Invalid tokenAddress: ${message}`);
123
+ }
124
+ }
125
+ /**
126
+ * Validate balance string
127
+ */
128
+ export function validateBalance(balance) {
129
+ try {
130
+ balanceStringSchema.parse(balance);
131
+ }
132
+ catch (error) {
133
+ const message = getZodErrorMessage(error);
134
+ throw new Error(`Invalid balance: ${message}`);
135
+ }
136
+ }
137
+ /**
138
+ * Validate wallet parameters (network, accountIndex, optional tokenAddress)
139
+ * Convenience function to validate common wallet operation parameters
140
+ *
141
+ * @param network - Network name
142
+ * @param accountIndex - Account index
143
+ * @param tokenAddress - Optional token address (null for native tokens)
144
+ */
145
+ export function validateWalletParams(network, accountIndex, tokenAddress) {
146
+ validateNetworkName(network);
147
+ validateAccountIndex(accountIndex);
148
+ if (tokenAddress !== undefined) {
149
+ validateTokenAddress(tokenAddress);
150
+ }
151
+ }
152
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,WAAW,CAAA;AAGlB;;GAEG;AACH,SAAS,kBAAkB,CAAC,KAAc;IACxC,IAAI,KAAK,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;QAChC,6CAA6C;QAC7C,MAAM,UAAU,G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AA;IACrD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,YAA2B;IAC9D,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;QAC1B,OAAM;IACR,CAAC;IACD,IAAI,CAAC;QACH,qBAAqB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;IAC3C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAA;QACzC,MAAM,IAAI,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAA;IACrD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,IAAI,CAAC;QACH,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAA;QACzC,MAAM,IAAI,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAA;IAChD,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAe,EACf,YAAoB,EACpB,YAA4B;IAE5B,mBAAmB,CAAC,OAAO,CAAC,CAAA;IAC5B,oBAAoB,CAAC,YAAY,CAAC,CAAA;IAClC,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,oBAAoB,CAAC,YAAY,CAAC,CAAA;IACpC,CAAC;AACH,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Wallet State Helper Functions
3
+ *
4
+ * Pure functions that determine wallet state transition decisions.
5
+ * These helpers are used by WdkAppProvider for wallet state synchronization logic.
6
+ *
7
+ * These functions are extracted for:
8
+ * - Readability: Complex state logic separated from component orchestration
9
+ * - Testability: Pure functions can be tested in isolation
10
+ * - Reusability: Can be used elsewhere if needed
11
+ *
12
+ * Note: The effect that uses these functions must remain consolidated to prevent race conditions.
13
+ */
14
+ import type { WalletLoadingState } from '../store/walletStore';
15
+ /**
16
+ * Determine if wallet state should be reset to not_loaded
17
+ * This happens when activeWalletId is cleared (null)
18
+ *
19
+ * @param activeWalletId - Currently active wallet identifier (null if none)
20
+ * @param walletLoadingState - Current wallet loading state
21
+ * @returns true if state should be reset to not_loaded
22
+ */
23
+ export declare function shouldResetToNotLoaded(activeWalletId: string | null, walletLoadingState: WalletLoadingState): boolean;
24
+ /**
25
+ * Determine wallet switch decision when activeWalletId changes
26
+ * Returns whether a switch should occur and whether the new wallet should be marked ready
27
+ *
28
+ * @param currentWalletId - Wallet ID currently tracked in loading state
29
+ * @param activeWalletId - New active wallet ID
30
+ * @param hasAddresses - Whether the new wallet has addresses available
31
+ * @returns Object with shouldSwitch and shouldMarkReady flags
32
+ */
33
+ export declare function getWalletSwitchDecision(currentWalletId: string | null, activeWalletId: string | null, hasAddresses: boolean): {
34
+ shouldSwitch: boolean;
35
+ shouldMarkReady: boolean;
36
+ };
37
+ /**
38
+ * Determine if wallet should be marked as ready
39
+ * This checks if wallet is in loading/checking state, addresses exist, and worklet is initialized with seed
40
+ *
41
+ * Note: If addresses exist but state is not_loaded, we need to go through loading first.
42
+ * This is handled by useWalletManager.initializeWallet() or useOnboarding.
43
+ *
44
+ * @param walletLoadingState - Current wallet loading state
45
+ * @param hasAddresses - Whether wallet has addresses available
46
+ * @param currentWalletId - Wallet ID currently tracked in loading state
47
+ * @param activeWalletId - Currently active wallet identifier
48
+ * @param isWorkletInitialized - Whether the worklet is initialized with wallet credentials (seed loaded)
49
+ * @returns true if wallet should be marked as ready
50
+ */
51
+ export declare function shouldMarkWalletAsReady(walletLoadingState: WalletLoadingState, hasAddresses: boolean, currentWalletId: string | null, activeWalletId: string | null, isWorkletInitialized: boolean): boolean;
52
+ /**
53
+ * Determine if an error should be handled for the current wallet
54
+ * Only handle errors if they're for the wallet we're currently tracking
55
+ *
56
+ * @param walletManagerError - Error message from wallet manager (null if no error)
57
+ * @param currentWalletId - Wallet ID currently tracked in loading state
58
+ * @param activeWalletId - Currently active wallet identifier
59
+ * @param walletLoadingState - Current wallet loading state
60
+ * @returns true if error should be handled for current wallet
61
+ */
62
+ export declare function shouldHandleError(walletManagerError: string | null, currentWalletId: string | null, activeWalletId: string | null, walletLoadingState: WalletLoadingState): boolean;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Wallet State Helper Functions
3
+ *
4
+ * Pure functions that determine wallet state transition decisions.
5
+ * These helpers are used by WdkAppProvider for wallet state synchronization logic.
6
+ *
7
+ * These functions are extracted for:
8
+ * - Readability: Complex state logic separated from component orchestration
9
+ * - Testability: Pure functions can be tested in isolation
10
+ * - Reusability: Can be used elsewhere if needed
11
+ *
12
+ * Note: The effect that uses these functions must remain consolidated to prevent race conditions.
13
+ */
14
+ import { isWalletLoadingState } from '../store/walletStore';
15
+ /**
16
+ * Determine if wallet state should be reset to not_loaded
17
+ * This happens when activeWalletId is cleared (null)
18
+ *
19
+ * @param activeWalletId - Currently active wallet identifier (null if none)
20
+ * @param walletLoadingState - Current wallet loading state
21
+ * @returns true if state should be reset to not_loaded
22
+ */
23
+ export function shouldResetToNotLoaded(activeWalletId, walletLoadingState) {
24
+ return !activeWalletId && walletLoadingState.type !== 'not_loaded';
25
+ }
26
+ /**
27
+ * Determine wallet switch decision when activeWalletId changes
28
+ * Returns whether a switch should occur and whether the new wallet should be marked ready
29
+ *
30
+ * @param currentWalletId - Wallet ID currently tracked in loading state
31
+ * @param activeWalletId - New active wallet ID
32
+ * @param hasAddresses - Whether the new wallet has addresses available
33
+ * @returns Object with shouldSwitch and shouldMarkReady flags
34
+ */
35
+ export function getWalletSwitchDecision(currentWalletId, activeWalletId, hasAddresses) {
36
+ if (currentWalletId !== activeWalletId) {
37
+ return { shouldSwitch: true, shouldMarkReady: hasAddresses };
38
+ }
39
+ return { shouldSwitch: false, shouldMarkReady: false };
40
+ }
41
+ /**
42
+ * Determine if wallet should be marked as ready
43
+ * This checks if wallet is in loading/checking state, addresses exist, and worklet is initialized with seed
44
+ *
45
+ * Note: If addresses exist but state is not_loaded, we need to go through loading first.
46
+ * This is handled by useWalletManager.initializeWallet() or useOnboarding.
47
+ *
48
+ * @param walletLoadingState - Current wallet loading state
49
+ * @param hasAddresses - Whether wallet has addresses available
50
+ * @param currentWalletId - Wallet ID currently tracked in loading state
51
+ * @param activeWalletId - Currently active wallet identifier
52
+ * @param isWorkletInitialized - Whether the worklet is initialized with wallet credentials (seed loaded)
53
+ * @returns true if wallet should be marked as ready
54
+ */
55
+ export function shouldMarkWalletAsReady(walletLoadingState, hasAddresses, currentWalletId, activeWalletId, isWorkletInitialized) {
56
+ // Only allow ready transition from loading/checking states
57
+ // AND worklet must be initialized with seed (not just addresses cached)
58
+ // If addresses exist but state is not_loaded, we need to go through loading first
59
+ // This is handled by useWalletManager.initializeWallet() or useOnboarding
60
+ if (isWalletLoadingState(walletLoadingState) && currentWalletId === activeWalletId && hasAddresses && isWorkletInitialized) {
61
+ return true;
62
+ }
63
+ return false;
64
+ }
65
+ /**
66
+ * Determine if an error should be handled for the current wallet
67
+ * Only handle errors if they're for the wallet we're currently tracking
68
+ *
69
+ * @param walletManagerError - Error message from wallet manager (null if no error)
70
+ * @param currentWalletId - Wallet ID currently tracked in loading state
71
+ * @param activeWalletId - Currently active wallet identifier
72
+ * @param walletLoadingState - Current wallet loading state
73
+ * @returns true if error should be handled for current wallet
74
+ */
75
+ export function shouldHandleError(walletManagerError, currentWalletId, activeWalletId, walletLoadingState) {
76
+ if (!walletManagerError)
77
+ return false;
78
+ // Only update error if we're tracking this wallet
79
+ return currentWalletId === activeWalletId || walletLoadingState.type === 'not_loaded';
80
+ }
81
+ //# sourceMappingURL=walletStateHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walletStateHelpers.js","sourceRoot":"","sources":["../../src/utils/walletStateHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAE3D;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CACpC,cAA6B,EAC7B,kBAAsC;IAEtC,OAAO,CAAC,cAAc,IAAI,kBAAkB,CAAC,IAAI,KAAK,YAAY,CAAA;AACpE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CACrC,eAA8B,EAC9B,cAA6B,EAC7B,YAAqB;IAErB,IAAI,eAAe,KAAK,cAAc,EAAE,CAAC;QACvC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,CAAA;IAC9D,CAAC;IACD,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,CAAA;AACxD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,uBAAuB,CACrC,kBAAsC,EACtC,YAAqB,EACrB,eAA8B,EAC9B,cAA6B,EAC7B,oBAA6B;IAE7B,2DAA2D;IAC3D,wEAAwE;IACxE,kFAAkF;IAClF,0EAA0E;IAC1E,IAAI,oBAAoB,CAAC,kBAAkB,CAAC,IAAI,eAAe,KAAK,cAAc,IAAI,YAAY,IAAI,oBAAoB,EAAE,CAAC;QAC3H,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAC/B,kBAAiC,EACjC,eAA8B,EAC9B,cAA6B,EAC7B,kBAAsC;IAEtC,IAAI,CAAC,kBAAkB;QAAE,OAAO,KAAK,CAAA;IACrC,kDAAkD;IAClD,OAAO,eAAe,KAAK,cAAc,IAAI,kBAAkB,CAAC,IAAI,KAAK,YAAY,CAAA;AACvF,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Wallet Utilities
3
+ *
4
+ * Helper functions for working with wallets and retrieving addresses from walletStore.
5
+ */
6
+ import type { WalletStore as WalletStoreType } from '../store/walletStore';
7
+ import type { WalletStore } from '../types';
8
+ /**
9
+ * Get addresses for a wallet from walletStore
10
+ *
11
+ * This helper function retrieves addresses for a specific accountIndex from the walletStore.
12
+ * Addresses are stored in walletStore as: { [network]: { [accountIndex]: address } }
13
+ * This converts them to: { [network]: address } for a specific accountIndex
14
+ *
15
+ * NOTE: walletStore is the ONLY place where addresses are actually stored.
16
+ * This function simply retrieves/looks up addresses from walletStore.
17
+ *
18
+ * @param walletStore - The wallet store instance (Zustand store) - the source of truth for addresses
19
+ * @param accountIndex - The account index to get addresses for
20
+ * @returns Record of network -> address for the given accountIndex
21
+ */
22
+ export declare function getWalletAddresses(walletStore: {
23
+ getState: () => WalletStoreType;
24
+ }, accountIndex: number): Record<string, string>;
25
+ /**
26
+ * Create a base wallet store that wraps the worklet and wallet stores
27
+ *
28
+ * This provides the worklet methods (callAccountMethod, isWalletInitialized)
29
+ * and helper functions for retrieving addresses from walletStore.
30
+ * Apps should extend this with their own wallet metadata and balance management.
31
+ *
32
+ * Always uses the default MMKV storage adapter.
33
+ *
34
+ * @returns Base wallet store implementation
35
+ */
36
+ export declare function createBaseWalletStore(): Pick<WalletStore, 'callAccountMethod' | 'isWalletInitialized'> & {
37
+ getWalletAddresses: (accountIndex: number) => Record<string, string>;
38
+ };
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Wallet Utilities
3
+ *
4
+ * Helper functions for working with wallets and retrieving addresses from walletStore.
5
+ */
6
+ import { AccountService } from '../services/accountService';
7
+ import { getWalletStore } from '../store/walletStore';
8
+ import { getWorkletStore } from '../store/workletStore';
9
+ /**
10
+ * Get addresses for a wallet from walletStore
11
+ *
12
+ * This helper function retrieves addresses for a specific accountIndex from the walletStore.
13
+ * Addresses are stored in walletStore as: { [network]: { [accountIndex]: address } }
14
+ * This converts them to: { [network]: address } for a specific accountIndex
15
+ *
16
+ * NOTE: walletStore is the ONLY place where addresses are actually stored.
17
+ * This function simply retrieves/looks up addresses from walletStore.
18
+ *
19
+ * @param walletStore - The wallet store instance (Zustand store) - the source of truth for addresses
20
+ * @param accountIndex - The account index to get addresses for
21
+ * @returns Record of network -> address for the given accountIndex
22
+ */
23
+ export function getWalletAddresses(walletStore, accountIndex) {
24
+ const state = walletStore.getState();
25
+ const addresses = {};
26
+ // Get active wallet ID or use all wallets
27
+ const activeWalletId = state.activeWalletId;
28
+ // Retrieve addresses for this accountIndex from walletStore
29
+ // state.addresses is WalletAddressesByWallet: { [walletId]: { [network]: { [accountIndex]: address } } }
30
+ if (activeWalletId && state.addresses[activeWalletId]) {
31
+ // Use active wallet if available
32
+ const walletAddresses = state.addresses[activeWalletId];
33
+ // walletAddresses is WalletAddresses: { [network]: { [accountIndex]: address } }
34
+ Object.entries(walletAddresses).forEach(([network, networkAddresses]) => {
35
+ if (networkAddresses && typeof networkAddresses === 'object') {
36
+ const address = networkAddresses[accountIndex];
37
+ if (address) {
38
+ addresses[network] = address;
39
+ }
40
+ }
41
+ });
42
+ }
43
+ else {
44
+ // Fallback: iterate over all wallets (for backward compatibility or when no active wallet)
45
+ Object.values(state.addresses).forEach((walletAddresses) => {
46
+ if (walletAddresses && typeof walletAddresses === 'object') {
47
+ // walletAddresses is WalletAddresses: { [network]: { [accountIndex]: address } }
48
+ Object.entries(walletAddresses).forEach(([network, networkAddresses]) => {
49
+ if (networkAddresses && typeof networkAddresses === 'object') {
50
+ const address = networkAddresses[accountIndex];
51
+ if (address) {
52
+ addresses[network] = address;
53
+ }
54
+ }
55
+ });
56
+ }
57
+ });
58
+ }
59
+ return addresses;
60
+ }
61
+ /**
62
+ * Create a base wallet store that wraps the worklet and wallet stores
63
+ *
64
+ * This provides the worklet methods (callAccountMethod, isWalletInitialized)
65
+ * and helper functions for retrieving addresses from walletStore.
66
+ * Apps should extend this with their own wallet metadata and balance management.
67
+ *
68
+ * Always uses the default MMKV storage adapter.
69
+ *
70
+ * @returns Base wallet store implementation
71
+ */
72
+ export function createBaseWalletStore() {
73
+ const workletStore = getWorkletStore();
74
+ const walletStore = getWalletStore();
75
+ return {
76
+ callAccountMethod: async (network, accountIndex, methodName, args) => {
77
+ return AccountService.callAccountMethod(network, accountIndex, methodName, args);
78
+ },
79
+ isWalletInitialized: () => {
80
+ return workletStore.getState().isInitialized;
81
+ },
82
+ getWalletAddresses: (accountIndex) => {
83
+ return getWalletAddresses(walletStore, accountIndex);
84
+ },
85
+ };
86
+ }
87
+ //# sourceMappingURL=walletUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walletUtils.js","sourceRoot":"","sources":["../../src/utils/walletUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAIvD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,WAAgD,EAChD,YAAoB;IAEpB,MAAM,KAAK,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAA;IACpC,MAAM,SAAS,GAA2B,EAAE,CAAA;IAE5C,0CAA0C;IAC1C,MAAM,cAAc,GAAG,KAAK,CAAC,cAAc,CAAA;IAE3C,4DAA4D;IAC5D,yGAAyG;IACzG,IAAI,cAAc,IAAI,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC;QACtD,iCAAiC;QACjC,MAAM,eAAe,GAAG,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;QACvD,iFAAiF;QACjF,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,gBAAgB,CAAC,EAAE,EAAE;YACtE,IAAI,gBAAgB,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;gBAC7D,MAAM,OAAO,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAA;gBAC9C,IAAI,OAAO,EAAE,CAAC;oBACZ,SAAS,CAA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OAAO,kBAAkB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAA;QACtD,CAAC;KACF,CAAA;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@spacesops/wdk-react-native-core",
3
+ "version": "1.0.0-beta.40",
4
+ "description": "Core functionality for React Native wallets - wallet management, balance fetching, and worklet operations",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "react-native": "./src/index.ts",
9
+ "files": [
10
+ "dist",
11
+ "src",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "react-native": "./src/index.ts",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "registry": "https://registry.npmjs.org/"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/spacesops/wdk-react-native-core.git"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/spacesops/wdk-react-native-core/issues"
32
+ },
33
+ "homepage": "https://github.com/spacesops/wdk-react-native-core#readme",
34
+ "scripts": {
35
+ "build": "tsc || true",
36
+ "build:strict": "tsc",
37
+ "typecheck": "tsc --noEmit",
38
+ "test": "jest",
39
+ "test:watch": "jest --watch",
40
+ "test:coverage": "jest --coverage",
41
+ "prepack": "npm run build",
42
+ "postinstall": "npm run build"
43
+ },
44
+ "keywords": [
45
+ "wallet",
46
+ "react-native",
47
+ "core",
48
+ "crypto",
49
+ "blockchain",
50
+ "balance"
51
+ ],
52
+ "author": "Spacesops",
53
+ "license": "Apache-2.0",
54
+ "dependencies": {
55
+ "@tetherto/wdk-react-native-secure-storage": "github:tetherto/wdk-react-native-secure-storage",
56
+ "@tanstack/react-query": "^5.0.0",
57
+ "expo-crypto": "^15.0.8",
58
+ "@spacesops/pear-wrk-wdk": "1.1.1-beta.40",
59
+ "@spacesops/react-native-bare-kit": "0.11.0-beta.40",
60
+ "react-native-mmkv": "^4.1.0",
61
+ "zod": "^3.22.0",
62
+ "zustand": "^5.0.9"
63
+ },
64
+ "devDependencies": {
65
+ "@testing-library/jest-native": "^5.4.3",
66
+ "@testing-library/react-native": "^12.4.0",
67
+ "@types/jest": "^29.5.0",
68
+ "@types/react": "^19.0.0",
69
+ "@types/react-native": "^0.73.0",
70
+ "bufferutil": "^4.1.0",
71
+ "jest": "^29.7.0",
72
+ "jest-environment-node": "^29.7.0",
73
+ "ts-jest": "^29.1.0",
74
+ "typescript": "^5.3.3"
75
+ },
76
+ "peerDependencies": {
77
+ "react-native": ">=0.70.0"
78
+ }
79
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Mock React module for Jest tests
3
+ * Required by Zustand v5 which imports React
4
+ */
5
+
6
+ export const useState = jest.fn((initial: any) => [initial, jest.fn()])
7
+ export const useEffect = jest.fn()
8
+ export const useCallback = jest.fn((fn: any) => fn)
9
+ export const useMemo = jest.fn((fn: any) => fn())
10
+ export const useRef = jest.fn((initial: any) => ({ current: initial }))
11
+ export const createContext = jest.fn(() => ({
12
+ Provider: ({ children }: any) => children,
13
+ Consumer: ({ children }: any) => children,
14
+ }))
15
+ export const useContext = jest.fn()
16
+ export const useReducer = jest.fn((reducer: any, initial: any) => [initial, jest.fn()])
17
+ export class Component {}
18
+ export const Fragment = ({ children }: any) => children
19
+ export const version = '18.0.0'
20
+
21
+ export default {
22
+ useState,
23
+ useEffect,
24
+ useCallback,
25
+ useMemo,
26
+ useRef,
27
+ createContext,
28
+ useContext,
29
+ useReducer,
30
+ Component,
31
+ Fragment,
32
+ version,
33
+ }
34
+