-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.jsx
89 lines (78 loc) · 3.2 KB
/
App.jsx
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
/*
Monitoring Center
Copyright (C) 2021 Atheesh Thirumalairajan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* eslint-disable react/style-prop-object */
/* eslint-disable react/jsx-no-bind */
import React from 'react';
import { Provider as PaperProvider } from 'react-native-paper';
import { NativeBaseProvider } from 'native-base';
import { StatusBar } from 'expo-status-bar';
import axios from 'axios';
import ApplicationInterface from './appsource/screens/ApplicationInterface';
import {
navigationTheme, monitoringTheme, monitoringProTheme, navigationProTheme,
} from './appsource/themes/bubblegum';
import DonationModal from './appsource/components/DonationModal';
import { fetchMiscKey, setMiscKey } from './appsource/controllers/StorageController';
import prodKeys from './appsource/controllers/ProductionController';
export default function App() {
const [donationLevel, setDonationLevel] = React.useState();
const DonationModalReference = React.useRef();
function handleDonationModalRequest() {
DonationModalReference.current.requestModalVisibility();
}
function InitializeApplication() {
/* Seamless Switch */
fetchMiscKey('@dlevel', (dLevel) => {
if (dLevel != null) setDonationLevel(+dLevel);
});
fetchMiscKey('@patreonData', (patreonData) => {
if (patreonData != null) {
// eslint-disable-next-line no-param-reassign
patreonData = JSON.parse(patreonData);
axios.post(
`${prodKeys.donationServer}/oauth/monitoring-center/license-status`,
{ userId: patreonData.userId },
).then((licenseStatus) => {
setMiscKey('@dlevel', licenseStatus.data.dLevel.toString(), () => {
setDonationLevel(licenseStatus.data.dLevel);
});
}).catch((error) => {
console.error(error);
});
} else {
setMiscKey('@dlevel', '0', () => {
setDonationLevel(0);
});
}
});
}
InitializeApplication();
return (
<NativeBaseProvider>
<PaperProvider theme={donationLevel > 1 ? monitoringProTheme : monitoringTheme}>
<ApplicationInterface
donationLevel={donationLevel}
donationModalRequest={handleDonationModalRequest}
navigationtheme={donationLevel > 1 ? navigationProTheme : navigationTheme}
/>
{/* Universal Modals */}
<DonationModal
ref={DonationModalReference}
/>
</PaperProvider>
<StatusBar style="auto" backgroundColor={donationLevel > 1 ? monitoringProTheme.colors.primary : monitoringTheme.colors.primary} translucent={false} />
</NativeBaseProvider>
);
}