@onairos/react-native 3.1.16 → 3.1.17

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 (198) 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/OnairosButton.js +290 -0
  16. package/lib/commonjs/components/OnairosButton.js.map +1 -0
  17. package/lib/commonjs/components/OnairosSignInButton.js +30 -8
  18. package/lib/commonjs/components/OnairosSignInButton.js.map +1 -1
  19. package/lib/commonjs/components/UniversalOnboarding.js +4 -4
  20. package/lib/commonjs/config/api.js +2 -2
  21. package/lib/commonjs/hooks/useConnections.js +6 -6
  22. package/lib/commonjs/hooks/useUserConnections.js +10 -10
  23. package/lib/commonjs/index.js +9 -10
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/services/apiClient.js +35 -35
  26. package/lib/commonjs/services/apiKeyService.js +99 -99
  27. package/lib/commonjs/services/authService.js +82 -82
  28. package/lib/commonjs/services/biometricPinService.js +10 -10
  29. package/lib/commonjs/services/connectedAccountsService.js +32 -32
  30. package/lib/commonjs/services/googleAuthService.js +15 -15
  31. package/lib/commonjs/services/imageCompressionService.js +15 -15
  32. package/lib/commonjs/services/jwtStorageService.js +59 -59
  33. package/lib/commonjs/services/mobileTrainingService.js +14 -14
  34. package/lib/commonjs/services/pinEncryptionService.js +10 -10
  35. package/lib/commonjs/services/pinStorageUtils.js +15 -15
  36. package/lib/commonjs/services/platformAuthService.js +47 -47
  37. package/lib/commonjs/services/storageService.js +31 -31
  38. package/lib/commonjs/services/trainingApiHelpers.js +33 -33
  39. package/lib/commonjs/services/userConnectionsService.js +24 -24
  40. package/lib/commonjs/utils/Portal.js +4 -4
  41. package/lib/commonjs/utils/api.js +24 -24
  42. package/lib/commonjs/utils/auth.js +18 -18
  43. package/lib/commonjs/utils/crypto.js +13 -13
  44. package/lib/commonjs/utils/encryption.js +12 -12
  45. package/lib/commonjs/utils/eventUtils.js +52 -52
  46. package/lib/commonjs/utils/programmaticFlow.js +16 -16
  47. package/lib/commonjs/utils/retryHelper.js +27 -27
  48. package/lib/module/assets/images/Checkbox.svg +3 -3
  49. package/lib/module/assets/images/EnochE.svg +19 -19
  50. package/lib/module/assets/images/Personalityprofile.svg +3 -3
  51. package/lib/module/assets/images/Personalitytraits.svg +3 -3
  52. package/lib/module/assets/images/Userpreferences.svg +3 -3
  53. package/lib/module/assets/images/arrow.svg +20 -20
  54. package/lib/module/assets/images/basicproficon.svg +43 -43
  55. package/lib/module/assets/images/basicprofile.svg +3 -3
  56. package/lib/module/assets/images/checkmark.svg +4 -4
  57. package/lib/module/assets/images/contentanalysis.svg +3 -3
  58. package/lib/module/assets/images/contenticon.svg +23 -23
  59. package/lib/module/assets/images/personalityicon.svg +18 -18
  60. package/lib/module/assets/images/x-close.svg +3 -3
  61. package/lib/module/components/OnairosButton.js +282 -0
  62. package/lib/module/components/OnairosButton.js.map +1 -0
  63. package/lib/module/components/OnairosSignInButton.js +30 -8
  64. package/lib/module/components/OnairosSignInButton.js.map +1 -1
  65. package/lib/module/components/UniversalOnboarding.js +4 -4
  66. package/lib/module/config/api.js +2 -2
  67. package/lib/module/hooks/useConnections.js +6 -6
  68. package/lib/module/hooks/useUserConnections.js +10 -10
  69. package/lib/module/index.js +8 -10
  70. package/lib/module/index.js.map +1 -1
  71. package/lib/module/services/apiClient.js +35 -35
  72. package/lib/module/services/apiKeyService.js +99 -99
  73. package/lib/module/services/authService.js +82 -82
  74. package/lib/module/services/biometricPinService.js +10 -10
  75. package/lib/module/services/connectedAccountsService.js +32 -32
  76. package/lib/module/services/googleAuthService.js +15 -15
  77. package/lib/module/services/imageCompressionService.js +15 -15
  78. package/lib/module/services/jwtStorageService.js +59 -59
  79. package/lib/module/services/mobileTrainingService.js +14 -14
  80. package/lib/module/services/pinEncryptionService.js +10 -10
  81. package/lib/module/services/pinStorageUtils.js +15 -15
  82. package/lib/module/services/platformAuthService.js +47 -47
  83. package/lib/module/services/storageService.js +31 -31
  84. package/lib/module/services/trainingApiHelpers.js +33 -33
  85. package/lib/module/services/userConnectionsService.js +24 -24
  86. package/lib/module/utils/Portal.js +4 -4
  87. package/lib/module/utils/api.js +24 -24
  88. package/lib/module/utils/auth.js +18 -18
  89. package/lib/module/utils/crypto.js +13 -13
  90. package/lib/module/utils/encryption.js +12 -12
  91. package/lib/module/utils/eventUtils.js +52 -52
  92. package/lib/module/utils/programmaticFlow.js +16 -16
  93. package/lib/module/utils/retryHelper.js +27 -27
  94. package/lib/typescript/components/OnairosButton.d.ts +37 -0
  95. package/lib/typescript/components/OnairosButton.d.ts.map +1 -0
  96. package/lib/typescript/components/OnairosSignInButton.d.ts +2 -1
  97. package/lib/typescript/components/OnairosSignInButton.d.ts.map +1 -1
  98. package/lib/typescript/index.d.ts +3 -4
  99. package/lib/typescript/index.d.ts.map +1 -1
  100. package/package.json +163 -163
  101. package/src/api/index.ts +151 -151
  102. package/src/assets/images/Checkbox.svg +3 -3
  103. package/src/assets/images/EnochE.svg +19 -19
  104. package/src/assets/images/Personalityprofile.svg +3 -3
  105. package/src/assets/images/Personalitytraits.svg +3 -3
  106. package/src/assets/images/Userpreferences.svg +3 -3
  107. package/src/assets/images/arrow.svg +20 -20
  108. package/src/assets/images/basicproficon.svg +43 -43
  109. package/src/assets/images/basicprofile.svg +3 -3
  110. package/src/assets/images/checkmark.svg +4 -4
  111. package/src/assets/images/contentanalysis.svg +3 -3
  112. package/src/assets/images/contenticon.svg +23 -23
  113. package/src/assets/images/personalityicon.svg +18 -18
  114. package/src/assets/images/x-close.svg +3 -3
  115. package/src/components/BodyText.tsx +33 -33
  116. package/src/components/BrandMark.tsx +62 -62
  117. package/src/components/CodeInput.tsx +32 -32
  118. package/src/components/DataRequestScreen.tsx +355 -355
  119. package/src/components/EmailInput.tsx +31 -31
  120. package/src/components/EmailVerificationModal.tsx +363 -363
  121. package/src/components/ExistingUserDataConfirmation.tsx +506 -506
  122. package/src/components/GoogleButton.tsx +55 -55
  123. package/src/components/HeadingGroup.tsx +49 -49
  124. package/src/components/ModalHeader.tsx +125 -125
  125. package/src/components/ModalSheet.tsx +57 -57
  126. package/src/components/Onairos.tsx +422 -422
  127. package/src/components/OnairosButton.tsx +339 -0
  128. package/src/components/OnairosSignInButton.tsx +30 -10
  129. package/src/components/Overlay.tsx +506 -506
  130. package/src/components/PersonaImage.tsx +79 -79
  131. package/src/components/PersonaLoadingScreen.tsx +201 -201
  132. package/src/components/PersonalizationConsentScreen.tsx +410 -410
  133. package/src/components/PinCreationScreen.tsx +492 -492
  134. package/src/components/PinInput.tsx +555 -555
  135. package/src/components/PlatformConnectorsStep.tsx +891 -891
  136. package/src/components/PlatformList.tsx +144 -144
  137. package/src/components/PlatformToggle.tsx +226 -226
  138. package/src/components/PrimaryButton.tsx +213 -213
  139. package/src/components/SignInMatchAnimation.tsx +225 -225
  140. package/src/components/SignInStep.tsx +217 -217
  141. package/src/components/TrainingModal.tsx +1047 -1047
  142. package/src/components/UniversalOnboarding.tsx +2887 -2887
  143. package/src/components/VerificationStep.tsx +198 -198
  144. package/src/components/WelcomeScreen.tsx +473 -473
  145. package/src/components/icons/Basicproficon.tsx +30 -30
  146. package/src/components/icons/Basicprofile.tsx +17 -17
  147. package/src/components/icons/Checkbox.tsx +17 -17
  148. package/src/components/icons/Checkmark.tsx +24 -24
  149. package/src/components/icons/Contentanalysis.tsx +17 -17
  150. package/src/components/icons/Contenticon.tsx +30 -30
  151. package/src/components/icons/EnochE.tsx +39 -39
  152. package/src/components/icons/Personalityicon.tsx +22 -22
  153. package/src/components/icons/Personalityprofile.tsx +17 -17
  154. package/src/components/icons/Personalitytraits.tsx +17 -17
  155. package/src/components/icons/Userpreferences.tsx +17 -17
  156. package/src/components/icons/index.ts +12 -12
  157. package/src/components/onboarding/OAuthWebView.tsx +232 -232
  158. package/src/config/api.ts +25 -25
  159. package/src/context/AuthContext.tsx +393 -393
  160. package/src/hooks/useConnectedAccounts.ts +138 -138
  161. package/src/hooks/useConnections.ts +161 -161
  162. package/src/hooks/useCredentials.ts +174 -174
  163. package/src/hooks/useUserConnections.ts +165 -165
  164. package/src/index.js +14 -0
  165. package/src/index.ts +94 -96
  166. package/src/services/apiClient.ts +336 -336
  167. package/src/services/apiKeyService.ts +919 -919
  168. package/src/services/authService.ts +1008 -1008
  169. package/src/services/biometricPinService.ts +192 -192
  170. package/src/services/connectedAccountsService.ts +289 -289
  171. package/src/services/googleAuthService.ts +279 -279
  172. package/src/services/imageCompressionService.ts +302 -302
  173. package/src/services/jwtStorageService.ts +256 -256
  174. package/src/services/mobileTrainingService.ts +203 -203
  175. package/src/services/pinEncryptionService.ts +75 -75
  176. package/src/services/pinStorageUtils.ts +96 -96
  177. package/src/services/platformAuthService.ts +1346 -1346
  178. package/src/services/storageService.ts +451 -451
  179. package/src/services/trainingApiHelpers.ts +66 -66
  180. package/src/services/userConnectionsService.ts +556 -556
  181. package/src/services/youtubeMigrationService.ts +453 -453
  182. package/src/theme/index.ts +239 -239
  183. package/src/types/ambient.d.ts +28 -28
  184. package/src/types/index.ts +265 -265
  185. package/src/types/node-fix.d.ts +18 -18
  186. package/src/types/node-override.d.ts +23 -23
  187. package/src/types/opacity.d.ts +15 -15
  188. package/src/types/types.d.ts +17 -17
  189. package/src/utils/Portal.tsx +82 -82
  190. package/src/utils/api.js +111 -111
  191. package/src/utils/auth.js +103 -103
  192. package/src/utils/crypto.js +59 -59
  193. package/src/utils/encryption.ts +68 -68
  194. package/src/utils/eventUtils.ts +302 -302
  195. package/src/utils/haptics.ts +58 -58
  196. package/src/utils/imagePreloader.ts +2 -2
  197. package/src/utils/programmaticFlow.ts +112 -112
  198. 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;