-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_layout.tsx
More file actions
422 lines (377 loc) · 13.9 KB
/
Copy path_layout.tsx
File metadata and controls
422 lines (377 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
import '@/global.css';
import { useCallback, useEffect, useState } from 'react';
import { Appearance, AppState, Platform } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import Toast from 'react-native-toast-message';
import * as Font from 'expo-font';
import * as Notifications from 'expo-notifications';
import { Stack, useGlobalSearchParams, usePathname } from 'expo-router';
import Head from 'expo-router/head';
import * as SplashScreen from 'expo-splash-screen';
import { ApolloProvider } from '@apollo/client/react';
import {
MonaSans_200ExtraLight,
MonaSans_300Light,
MonaSans_400Regular,
MonaSans_500Medium,
MonaSans_600SemiBold,
MonaSans_700Bold,
MonaSans_800ExtraBold,
MonaSans_900Black,
useFonts,
} from '@expo-google-fonts/mona-sans';
import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
import NetInfo from '@react-native-community/netinfo';
import { PortalHost } from '@rn-primitives/portal';
import * as Sentry from '@sentry/react-native';
import {
focusManager,
onlineManager,
QueryClient,
QueryClientProvider,
} from '@tanstack/react-query';
import { injectSpeedInsights } from '@vercel/speed-insights';
import { WagmiProvider } from 'wagmi';
import DeferredModalProviders from '@/components/DeferredModalProviders';
import AppErrorBoundary from '@/components/ErrorBoundary';
import Intercom from '@/components/Intercom/index';
import { LazyThirdwebProvider } from '@/components/LazyThirdwebProvider';
import LazyWhatsNewModal from '@/components/LazyWhatsNewModal';
import { toastProps } from '@/components/Toast';
import { TurnkeyProvider } from '@/components/TurnkeyProvider';
import { getInfoClient } from '@/graphql/clients';
import { useAttributionInitialization } from '@/hooks/useAttributionInitialization';
import { usePushNotifications } from '@/hooks/usePushNotifications';
import { useTrackingTransparency } from '@/hooks/useTrackingTransparency';
import { useWhatsNew } from '@/hooks/useWhatsNew';
import { initAnalytics, track, trackScreen } from '@/lib/analytics';
import { EXPO_PUBLIC_ENVIRONMENT, isProduction } from '@/lib/config';
import { config } from '@/lib/wagmi';
import { useUserStore } from '@/store/useUserStore';
import type { ErrorBoundaryProps } from 'expo-router';
Sentry.init({
dsn: 'https://8e2914f77c8a188a9938a9eaa0ffc0ba@o4509954049376256.ingest.us.sentry.io/4509954077949952',
enabled: isProduction && !__DEV__,
environment: EXPO_PUBLIC_ENVIRONMENT || 'development',
debug: !isProduction,
sendDefaultPii: true,
// Performance Monitoring - configured upfront, integrations added later
tracesSampleRate: 0.5,
profilesSampleRate: 0.5,
// Release Health
enableAutoSessionTracking: true,
sessionTrackingIntervalMillis: 30000,
// Error Filtering
ignoreErrors: [
'Network request failed',
'NetworkError',
'Failed to fetch',
'AbortError',
'Non-serializable values were found in the navigation state',
],
// Breadcrumbs
maxBreadcrumbs: 100,
beforeBreadcrumb(breadcrumb) {
if (breadcrumb.category === 'console' && breadcrumb.level === 'debug') {
return null;
}
return breadcrumb;
},
beforeSend(event) {
if (event.environment !== 'production') {
return null;
}
if (event.request?.cookies) {
delete event.request.cookies;
}
return event;
},
// Configure Session Replay - rates set upfront, integration added later
replaysSessionSampleRate: 0.5,
replaysOnErrorSampleRate: 1,
// Integrations
integrations: [
Sentry.mobileReplayIntegration({
maskAllText: false, // Set to true if you want to mask sensitive text
maskAllImages: false, // Set to true to mask images
}),
Sentry.feedbackIntegration(),
Sentry.reactNativeTracingIntegration(),
Sentry.reactNavigationIntegration({
routeChangeTimeoutMs: 50,
}),
],
// Attachments
attachScreenshot: true,
attachViewHierarchy: true,
// Network tracking
// tracePropagationTargets: [/^https:\/\/app\.solid\.xyz/],
});
export function ErrorBoundary(props: ErrorBoundaryProps) {
return <AppErrorBoundary {...props} />;
}
if (Platform.OS !== 'web') {
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
shouldShowBanner: true,
shouldShowList: true,
}),
});
}
// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync();
// Set the animation options - instant hide, no fade
SplashScreen.setOptions({
duration: 0,
fade: false,
});
// WhatsNew wrapper component - must be inside QueryClientProvider
// since useWhatsNew uses React Query hooks.
// Note: Only rendered when hasSelectedUser is true (see conditional render below)
// Uses LazyWhatsNewModal to defer react-native-reanimated-carousel bundle
function WhatsNewWrapper() {
const { whatsNew, isVisible, closeWhatsNew } = useWhatsNew();
if (!whatsNew) return null;
return <LazyWhatsNewModal whatsNew={whatsNew} isOpen={isVisible} onClose={closeWhatsNew} />;
}
// On native, React Query's focus and online managers have no default wiring:
// `refetchOnWindowFocus` listens to `visibilitychange` (web-only) and
// `refetchOnReconnect` has no transport to detect connectivity. Without this
// bridge, a query with `refetchOnWindowFocus: true` (e.g. tokenBalances)
// never fires when the app returns from background, and queries don't recover
// after a network drop. Wire AppState → focusManager and NetInfo → onlineManager.
if (Platform.OS !== 'web') {
focusManager.setEventListener(handleFocus => {
const subscription = AppState.addEventListener('change', status => {
handleFocus(status === 'active');
});
return () => subscription.remove();
});
onlineManager.setEventListener(setOnline => {
return NetInfo.addEventListener(state => {
setOnline(!!state.isConnected);
});
});
}
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
staleTime: 5 * 60 * 1000, // 5 minutes - data considered fresh
gcTime: 10 * 60 * 1000, // 10 minutes - garbage collect unused queries
retry: 2,
},
},
});
export default Sentry.wrap(function RootLayout() {
const [appIsReady, setAppIsReady] = useState(false);
const [splashScreenHidden, setSplashScreenHidden] = useState(false);
const hasSelectedUser = useUserStore(state => state.users.some(u => u.selected));
// Initialize attribution tracking automatically (handles web and mobile)
useAttributionInitialization();
// Push notification lifecycle: token refresh + notification tap handling
usePushNotifications();
// App Tracking Transparency (iOS only)
const {
isReady: attReady,
hasChecked: attChecked,
isTrackingAllowed,
status: attStatus,
requestPermission,
} = useTrackingTransparency();
useEffect(() => {
if (!splashScreenHidden) return;
if (Platform.OS === 'ios' && !attReady) return;
initAnalytics(isTrackingAllowed).catch(e => console.warn('Analytics init error:', e));
}, [splashScreenHidden, attReady, isTrackingAllowed]);
useEffect(() => {
if (!splashScreenHidden || !attChecked) return;
if (Platform.OS !== 'ios' || attStatus !== 'undetermined') return;
const timer = setTimeout(async () => {
const granted = await requestPermission();
track('ATT_Response', { status: granted ? 'granted' : 'denied' });
}, 5000);
return () => clearTimeout(timer);
}, [splashScreenHidden, attChecked, attStatus, requestPermission]);
// Load only critical font weights to speed up FCP
// Regular (400) and SemiBold (600) cover most UI text
const [criticalFontsLoaded, fontError] = useFonts({
MonaSans_400Regular,
MonaSans_600SemiBold,
});
// Load remaining font weights after first paint (deferred)
useEffect(() => {
if (criticalFontsLoaded) {
// Defer non-critical font loading to not block render
Font.loadAsync({
MonaSans_200ExtraLight,
MonaSans_300Light,
MonaSans_500Medium,
MonaSans_700Bold,
MonaSans_800ExtraBold,
MonaSans_900Black,
}).catch(e => console.warn('Error loading secondary fonts:', e));
}
}, [criticalFontsLoaded]);
const pathname = usePathname();
const params = useGlobalSearchParams();
useEffect(() => {
// Only run on Web and only in production
if (Platform.OS === 'web' && isProduction) {
injectSpeedInsights();
}
}, []);
useEffect(() => {
async function prepare() {
try {
// Pre-load fonts, make any API calls you need to do here
// await Font.loadAsync(Entypo.font);
if (Platform.OS !== 'web') {
Appearance.setColorScheme('dark');
}
// Add any additional initialization here
// await initializeApp();
} catch (e) {
console.warn('Error during app initialization:', e);
} finally {
// Tell the application to render
setAppIsReady(true);
}
}
prepare();
}, []);
const onLayoutRootView = useCallback(async () => {
if (appIsReady && !splashScreenHidden) {
// This tells the splash screen to hide immediately! If we call this after
// `setAppIsReady`, then we may see a blank screen while the app is
// loading its initial state and rendering its first pixels. So instead,
// we hide the splash screen once we know the root view has already
// performed layout.
try {
await SplashScreen.hideAsync();
setSplashScreenHidden(true);
} catch (error) {
console.warn('Error hiding splash screen:', error);
}
}
}, [appIsReady, splashScreenHidden]);
// Track screen views on all platforms (web, iOS, Android)
// trackScreen() handles platform-specific routing internally:
// - Amplitude: tracks on all platforms
// - Firebase: tracks on web only
useEffect(() => {
trackScreen(pathname, params);
}, [pathname, params]);
useEffect(() => {
if (fontError) {
console.error('Error loading fonts:', fontError);
}
}, [fontError]);
if (!appIsReady || !criticalFontsLoaded) {
return null;
}
return (
<SafeAreaProvider style={{ flex: 1 }} onLayout={onLayoutRootView}>
<TurnkeyProvider>
<LazyThirdwebProvider>
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<ApolloProvider client={getInfoClient()}>
<Intercom>
<GestureHandlerRootView style={{ flex: 1 }}>
<BottomSheetModalProvider>
{Platform.OS === 'web' && (
<Head>
<title>Solid - The Savings Super-App</title>
</Head>
)}
<Stack
screenOptions={{
contentStyle: {
backgroundColor: '#000',
},
}}
>
<Stack.Screen
name="(protected)"
options={{
headerShown: false,
animation: 'none',
}}
/>
<Stack.Screen
name="overview"
options={{
headerShown: false,
animation: 'none',
}}
/>
<Stack.Screen
name="card-onboard"
options={{
headerShown: false,
animation: 'none',
}}
/>
<Stack.Screen
name="welcome"
options={{
headerShown: false,
animation: 'none',
}}
/>
<Stack.Screen
name="notifications"
options={{
headerShown: false,
animation: 'none',
}}
/>
<Stack.Screen
name="passkey-not-supported"
options={{
headerShown: false,
animation: 'none',
}}
/>
<Stack.Screen
name="onboarding"
options={{
headerShown: false,
animation: 'none',
}}
/>
<Stack.Screen
name="signup"
options={{
headerShown: false,
animation: 'none',
}}
/>
<Stack.Screen
name="recovery"
options={{
headerShown: false,
animation: 'none',
}}
/>
</Stack>
<PortalHost />
<DeferredModalProviders />
{hasSelectedUser && <WhatsNewWrapper />}
</BottomSheetModalProvider>
</GestureHandlerRootView>
</Intercom>
</ApolloProvider>
</QueryClientProvider>
</WagmiProvider>
</LazyThirdwebProvider>
<Toast {...toastProps} />
</TurnkeyProvider>
</SafeAreaProvider>
);
});