-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathApp.tsx
More file actions
179 lines (162 loc) · 5.12 KB
/
App.tsx
File metadata and controls
179 lines (162 loc) · 5.12 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
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable react-native/no-inline-styles */
import 'react-native-screens';
import {enableScreens} from 'react-native-screens';
import {StatusBar, NativeModules, Platform} from 'react-native';
import React, {useEffect} from 'react';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import CreateRootNavigator from './src/index';
import {StateProvider} from './src/services/State/State.js';
import {initialState} from './src/services/State/InitialState.js';
import {reducer, actions} from './src/services/State/Reducer.js';
import {useStateValue} from './src/services/State/State.js';
import {theme} from './src/services/Common/theme.js';
import PollingService from './src/services/PollingService';
import ReportDeliveryNotificationService from './src/services/ReportDeliveryNotificationService';
import ShareToCleanAppService from './src/services/ShareToCleanAppService';
import {
getLanguage,
getUserInfo,
getDataUsageFlag,
isPrivacyAndTermsAccepted,
getCacheVault,
getMapLocation,
getPlayers,
getGuilds,
} from './src/services/DataManager.js';
import {store} from './src/store/store.js';
import {Provider} from 'react-redux';
// import {persistStore} from 'redux-persist';
import i18next from 'i18next';
import {I18nextProvider} from 'react-i18next';
import {MenuProvider} from 'react-native-popup-menu';
import {ethers} from 'ethers';
import SplashScreen from 'react-native-splash-screen';
enableScreens();
const RootNavigator = () => {
useEffect(() => {
checkLanguage();
checkStatus();
checkDataUsageSettings();
checkVerifySettings();
checkCacheVault();
checkMapLocation();
checkPlayers();
checkGuilds();
}, []);
const [{progressSettings, alertSettings, fabShow}, dispatch] =
useStateValue();
// Initialize polling service with dispatch
useEffect(() => {
PollingService.setDispatch(dispatch);
PollingService.startPolling();
ReportDeliveryNotificationService.start();
ShareToCleanAppService.start();
// Cleanup when component unmounts
return () => {
PollingService.stopPolling();
ReportDeliveryNotificationService.stop();
ShareToCleanAppService.stop();
};
}, [dispatch]);
const {show = false} = progressSettings || {};
const {settings} = alertSettings || {};
const checkDataUsageSettings = async () => {
let isDataUsageAvailable = await getDataUsageFlag();
dispatch({
type: actions.SET_DATAUSAGE,
dataUsageSettings: isDataUsageAvailable,
});
};
const checkVerifySettings = async () => {
let verifyAvailable = await isPrivacyAndTermsAccepted();
dispatch({
type: actions.SET_VERIFYSETTING,
verifySettings: verifyAvailable,
});
};
const checkLanguage = async () => {
let language = await getLanguage();
if (!language) {
const deviceLanguage =
Platform.OS === 'ios'
? NativeModules.SettingsManager.settings.AppleLocale || //iOS 13
NativeModules.SettingsManager.settings.AppleLanguages[0]
: NativeModules.I18nManager.localeIdentifier;
language = deviceLanguage.split('_')[0];
}
await i18next.changeLanguage(language);
dispatch({
type: actions.SET_LANGUAGE,
selectedLanguage: language,
});
};
const checkStatus = async () => {
try {
const userInfo = await getUserInfo();
if (userInfo && userInfo.id) {
dispatch({
type: actions.SET_USER,
user: userInfo,
});
} else {
dispatch({
type: actions.SET_USER,
user: '',
});
}
} catch (err) {}
};
const checkCacheVault = async () => {
const cacheVault = await getCacheVault();
dispatch({
type: actions.SET_CACHE_VAULT,
cacheVault: cacheVault,
});
};
const checkMapLocation = async () => {
const mapLocation = await getMapLocation();
dispatch({
type: actions.SET_MAP_LOCATION,
mapLocation: mapLocation,
});
};
const checkPlayers = async () => {
const players = await getPlayers();
dispatch({
type: actions.SET_PLAYERS,
players: players,
});
};
const checkGuilds = async () => {
const guilds = await getGuilds();
dispatch({
type: actions.SET_GUILDS,
guilds: guilds,
});
};
return (
<SafeAreaProvider style={{flex: 1, backgroundColor: theme.APP_COLOR_1}}>
<StatusBar barStyle="light-content" backgroundColor={theme.APP_COLOR_1} />
<CreateRootNavigator />
</SafeAreaProvider>
);
};
const App = () => {
const fetcher = ['ethers', {ethers, provider: ethers.getDefaultProvider()}];
useEffect(() => {
SplashScreen.hide();
});
return (
<Provider store={store}>
<StateProvider initialState={initialState} reducer={reducer}>
<MenuProvider>
<I18nextProvider i18n={i18next}>
<RootNavigator />
</I18nextProvider>
</MenuProvider>
</StateProvider>
</Provider>
);
};
export default App;