-
Notifications
You must be signed in to change notification settings - Fork 5
/
App.js
126 lines (112 loc) · 3.5 KB
/
App.js
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
import '@/config/logs';
import '@/config/i18n';
import '@/config/reactotron';
import '@/config/extensions';
import * as Sentry from '@sentry/react-native';
import React, { useEffect, useRef, useState } from 'react';
import { AppState, Platform, StatusBar } from 'react-native';
import RNBootSplash from 'react-native-bootsplash';
import codePush from 'react-native-code-push';
import Config from 'react-native-config';
import {
getBuildNumber,
getBundleId,
getVersion,
} from 'react-native-device-info';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { ToastProvider } from 'react-native-toast-notifications';
import { Provider } from 'react-redux';
import Reactotron from 'reactotron-react-native';
import { PersistGate } from 'redux-persist/integration/react';
import { ErrorBoundary } from '@/components/common';
import { toastProviderProps } from '@/components/common/Toast';
import { isIos } from '@/constants/platform';
import Routes from '@/navigation';
import { useAppDispatch } from '@/redux/hooks';
import { initKeyring } from '@/redux/slices/keyring';
import { persistor, store } from '@/redux/store';
import { navigationRef } from '@/utils/navigation';
const routingInstrumentation = new Sentry.ReactNavigationInstrumentation();
const baseDist = getBuildNumber();
const baseRelease = `${getBundleId()}@${getVersion()}:${Platform.OS}`;
Sentry.init({
dsn: Config.SENTRY_DSN,
tracesSampleRate: 1.0,
dist: baseDist,
debug: false,
release: baseRelease,
environment: __DEV__ ? 'local' : 'productive',
normalizeDepth: 10,
enableOutOfMemoryTracking: false,
integrations: [
new Sentry.ReactNativeTracing({
routingInstrumentation,
}),
],
});
const PersistedApp = () => {
const appState = useRef(AppState.currentState);
const [showRoutes, setShowRoutes] = useState(false);
const dispatch = useAppDispatch();
useEffect(() => {
const event = AppState.addEventListener('change', handleAppStateChange);
return () => {
event.remove();
};
}, []);
const checkUpdates = async () => {
await codePush.sync({
installMode: codePush.InstallMode.IMMEDIATE,
deploymentKey: isIos
? Config.CODE_PUSH_IOS_DEPLOY_KEY
: Config.CODE_PUSH_ANDROID_DEPLOY_KEY,
});
};
const handleAppStateChange = nextAppState => {
if (nextAppState === 'background') {
checkUpdates();
}
if (appState.current !== nextAppState) {
appState.current = nextAppState;
}
};
useEffect(() => {
dispatch(
initKeyring({
callback: () => {
RNBootSplash.hide({ fade: true });
setShowRoutes(true);
},
})
);
}, []);
return (
<PersistGate loading={null} persistor={persistor}>
<ErrorBoundary>
<SafeAreaProvider>
<ToastProvider {...toastProviderProps}>
<StatusBar barStyle="light-content" backgroundColor="black" />
{showRoutes && (
<Routes
routingInstrumentation={routingInstrumentation}
ref={navigationRef}
/>
)}
</ToastProvider>
</SafeAreaProvider>
</ErrorBoundary>
</PersistGate>
);
};
const App = () => (
<Provider store={store}>
<PersistedApp />
</Provider>
);
const AppWithSentry = Sentry.wrap(__DEV__ ? Reactotron.overlay(App) : App);
export default codePush({
checkfrecuency: codePush.CheckFrequency.MANUAL,
deploymentKey: isIos
? Config.CODE_PUSH_IOS_DEPLOY_KEY
: Config.CODE_PUSH_ANDROID_DEPLOY_KEY,
})(AppWithSentry);