@onairos/react-native 3.1.16 → 3.1.18

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 (207) hide show
  1. package/README.md +404 -0
  2. package/lib/commonjs/assets/images/Checkbox.svg +3 -3
  3. package/lib/commonjs/assets/images/EnochE.svg +19 -19
  4. package/lib/commonjs/assets/images/Personalityprofile.svg +3 -3
  5. package/lib/commonjs/assets/images/Personalitytraits.svg +3 -3
  6. package/lib/commonjs/assets/images/Userpreferences.svg +3 -3
  7. package/lib/commonjs/assets/images/arrow.svg +20 -20
  8. package/lib/commonjs/assets/images/basicproficon.svg +43 -43
  9. package/lib/commonjs/assets/images/basicprofile.svg +3 -3
  10. package/lib/commonjs/assets/images/checkmark.svg +4 -4
  11. package/lib/commonjs/assets/images/contentanalysis.svg +3 -3
  12. package/lib/commonjs/assets/images/contenticon.svg +23 -23
  13. package/lib/commonjs/assets/images/personalityicon.svg +18 -18
  14. package/lib/commonjs/assets/images/x-close.svg +3 -3
  15. package/lib/commonjs/components/ModalSheet.js +8 -2
  16. package/lib/commonjs/components/ModalSheet.js.map +1 -1
  17. package/lib/commonjs/components/OnairosButton.js +290 -0
  18. package/lib/commonjs/components/OnairosButton.js.map +1 -0
  19. package/lib/commonjs/components/OnairosSignInButton.js +32 -8
  20. package/lib/commonjs/components/OnairosSignInButton.js.map +1 -1
  21. package/lib/commonjs/components/UniversalOnboarding.js +4 -4
  22. package/lib/commonjs/components/WelcomeScreen.js +29 -13
  23. package/lib/commonjs/components/WelcomeScreen.js.map +1 -1
  24. package/lib/commonjs/config/api.js +2 -2
  25. package/lib/commonjs/hooks/useConnections.js +6 -6
  26. package/lib/commonjs/hooks/useUserConnections.js +10 -10
  27. package/lib/commonjs/index.js +13 -6
  28. package/lib/commonjs/index.js.map +1 -1
  29. package/lib/commonjs/services/apiClient.js +35 -35
  30. package/lib/commonjs/services/apiKeyService.js +99 -99
  31. package/lib/commonjs/services/authService.js +82 -82
  32. package/lib/commonjs/services/biometricPinService.js +10 -10
  33. package/lib/commonjs/services/connectedAccountsService.js +32 -32
  34. package/lib/commonjs/services/googleAuthService.js +15 -15
  35. package/lib/commonjs/services/imageCompressionService.js +15 -15
  36. package/lib/commonjs/services/jwtStorageService.js +59 -59
  37. package/lib/commonjs/services/mobileTrainingService.js +14 -14
  38. package/lib/commonjs/services/pinEncryptionService.js +10 -10
  39. package/lib/commonjs/services/pinStorageUtils.js +15 -15
  40. package/lib/commonjs/services/platformAuthService.js +47 -47
  41. package/lib/commonjs/services/storageService.js +31 -31
  42. package/lib/commonjs/services/trainingApiHelpers.js +33 -33
  43. package/lib/commonjs/services/userConnectionsService.js +24 -24
  44. package/lib/commonjs/utils/Portal.js +4 -4
  45. package/lib/commonjs/utils/api.js +24 -24
  46. package/lib/commonjs/utils/auth.js +18 -18
  47. package/lib/commonjs/utils/crypto.js +13 -13
  48. package/lib/commonjs/utils/encryption.js +12 -12
  49. package/lib/commonjs/utils/eventUtils.js +52 -52
  50. package/lib/commonjs/utils/programmaticFlow.js +16 -16
  51. package/lib/commonjs/utils/retryHelper.js +27 -27
  52. package/lib/module/assets/images/Checkbox.svg +3 -3
  53. package/lib/module/assets/images/EnochE.svg +19 -19
  54. package/lib/module/assets/images/Personalityprofile.svg +3 -3
  55. package/lib/module/assets/images/Personalitytraits.svg +3 -3
  56. package/lib/module/assets/images/Userpreferences.svg +3 -3
  57. package/lib/module/assets/images/arrow.svg +20 -20
  58. package/lib/module/assets/images/basicproficon.svg +43 -43
  59. package/lib/module/assets/images/basicprofile.svg +3 -3
  60. package/lib/module/assets/images/checkmark.svg +4 -4
  61. package/lib/module/assets/images/contentanalysis.svg +3 -3
  62. package/lib/module/assets/images/contenticon.svg +23 -23
  63. package/lib/module/assets/images/personalityicon.svg +18 -18
  64. package/lib/module/assets/images/x-close.svg +3 -3
  65. package/lib/module/components/ModalSheet.js +7 -2
  66. package/lib/module/components/ModalSheet.js.map +1 -1
  67. package/lib/module/components/OnairosButton.js +282 -0
  68. package/lib/module/components/OnairosButton.js.map +1 -0
  69. package/lib/module/components/OnairosSignInButton.js +32 -8
  70. package/lib/module/components/OnairosSignInButton.js.map +1 -1
  71. package/lib/module/components/UniversalOnboarding.js +4 -4
  72. package/lib/module/components/WelcomeScreen.js +25 -10
  73. package/lib/module/components/WelcomeScreen.js.map +1 -1
  74. package/lib/module/config/api.js +2 -2
  75. package/lib/module/hooks/useConnections.js +6 -6
  76. package/lib/module/hooks/useUserConnections.js +10 -10
  77. package/lib/module/index.js +11 -11
  78. package/lib/module/index.js.map +1 -1
  79. package/lib/module/services/apiClient.js +35 -35
  80. package/lib/module/services/apiKeyService.js +99 -99
  81. package/lib/module/services/authService.js +82 -82
  82. package/lib/module/services/biometricPinService.js +10 -10
  83. package/lib/module/services/connectedAccountsService.js +32 -32
  84. package/lib/module/services/googleAuthService.js +15 -15
  85. package/lib/module/services/imageCompressionService.js +15 -15
  86. package/lib/module/services/jwtStorageService.js +59 -59
  87. package/lib/module/services/mobileTrainingService.js +14 -14
  88. package/lib/module/services/pinEncryptionService.js +10 -10
  89. package/lib/module/services/pinStorageUtils.js +15 -15
  90. package/lib/module/services/platformAuthService.js +47 -47
  91. package/lib/module/services/storageService.js +31 -31
  92. package/lib/module/services/trainingApiHelpers.js +33 -33
  93. package/lib/module/services/userConnectionsService.js +24 -24
  94. package/lib/module/utils/Portal.js +4 -4
  95. package/lib/module/utils/api.js +24 -24
  96. package/lib/module/utils/auth.js +18 -18
  97. package/lib/module/utils/crypto.js +13 -13
  98. package/lib/module/utils/encryption.js +12 -12
  99. package/lib/module/utils/eventUtils.js +52 -52
  100. package/lib/module/utils/programmaticFlow.js +16 -16
  101. package/lib/module/utils/retryHelper.js +27 -27
  102. package/lib/typescript/components/ModalSheet.d.ts.map +1 -1
  103. package/lib/typescript/components/OnairosButton.d.ts +37 -0
  104. package/lib/typescript/components/OnairosButton.d.ts.map +1 -0
  105. package/lib/typescript/components/OnairosSignInButton.d.ts.map +1 -1
  106. package/lib/typescript/components/WelcomeScreen.d.ts.map +1 -1
  107. package/lib/typescript/index.d.ts +3 -1
  108. package/lib/typescript/index.d.ts.map +1 -1
  109. package/package.json +145 -163
  110. package/src/api/index.ts +151 -151
  111. package/src/assets/images/Checkbox.svg +3 -3
  112. package/src/assets/images/EnochE.svg +19 -19
  113. package/src/assets/images/Personalityprofile.svg +3 -3
  114. package/src/assets/images/Personalitytraits.svg +3 -3
  115. package/src/assets/images/Userpreferences.svg +3 -3
  116. package/src/assets/images/arrow.svg +20 -20
  117. package/src/assets/images/basicproficon.svg +43 -43
  118. package/src/assets/images/basicprofile.svg +3 -3
  119. package/src/assets/images/checkmark.svg +4 -4
  120. package/src/assets/images/contentanalysis.svg +3 -3
  121. package/src/assets/images/contenticon.svg +23 -23
  122. package/src/assets/images/personalityicon.svg +18 -18
  123. package/src/assets/images/x-close.svg +3 -3
  124. package/src/components/BodyText.tsx +33 -33
  125. package/src/components/BrandMark.tsx +62 -62
  126. package/src/components/CodeInput.tsx +32 -32
  127. package/src/components/DataRequestScreen.tsx +355 -355
  128. package/src/components/EmailInput.tsx +31 -31
  129. package/src/components/EmailVerificationModal.tsx +363 -363
  130. package/src/components/ExistingUserDataConfirmation.tsx +506 -506
  131. package/src/components/GoogleButton.tsx +55 -55
  132. package/src/components/HeadingGroup.tsx +49 -49
  133. package/src/components/ModalHeader.tsx +125 -125
  134. package/src/components/ModalSheet.tsx +59 -57
  135. package/src/components/Onairos.tsx +422 -422
  136. package/src/components/OnairosButton.tsx +339 -0
  137. package/src/components/OnairosSignInButton.tsx +31 -9
  138. package/src/components/Overlay.tsx +506 -506
  139. package/src/components/PersonaImage.tsx +79 -79
  140. package/src/components/PersonaLoadingScreen.tsx +201 -201
  141. package/src/components/PersonalizationConsentScreen.tsx +410 -410
  142. package/src/components/PinCreationScreen.tsx +492 -492
  143. package/src/components/PinInput.tsx +555 -555
  144. package/src/components/PlatformConnectorsStep.tsx +891 -891
  145. package/src/components/PlatformList.tsx +144 -144
  146. package/src/components/PlatformToggle.tsx +226 -226
  147. package/src/components/PrimaryButton.tsx +213 -213
  148. package/src/components/SignInMatchAnimation.tsx +225 -225
  149. package/src/components/SignInStep.tsx +217 -217
  150. package/src/components/TrainingModal.tsx +1047 -1047
  151. package/src/components/UniversalOnboarding.tsx +2887 -2887
  152. package/src/components/VerificationStep.tsx +198 -198
  153. package/src/components/WelcomeScreen.tsx +490 -473
  154. package/src/components/icons/Basicproficon.tsx +30 -30
  155. package/src/components/icons/Basicprofile.tsx +17 -17
  156. package/src/components/icons/Checkbox.tsx +17 -17
  157. package/src/components/icons/Checkmark.tsx +24 -24
  158. package/src/components/icons/Contentanalysis.tsx +17 -17
  159. package/src/components/icons/Contenticon.tsx +30 -30
  160. package/src/components/icons/EnochE.tsx +39 -39
  161. package/src/components/icons/Personalityicon.tsx +22 -22
  162. package/src/components/icons/Personalityprofile.tsx +17 -17
  163. package/src/components/icons/Personalitytraits.tsx +17 -17
  164. package/src/components/icons/Userpreferences.tsx +17 -17
  165. package/src/components/icons/index.ts +12 -12
  166. package/src/components/onboarding/OAuthWebView.tsx +232 -232
  167. package/src/config/api.ts +25 -25
  168. package/src/context/AuthContext.tsx +393 -393
  169. package/src/hooks/useConnectedAccounts.ts +138 -138
  170. package/src/hooks/useConnections.ts +161 -161
  171. package/src/hooks/useCredentials.ts +174 -174
  172. package/src/hooks/useUserConnections.ts +165 -165
  173. package/src/index.js +14 -0
  174. package/src/index.ts +99 -96
  175. package/src/services/apiClient.ts +336 -336
  176. package/src/services/apiKeyService.ts +919 -919
  177. package/src/services/authService.ts +1008 -1008
  178. package/src/services/biometricPinService.ts +192 -192
  179. package/src/services/connectedAccountsService.ts +289 -289
  180. package/src/services/googleAuthService.ts +279 -279
  181. package/src/services/imageCompressionService.ts +302 -302
  182. package/src/services/jwtStorageService.ts +256 -256
  183. package/src/services/mobileTrainingService.ts +203 -203
  184. package/src/services/pinEncryptionService.ts +75 -75
  185. package/src/services/pinStorageUtils.ts +96 -96
  186. package/src/services/platformAuthService.ts +1346 -1346
  187. package/src/services/storageService.ts +451 -451
  188. package/src/services/trainingApiHelpers.ts +66 -66
  189. package/src/services/userConnectionsService.ts +556 -556
  190. package/src/services/youtubeMigrationService.ts +453 -453
  191. package/src/theme/index.ts +239 -239
  192. package/src/types/ambient.d.ts +28 -28
  193. package/src/types/index.ts +265 -265
  194. package/src/types/node-fix.d.ts +18 -18
  195. package/src/types/node-override.d.ts +23 -23
  196. package/src/types/opacity.d.ts +15 -15
  197. package/src/types/types.d.ts +17 -17
  198. package/src/utils/Portal.tsx +82 -82
  199. package/src/utils/api.js +111 -111
  200. package/src/utils/auth.js +103 -103
  201. package/src/utils/crypto.js +59 -59
  202. package/src/utils/encryption.ts +68 -68
  203. package/src/utils/eventUtils.ts +302 -302
  204. package/src/utils/haptics.ts +58 -58
  205. package/src/utils/imagePreloader.ts +2 -2
  206. package/src/utils/programmaticFlow.ts +112 -112
  207. package/src/utils/retryHelper.ts +274 -274
@@ -1,492 +1,492 @@
1
- import React, { useState, useEffect } from 'react';
2
- import {
3
- View,
4
- Text,
5
- StyleSheet,
6
- TouchableOpacity,
7
- TextInput,
8
- Alert,
9
- ActivityIndicator,
10
- } from 'react-native';
11
- import { COLORS } from '../theme';
12
- import { triggerHaptic, HapticType } from '../utils/haptics';
13
- import { biometricPinService } from '../services/biometricPinService';
14
- import { setTemporaryPin } from '../services/pinStorageUtils';
15
-
16
- interface PinCreationScreenProps {
17
- visible: boolean;
18
- onComplete: (pin: string) => void;
19
- onBack: () => void;
20
- }
21
-
22
- const PinCreationScreen: React.FC<PinCreationScreenProps> = ({
23
- visible,
24
- onComplete,
25
- onBack,
26
- }) => {
27
- const [pin, setPin] = useState('');
28
- const [requirements, setRequirements] = useState({
29
- length: false,
30
- uppercase: false,
31
- number: false,
32
- });
33
- const [isLoading, setIsLoading] = useState(false);
34
- const [biometricAvailable, setBiometricAvailable] = useState(false);
35
- const [biometricStatus, setBiometricStatus] = useState<'checking' | 'available' | 'unavailable' | 'storing' | 'success' | 'error'>('checking');
36
-
37
- const validatePin = (pinText: string) => {
38
- const newRequirements = {
39
- length: pinText.length >= 6,
40
- uppercase: /[A-Z]/.test(pinText),
41
- number: /[0-9]/.test(pinText),
42
- };
43
- setRequirements(newRequirements);
44
- return Object.values(newRequirements).every(req => req);
45
- };
46
-
47
- const handlePinChange = (text: string) => {
48
- setPin(text);
49
- validatePin(text);
50
- };
51
-
52
- const handleContinue = async () => {
53
- if (!validatePin(pin)) {
54
- triggerHaptic(HapticType.ERROR);
55
- Alert.alert('Invalid PIN', 'Please ensure your PIN meets all requirements.');
56
- return;
57
- }
58
-
59
- triggerHaptic(HapticType.BUTTON_PRESS);
60
- setIsLoading(true);
61
-
62
- try {
63
- console.log('🔐 Starting PIN creation process...');
64
-
65
- // Store PIN temporarily for the onboarding flow first
66
- setTemporaryPin(pin);
67
- console.log('📝 PIN stored temporarily for onboarding');
68
-
69
- // If biometric is available, immediately trigger Face ID authentication
70
- if (biometricAvailable) {
71
- setBiometricStatus('storing');
72
- console.log('🔐 [PIN CREATION] Biometric storage enabled, starting biometric flow...');
73
-
74
- // Double-check biometric availability right before triggering
75
- const biometricStillAvailable = await biometricPinService.isBiometricAvailable();
76
- console.log('📱 [PIN CREATION] Biometric available before storage:', biometricStillAvailable);
77
-
78
- if (!biometricStillAvailable) {
79
- console.error('❌ [PIN CREATION] Face ID not available on this device');
80
- setBiometricStatus('unavailable');
81
- setIsLoading(false);
82
- return;
83
- }
84
-
85
- // Immediately attempt to store PIN with biometric authentication
86
- console.log('🔐 [PIN CREATION] Triggering biometric authentication for PIN storage...');
87
-
88
- // This will immediately show the Face ID prompt
89
- const stored = await biometricPinService.storePinWithBiometric(pin);
90
-
91
- if (stored) {
92
- console.log('✅ PIN stored successfully with Face ID');
93
-
94
- // Verify the PIN was actually stored by checking if it can be retrieved
95
- const isStored = await biometricPinService.isPinStored();
96
- if (isStored) {
97
- console.log('✅ PIN storage verified - proceeding with onboarding');
98
- setBiometricStatus('success');
99
- triggerHaptic(HapticType.SUCCESS);
100
-
101
- // Brief success state, then continue
102
- setTimeout(() => {
103
- setIsLoading(false);
104
- onComplete(pin);
105
- }, 800);
106
- } else {
107
- console.error('❌ PIN storage verification failed');
108
- setBiometricStatus('error');
109
- setIsLoading(false);
110
- triggerHaptic(HapticType.ERROR);
111
- Alert.alert(
112
- 'PIN Storage Error',
113
- 'PIN storage verification failed. Please try again.',
114
- [{ text: 'OK' }]
115
- );
116
- }
117
- } else {
118
- console.log('⚠️ Face ID authentication was cancelled or failed');
119
- setBiometricStatus('error');
120
- triggerHaptic(HapticType.ERROR);
121
-
122
- // Show error but still allow continuation
123
- Alert.alert(
124
- 'Face ID Setup',
125
- 'Face ID authentication was cancelled or failed. Your PIN is still saved securely.',
126
- [
127
- {
128
- text: 'Try Again',
129
- onPress: () => {
130
- setIsLoading(false);
131
- setBiometricStatus('available');
132
- }
133
- },
134
- {
135
- text: 'Continue Without Face ID',
136
- onPress: () => {
137
- setIsLoading(false);
138
- onComplete(pin);
139
- }
140
- }
141
- ]
142
- );
143
- }
144
- } else {
145
- console.log('📱 Biometric not available, continuing without Face ID');
146
- setBiometricStatus('unavailable');
147
- setIsLoading(false);
148
- onComplete(pin);
149
- }
150
- } catch (error) {
151
- console.error('❌ Error in PIN creation process:', error);
152
- setBiometricStatus('error');
153
- setIsLoading(false);
154
- triggerHaptic(HapticType.ERROR);
155
- Alert.alert(
156
- 'PIN Creation Error',
157
- 'There was an issue creating your PIN. Please try again.',
158
- [{ text: 'OK' }]
159
- );
160
- }
161
- };
162
-
163
- const handleBack = () => {
164
- triggerHaptic(HapticType.BUTTON_PRESS);
165
- onBack();
166
- };
167
-
168
- // Check biometric availability on component mount
169
- useEffect(() => {
170
- const checkBiometric = async () => {
171
- try {
172
- setBiometricStatus('checking');
173
- const available = await biometricPinService.isBiometricAvailable();
174
- setBiometricAvailable(available);
175
- setBiometricStatus(available ? 'available' : 'unavailable');
176
- console.log('📱 Biometric availability check:', available);
177
- } catch (error) {
178
- console.error('❌ Error checking biometric availability:', error);
179
- setBiometricAvailable(false);
180
- setBiometricStatus('unavailable');
181
- }
182
- };
183
-
184
- if (visible) {
185
- checkBiometric();
186
- }
187
- }, [visible]);
188
-
189
- const allRequirementsMet = Object.values(requirements).every(req => req);
190
-
191
- if (!visible) return null;
192
-
193
- return (
194
- <View style={styles.container}>
195
- {/* Title */}
196
- <View style={styles.titleContainer}>
197
- <Text style={styles.title}>Create a PIN</Text>
198
- <Text style={styles.subtitle}>A PIN so only you have access to your data.</Text>
199
- </View>
200
-
201
- {/* PIN Input */}
202
- <View style={styles.pinContainer}>
203
- <TextInput
204
- style={styles.pinInput}
205
- value={pin}
206
- onChangeText={handlePinChange}
207
- placeholder="Enter your PIN"
208
- secureTextEntry
209
- autoFocus
210
- maxLength={20}
211
- />
212
- </View>
213
-
214
- {/* Requirements */}
215
- <View style={styles.requirementsContainer}>
216
- <Text style={styles.requirementsTitle}>Your PIN must:</Text>
217
-
218
- <View style={styles.requirementItem}>
219
- <View style={[styles.checkbox, requirements.length && styles.checkboxChecked]}>
220
- {requirements.length && <Text style={styles.checkmark}>✓</Text>}
221
- </View>
222
- <Text style={[styles.requirementText, requirements.length && styles.requirementTextMet]}>
223
- Be at least 6 characters in length.
224
- </Text>
225
- </View>
226
-
227
- <View style={styles.requirementItem}>
228
- <View style={[styles.checkbox, requirements.uppercase && styles.checkboxChecked]}>
229
- {requirements.uppercase && <Text style={styles.checkmark}>✓</Text>}
230
- </View>
231
- <Text style={[styles.requirementText, requirements.uppercase && styles.requirementTextMet]}>
232
- Contain an uppercase letter.
233
- </Text>
234
- </View>
235
-
236
- <View style={styles.requirementItem}>
237
- <View style={[styles.checkbox, requirements.number && styles.checkboxChecked]}>
238
- {requirements.number && <Text style={styles.checkmark}>✓</Text>}
239
- </View>
240
- <Text style={[styles.requirementText, requirements.number && styles.requirementTextMet]}>
241
- Contain a number.
242
- </Text>
243
- </View>
244
- </View>
245
-
246
- {/* FaceID Security Card */}
247
- <View style={[
248
- styles.securityCard,
249
- biometricStatus === 'success' && styles.securityCardSuccess,
250
- biometricStatus === 'error' && styles.securityCardError
251
- ]}>
252
- <View style={styles.securityIconContainer}>
253
- {biometricStatus === 'checking' && (
254
- <ActivityIndicator size="small" color={COLORS.grey600} />
255
- )}
256
- {biometricStatus === 'storing' && (
257
- <ActivityIndicator size="small" color="#D4A536" />
258
- )}
259
- {biometricStatus === 'available' && (
260
- <Text style={styles.securityIcon}>🔐</Text>
261
- )}
262
- {biometricStatus === 'unavailable' && (
263
- <Text style={styles.securityIcon}>⚠️</Text>
264
- )}
265
- {biometricStatus === 'success' && (
266
- <Text style={styles.securityIcon}>✅</Text>
267
- )}
268
- {biometricStatus === 'error' && (
269
- <Text style={styles.securityIcon}>❌</Text>
270
- )}
271
- </View>
272
- <View style={styles.securityTextContainer}>
273
- <Text style={styles.securityTitle}>
274
- {biometricStatus === 'checking' && 'Checking Face ID...'}
275
- {biometricStatus === 'available' && 'Enhanced Security'}
276
- {biometricStatus === 'unavailable' && 'Face ID Unavailable'}
277
- {biometricStatus === 'storing' && 'Securing with Face ID...'}
278
- {biometricStatus === 'success' && 'PIN Secured with Face ID'}
279
- {biometricStatus === 'error' && 'Face ID Setup Failed'}
280
- </Text>
281
- <Text style={styles.securityDescription}>
282
- {biometricStatus === 'checking' && 'Verifying Face ID availability on your device.'}
283
- {biometricStatus === 'available' && 'We use Face ID to ensure only you can access your data.'}
284
- {biometricStatus === 'unavailable' && 'Face ID is not available on this device. Your PIN will be stored securely.'}
285
- {biometricStatus === 'storing' && 'Please authenticate with Face ID to secure your PIN.'}
286
- {biometricStatus === 'success' && 'Your PIN is now protected with Face ID authentication.'}
287
- {biometricStatus === 'error' && 'Face ID setup failed, but your PIN is stored securely.'}
288
- </Text>
289
- </View>
290
- </View>
291
-
292
- {/* Continue Button */}
293
- <View style={styles.buttonContainer}>
294
- <TouchableOpacity
295
- style={[
296
- styles.continueButton,
297
- allRequirementsMet && styles.continueButtonActive
298
- ]}
299
- onPress={handleContinue}
300
- disabled={!allRequirementsMet || isLoading}
301
- >
302
- {isLoading ? (
303
- <ActivityIndicator size="small" color="#FFFFFF" />
304
- ) : (
305
- <Text style={[
306
- styles.continueButtonText,
307
- allRequirementsMet && styles.continueButtonTextActive
308
- ]}>
309
- Continue
310
- </Text>
311
- )}
312
- </TouchableOpacity>
313
- </View>
314
- </View>
315
- );
316
- };
317
-
318
- const styles = StyleSheet.create({
319
- container: {
320
- flex: 1,
321
- backgroundColor: COLORS.surface,
322
- paddingHorizontal: 24,
323
- paddingTop: 0,
324
- },
325
-
326
- titleContainer: {
327
- alignItems: 'center',
328
- marginBottom: 15,
329
- paddingTop: -10,
330
- marginTop: -15,
331
- },
332
-
333
- title: {
334
- fontSize: 24,
335
- fontWeight: '700',
336
- color: COLORS.grey800,
337
- marginBottom: 8,
338
- fontFamily: 'IBM Plex Sans',
339
- },
340
-
341
- subtitle: {
342
- fontSize: 16,
343
- color: COLORS.grey600,
344
- lineHeight: 24,
345
- fontFamily: 'Inter',
346
- },
347
-
348
- pinContainer: {
349
- marginBottom: 32,
350
- },
351
-
352
- pinInput: {
353
- backgroundColor: '#F8F9FA',
354
- borderRadius: 12,
355
- paddingVertical: 16,
356
- paddingHorizontal: 16,
357
- fontSize: 16,
358
- fontFamily: 'Inter',
359
- borderWidth: 1,
360
- borderColor: '#E5E5E5',
361
- },
362
-
363
- requirementsContainer: {
364
- marginBottom: 32,
365
- },
366
-
367
- requirementsTitle: {
368
- fontSize: 16,
369
- fontWeight: '600',
370
- color: COLORS.grey800,
371
- marginBottom: 16,
372
- fontFamily: 'Inter',
373
- },
374
-
375
- requirementItem: {
376
- flexDirection: 'row',
377
- alignItems: 'center',
378
- marginBottom: 12,
379
- },
380
-
381
- checkbox: {
382
- width: 20,
383
- height: 20,
384
- borderRadius: 10,
385
- borderWidth: 2,
386
- borderColor: '#E5E5E5',
387
- marginRight: 12,
388
- alignItems: 'center',
389
- justifyContent: 'center',
390
- },
391
-
392
- checkboxChecked: {
393
- borderColor: '#4CD964',
394
- backgroundColor: '#4CD964',
395
- },
396
-
397
- checkmark: {
398
- color: '#FFFFFF',
399
- fontSize: 12,
400
- fontWeight: 'bold',
401
- },
402
-
403
- requirementText: {
404
- fontSize: 14,
405
- color: COLORS.grey600,
406
- fontFamily: 'Inter',
407
- flex: 1,
408
- },
409
-
410
- requirementTextMet: {
411
- color: COLORS.grey800,
412
- },
413
-
414
- securityCard: {
415
- backgroundColor: '#F8F9FA',
416
- borderRadius: 12,
417
- padding: 16,
418
- flexDirection: 'row',
419
- alignItems: 'center',
420
- marginBottom: 24,
421
- borderWidth: 1,
422
- borderColor: '#E5E5E5',
423
- },
424
-
425
- securityCardSuccess: {
426
- backgroundColor: '#F0FDF4',
427
- borderColor: '#22C55E',
428
- },
429
-
430
- securityCardError: {
431
- backgroundColor: '#FEF2F2',
432
- borderColor: '#EF4444',
433
- },
434
-
435
- securityIconContainer: {
436
- marginRight: 12,
437
- },
438
-
439
- securityIcon: {
440
- fontSize: 24,
441
- },
442
-
443
- securityTextContainer: {
444
- flex: 1,
445
- },
446
-
447
- securityTitle: {
448
- fontSize: 14,
449
- fontWeight: '600',
450
- color: COLORS.grey800,
451
- marginBottom: 4,
452
- fontFamily: 'Inter',
453
- },
454
-
455
- securityDescription: {
456
- fontSize: 13,
457
- color: COLORS.grey600,
458
- lineHeight: 18,
459
- fontFamily: 'Inter',
460
- },
461
-
462
- buttonContainer: {
463
- marginTop: 'auto',
464
- paddingBottom: 34,
465
- },
466
-
467
- continueButton: {
468
- backgroundColor: '#E5E5E5',
469
- borderRadius: 25,
470
- paddingVertical: 16,
471
- alignItems: 'center',
472
- justifyContent: 'center',
473
- },
474
-
475
- continueButtonActive: {
476
- backgroundColor: '#2D3436',
477
- },
478
-
479
- continueButtonText: {
480
- fontSize: 16,
481
- fontWeight: '600',
482
- color: '#999999',
483
- fontFamily: 'Inter',
484
- },
485
-
486
- continueButtonTextActive: {
487
- color: '#FFFFFF',
488
- },
489
- });
490
-
491
- export { PinCreationScreen };
492
- export default PinCreationScreen;
1
+ import React, { useState, useEffect } from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ StyleSheet,
6
+ TouchableOpacity,
7
+ TextInput,
8
+ Alert,
9
+ ActivityIndicator,
10
+ } from 'react-native';
11
+ import { COLORS } from '../theme';
12
+ import { triggerHaptic, HapticType } from '../utils/haptics';
13
+ import { biometricPinService } from '../services/biometricPinService';
14
+ import { setTemporaryPin } from '../services/pinStorageUtils';
15
+
16
+ interface PinCreationScreenProps {
17
+ visible: boolean;
18
+ onComplete: (pin: string) => void;
19
+ onBack: () => void;
20
+ }
21
+
22
+ const PinCreationScreen: React.FC<PinCreationScreenProps> = ({
23
+ visible,
24
+ onComplete,
25
+ onBack,
26
+ }) => {
27
+ const [pin, setPin] = useState('');
28
+ const [requirements, setRequirements] = useState({
29
+ length: false,
30
+ uppercase: false,
31
+ number: false,
32
+ });
33
+ const [isLoading, setIsLoading] = useState(false);
34
+ const [biometricAvailable, setBiometricAvailable] = useState(false);
35
+ const [biometricStatus, setBiometricStatus] = useState<'checking' | 'available' | 'unavailable' | 'storing' | 'success' | 'error'>('checking');
36
+
37
+ const validatePin = (pinText: string) => {
38
+ const newRequirements = {
39
+ length: pinText.length >= 6,
40
+ uppercase: /[A-Z]/.test(pinText),
41
+ number: /[0-9]/.test(pinText),
42
+ };
43
+ setRequirements(newRequirements);
44
+ return Object.values(newRequirements).every(req => req);
45
+ };
46
+
47
+ const handlePinChange = (text: string) => {
48
+ setPin(text);
49
+ validatePin(text);
50
+ };
51
+
52
+ const handleContinue = async () => {
53
+ if (!validatePin(pin)) {
54
+ triggerHaptic(HapticType.ERROR);
55
+ Alert.alert('Invalid PIN', 'Please ensure your PIN meets all requirements.');
56
+ return;
57
+ }
58
+
59
+ triggerHaptic(HapticType.BUTTON_PRESS);
60
+ setIsLoading(true);
61
+
62
+ try {
63
+ console.log('🔐 Starting PIN creation process...');
64
+
65
+ // Store PIN temporarily for the onboarding flow first
66
+ setTemporaryPin(pin);
67
+ console.log('📝 PIN stored temporarily for onboarding');
68
+
69
+ // If biometric is available, immediately trigger Face ID authentication
70
+ if (biometricAvailable) {
71
+ setBiometricStatus('storing');
72
+ console.log('🔐 [PIN CREATION] Biometric storage enabled, starting biometric flow...');
73
+
74
+ // Double-check biometric availability right before triggering
75
+ const biometricStillAvailable = await biometricPinService.isBiometricAvailable();
76
+ console.log('📱 [PIN CREATION] Biometric available before storage:', biometricStillAvailable);
77
+
78
+ if (!biometricStillAvailable) {
79
+ console.error('❌ [PIN CREATION] Face ID not available on this device');
80
+ setBiometricStatus('unavailable');
81
+ setIsLoading(false);
82
+ return;
83
+ }
84
+
85
+ // Immediately attempt to store PIN with biometric authentication
86
+ console.log('🔐 [PIN CREATION] Triggering biometric authentication for PIN storage...');
87
+
88
+ // This will immediately show the Face ID prompt
89
+ const stored = await biometricPinService.storePinWithBiometric(pin);
90
+
91
+ if (stored) {
92
+ console.log('✅ PIN stored successfully with Face ID');
93
+
94
+ // Verify the PIN was actually stored by checking if it can be retrieved
95
+ const isStored = await biometricPinService.isPinStored();
96
+ if (isStored) {
97
+ console.log('✅ PIN storage verified - proceeding with onboarding');
98
+ setBiometricStatus('success');
99
+ triggerHaptic(HapticType.SUCCESS);
100
+
101
+ // Brief success state, then continue
102
+ setTimeout(() => {
103
+ setIsLoading(false);
104
+ onComplete(pin);
105
+ }, 800);
106
+ } else {
107
+ console.error('❌ PIN storage verification failed');
108
+ setBiometricStatus('error');
109
+ setIsLoading(false);
110
+ triggerHaptic(HapticType.ERROR);
111
+ Alert.alert(
112
+ 'PIN Storage Error',
113
+ 'PIN storage verification failed. Please try again.',
114
+ [{ text: 'OK' }]
115
+ );
116
+ }
117
+ } else {
118
+ console.log('⚠️ Face ID authentication was cancelled or failed');
119
+ setBiometricStatus('error');
120
+ triggerHaptic(HapticType.ERROR);
121
+
122
+ // Show error but still allow continuation
123
+ Alert.alert(
124
+ 'Face ID Setup',
125
+ 'Face ID authentication was cancelled or failed. Your PIN is still saved securely.',
126
+ [
127
+ {
128
+ text: 'Try Again',
129
+ onPress: () => {
130
+ setIsLoading(false);
131
+ setBiometricStatus('available');
132
+ }
133
+ },
134
+ {
135
+ text: 'Continue Without Face ID',
136
+ onPress: () => {
137
+ setIsLoading(false);
138
+ onComplete(pin);
139
+ }
140
+ }
141
+ ]
142
+ );
143
+ }
144
+ } else {
145
+ console.log('📱 Biometric not available, continuing without Face ID');
146
+ setBiometricStatus('unavailable');
147
+ setIsLoading(false);
148
+ onComplete(pin);
149
+ }
150
+ } catch (error) {
151
+ console.error('❌ Error in PIN creation process:', error);
152
+ setBiometricStatus('error');
153
+ setIsLoading(false);
154
+ triggerHaptic(HapticType.ERROR);
155
+ Alert.alert(
156
+ 'PIN Creation Error',
157
+ 'There was an issue creating your PIN. Please try again.',
158
+ [{ text: 'OK' }]
159
+ );
160
+ }
161
+ };
162
+
163
+ const handleBack = () => {
164
+ triggerHaptic(HapticType.BUTTON_PRESS);
165
+ onBack();
166
+ };
167
+
168
+ // Check biometric availability on component mount
169
+ useEffect(() => {
170
+ const checkBiometric = async () => {
171
+ try {
172
+ setBiometricStatus('checking');
173
+ const available = await biometricPinService.isBiometricAvailable();
174
+ setBiometricAvailable(available);
175
+ setBiometricStatus(available ? 'available' : 'unavailable');
176
+ console.log('📱 Biometric availability check:', available);
177
+ } catch (error) {
178
+ console.error('❌ Error checking biometric availability:', error);
179
+ setBiometricAvailable(false);
180
+ setBiometricStatus('unavailable');
181
+ }
182
+ };
183
+
184
+ if (visible) {
185
+ checkBiometric();
186
+ }
187
+ }, [visible]);
188
+
189
+ const allRequirementsMet = Object.values(requirements).every(req => req);
190
+
191
+ if (!visible) return null;
192
+
193
+ return (
194
+ <View style={styles.container}>
195
+ {/* Title */}
196
+ <View style={styles.titleContainer}>
197
+ <Text style={styles.title}>Create a PIN</Text>
198
+ <Text style={styles.subtitle}>A PIN so only you have access to your data.</Text>
199
+ </View>
200
+
201
+ {/* PIN Input */}
202
+ <View style={styles.pinContainer}>
203
+ <TextInput
204
+ style={styles.pinInput}
205
+ value={pin}
206
+ onChangeText={handlePinChange}
207
+ placeholder="Enter your PIN"
208
+ secureTextEntry
209
+ autoFocus
210
+ maxLength={20}
211
+ />
212
+ </View>
213
+
214
+ {/* Requirements */}
215
+ <View style={styles.requirementsContainer}>
216
+ <Text style={styles.requirementsTitle}>Your PIN must:</Text>
217
+
218
+ <View style={styles.requirementItem}>
219
+ <View style={[styles.checkbox, requirements.length && styles.checkboxChecked]}>
220
+ {requirements.length && <Text style={styles.checkmark}>✓</Text>}
221
+ </View>
222
+ <Text style={[styles.requirementText, requirements.length && styles.requirementTextMet]}>
223
+ Be at least 6 characters in length.
224
+ </Text>
225
+ </View>
226
+
227
+ <View style={styles.requirementItem}>
228
+ <View style={[styles.checkbox, requirements.uppercase && styles.checkboxChecked]}>
229
+ {requirements.uppercase && <Text style={styles.checkmark}>✓</Text>}
230
+ </View>
231
+ <Text style={[styles.requirementText, requirements.uppercase && styles.requirementTextMet]}>
232
+ Contain an uppercase letter.
233
+ </Text>
234
+ </View>
235
+
236
+ <View style={styles.requirementItem}>
237
+ <View style={[styles.checkbox, requirements.number && styles.checkboxChecked]}>
238
+ {requirements.number && <Text style={styles.checkmark}>✓</Text>}
239
+ </View>
240
+ <Text style={[styles.requirementText, requirements.number && styles.requirementTextMet]}>
241
+ Contain a number.
242
+ </Text>
243
+ </View>
244
+ </View>
245
+
246
+ {/* FaceID Security Card */}
247
+ <View style={[
248
+ styles.securityCard,
249
+ biometricStatus === 'success' && styles.securityCardSuccess,
250
+ biometricStatus === 'error' && styles.securityCardError
251
+ ]}>
252
+ <View style={styles.securityIconContainer}>
253
+ {biometricStatus === 'checking' && (
254
+ <ActivityIndicator size="small" color={COLORS.grey600} />
255
+ )}
256
+ {biometricStatus === 'storing' && (
257
+ <ActivityIndicator size="small" color="#D4A536" />
258
+ )}
259
+ {biometricStatus === 'available' && (
260
+ <Text style={styles.securityIcon}>🔐</Text>
261
+ )}
262
+ {biometricStatus === 'unavailable' && (
263
+ <Text style={styles.securityIcon}>⚠️</Text>
264
+ )}
265
+ {biometricStatus === 'success' && (
266
+ <Text style={styles.securityIcon}>✅</Text>
267
+ )}
268
+ {biometricStatus === 'error' && (
269
+ <Text style={styles.securityIcon}>❌</Text>
270
+ )}
271
+ </View>
272
+ <View style={styles.securityTextContainer}>
273
+ <Text style={styles.securityTitle}>
274
+ {biometricStatus === 'checking' && 'Checking Face ID...'}
275
+ {biometricStatus === 'available' && 'Enhanced Security'}
276
+ {biometricStatus === 'unavailable' && 'Face ID Unavailable'}
277
+ {biometricStatus === 'storing' && 'Securing with Face ID...'}
278
+ {biometricStatus === 'success' && 'PIN Secured with Face ID'}
279
+ {biometricStatus === 'error' && 'Face ID Setup Failed'}
280
+ </Text>
281
+ <Text style={styles.securityDescription}>
282
+ {biometricStatus === 'checking' && 'Verifying Face ID availability on your device.'}
283
+ {biometricStatus === 'available' && 'We use Face ID to ensure only you can access your data.'}
284
+ {biometricStatus === 'unavailable' && 'Face ID is not available on this device. Your PIN will be stored securely.'}
285
+ {biometricStatus === 'storing' && 'Please authenticate with Face ID to secure your PIN.'}
286
+ {biometricStatus === 'success' && 'Your PIN is now protected with Face ID authentication.'}
287
+ {biometricStatus === 'error' && 'Face ID setup failed, but your PIN is stored securely.'}
288
+ </Text>
289
+ </View>
290
+ </View>
291
+
292
+ {/* Continue Button */}
293
+ <View style={styles.buttonContainer}>
294
+ <TouchableOpacity
295
+ style={[
296
+ styles.continueButton,
297
+ allRequirementsMet && styles.continueButtonActive
298
+ ]}
299
+ onPress={handleContinue}
300
+ disabled={!allRequirementsMet || isLoading}
301
+ >
302
+ {isLoading ? (
303
+ <ActivityIndicator size="small" color="#FFFFFF" />
304
+ ) : (
305
+ <Text style={[
306
+ styles.continueButtonText,
307
+ allRequirementsMet && styles.continueButtonTextActive
308
+ ]}>
309
+ Continue
310
+ </Text>
311
+ )}
312
+ </TouchableOpacity>
313
+ </View>
314
+ </View>
315
+ );
316
+ };
317
+
318
+ const styles = StyleSheet.create({
319
+ container: {
320
+ flex: 1,
321
+ backgroundColor: COLORS.surface,
322
+ paddingHorizontal: 24,
323
+ paddingTop: 0,
324
+ },
325
+
326
+ titleContainer: {
327
+ alignItems: 'center',
328
+ marginBottom: 15,
329
+ paddingTop: -10,
330
+ marginTop: -15,
331
+ },
332
+
333
+ title: {
334
+ fontSize: 24,
335
+ fontWeight: '700',
336
+ color: COLORS.grey800,
337
+ marginBottom: 8,
338
+ fontFamily: 'IBM Plex Sans',
339
+ },
340
+
341
+ subtitle: {
342
+ fontSize: 16,
343
+ color: COLORS.grey600,
344
+ lineHeight: 24,
345
+ fontFamily: 'Inter',
346
+ },
347
+
348
+ pinContainer: {
349
+ marginBottom: 32,
350
+ },
351
+
352
+ pinInput: {
353
+ backgroundColor: '#F8F9FA',
354
+ borderRadius: 12,
355
+ paddingVertical: 16,
356
+ paddingHorizontal: 16,
357
+ fontSize: 16,
358
+ fontFamily: 'Inter',
359
+ borderWidth: 1,
360
+ borderColor: '#E5E5E5',
361
+ },
362
+
363
+ requirementsContainer: {
364
+ marginBottom: 32,
365
+ },
366
+
367
+ requirementsTitle: {
368
+ fontSize: 16,
369
+ fontWeight: '600',
370
+ color: COLORS.grey800,
371
+ marginBottom: 16,
372
+ fontFamily: 'Inter',
373
+ },
374
+
375
+ requirementItem: {
376
+ flexDirection: 'row',
377
+ alignItems: 'center',
378
+ marginBottom: 12,
379
+ },
380
+
381
+ checkbox: {
382
+ width: 20,
383
+ height: 20,
384
+ borderRadius: 10,
385
+ borderWidth: 2,
386
+ borderColor: '#E5E5E5',
387
+ marginRight: 12,
388
+ alignItems: 'center',
389
+ justifyContent: 'center',
390
+ },
391
+
392
+ checkboxChecked: {
393
+ borderColor: '#4CD964',
394
+ backgroundColor: '#4CD964',
395
+ },
396
+
397
+ checkmark: {
398
+ color: '#FFFFFF',
399
+ fontSize: 12,
400
+ fontWeight: 'bold',
401
+ },
402
+
403
+ requirementText: {
404
+ fontSize: 14,
405
+ color: COLORS.grey600,
406
+ fontFamily: 'Inter',
407
+ flex: 1,
408
+ },
409
+
410
+ requirementTextMet: {
411
+ color: COLORS.grey800,
412
+ },
413
+
414
+ securityCard: {
415
+ backgroundColor: '#F8F9FA',
416
+ borderRadius: 12,
417
+ padding: 16,
418
+ flexDirection: 'row',
419
+ alignItems: 'center',
420
+ marginBottom: 24,
421
+ borderWidth: 1,
422
+ borderColor: '#E5E5E5',
423
+ },
424
+
425
+ securityCardSuccess: {
426
+ backgroundColor: '#F0FDF4',
427
+ borderColor: '#22C55E',
428
+ },
429
+
430
+ securityCardError: {
431
+ backgroundColor: '#FEF2F2',
432
+ borderColor: '#EF4444',
433
+ },
434
+
435
+ securityIconContainer: {
436
+ marginRight: 12,
437
+ },
438
+
439
+ securityIcon: {
440
+ fontSize: 24,
441
+ },
442
+
443
+ securityTextContainer: {
444
+ flex: 1,
445
+ },
446
+
447
+ securityTitle: {
448
+ fontSize: 14,
449
+ fontWeight: '600',
450
+ color: COLORS.grey800,
451
+ marginBottom: 4,
452
+ fontFamily: 'Inter',
453
+ },
454
+
455
+ securityDescription: {
456
+ fontSize: 13,
457
+ color: COLORS.grey600,
458
+ lineHeight: 18,
459
+ fontFamily: 'Inter',
460
+ },
461
+
462
+ buttonContainer: {
463
+ marginTop: 'auto',
464
+ paddingBottom: 34,
465
+ },
466
+
467
+ continueButton: {
468
+ backgroundColor: '#E5E5E5',
469
+ borderRadius: 25,
470
+ paddingVertical: 16,
471
+ alignItems: 'center',
472
+ justifyContent: 'center',
473
+ },
474
+
475
+ continueButtonActive: {
476
+ backgroundColor: '#2D3436',
477
+ },
478
+
479
+ continueButtonText: {
480
+ fontSize: 16,
481
+ fontWeight: '600',
482
+ color: '#999999',
483
+ fontFamily: 'Inter',
484
+ },
485
+
486
+ continueButtonTextActive: {
487
+ color: '#FFFFFF',
488
+ },
489
+ });
490
+
491
+ export { PinCreationScreen };
492
+ export default PinCreationScreen;