2024-10-23 19:11:06 -04:00
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
|
import { useDispatch } from "react-redux";
|
2024-07-19 10:40:40 -07:00
|
|
|
import "react-toastify/dist/ReactToastify.css";
|
|
|
|
|
import { ToastContainer } from "react-toastify";
|
2024-08-28 22:14:55 -04:00
|
|
|
import { ThemeProvider } from "@emotion/react";
|
2024-08-29 17:14:17 -04:00
|
|
|
import lightTheme from "./Utils/Theme/lightTheme";
|
|
|
|
|
import darkTheme from "./Utils/Theme/darkTheme";
|
2024-11-09 08:01:14 -05:00
|
|
|
import { CssBaseline, GlobalStyles } from "@mui/material";
|
2024-10-31 14:49:26 -04:00
|
|
|
import { getAppSettings } from "./Features/Settings/settingsSlice";
|
2024-09-27 12:13:39 +08:00
|
|
|
import { logger } from "./Utils/Logger"; // Import the logger
|
|
|
|
|
import { networkService } from "./main";
|
2024-12-12 00:09:41 -05:00
|
|
|
import { Routes } from "./Routes";
|
2025-02-12 10:23:55 -08:00
|
|
|
import WalletProvider from "./Components/WalletProvider";
|
2025-03-02 02:43:53 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
import { setLanguage } from "./Features/UI/uiSlice";
|
2024-12-12 00:09:41 -05:00
|
|
|
|
2024-05-03 12:29:37 -04:00
|
|
|
function App() {
|
2024-10-17 12:05:06 +08:00
|
|
|
const mode = useSelector((state) => state.ui.mode);
|
|
|
|
|
const { authToken } = useSelector((state) => state.auth);
|
|
|
|
|
const dispatch = useDispatch();
|
2025-03-02 02:43:53 +03:00
|
|
|
const { i18n } = useTranslation();
|
2024-09-27 10:55:37 +08:00
|
|
|
|
2024-10-17 12:05:06 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (authToken) {
|
2025-03-02 02:43:53 +03:00
|
|
|
dispatch(getAppSettings({ authToken })).then((action) => {
|
|
|
|
|
if (action.payload && action.payload.success) {
|
2025-04-04 01:02:26 +03:00
|
|
|
const { language } = action.payload.data;
|
|
|
|
|
const availableLanguages = Object.keys(i18n.options.resources || {});
|
|
|
|
|
if (language && availableLanguages.includes(language)) {
|
2025-03-02 02:43:53 +03:00
|
|
|
dispatch(setLanguage(language));
|
|
|
|
|
i18n.changeLanguage(language);
|
2025-04-04 01:02:26 +03:00
|
|
|
} else {
|
|
|
|
|
dispatch(setLanguage(availableLanguages[0]));
|
|
|
|
|
i18n.changeLanguage(availableLanguages[0]);
|
2025-03-02 02:43:53 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-10-17 12:05:06 +08:00
|
|
|
}
|
2025-03-02 02:43:53 +03:00
|
|
|
}, [dispatch, authToken, i18n]);
|
2024-08-28 22:14:55 -04:00
|
|
|
|
2024-10-17 12:05:06 +08:00
|
|
|
// Cleanup
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
return () => {
|
|
|
|
|
logger.cleanup();
|
|
|
|
|
networkService.cleanup();
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
2024-09-27 12:13:39 +08:00
|
|
|
|
2024-10-17 12:05:06 +08:00
|
|
|
return (
|
2024-11-09 08:01:14 -05:00
|
|
|
/* Extract Themeprovider, baseline and global styles to Styles */
|
2024-10-17 12:05:06 +08:00
|
|
|
<ThemeProvider theme={mode === "light" ? lightTheme : darkTheme}>
|
2025-02-12 10:23:55 -08:00
|
|
|
<WalletProvider>
|
|
|
|
|
<CssBaseline />
|
|
|
|
|
<GlobalStyles
|
|
|
|
|
styles={({ palette }) => {
|
|
|
|
|
return {
|
|
|
|
|
body: {
|
|
|
|
|
backgroundImage: `radial-gradient(circle, ${palette.gradient.color1}, ${palette.gradient.color2}, ${palette.gradient.color3}, ${palette.gradient.color4}, ${palette.gradient.color5})`,
|
|
|
|
|
color: palette.primary.contrastText,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Routes />
|
|
|
|
|
<ToastContainer />
|
|
|
|
|
</WalletProvider>
|
2024-10-17 12:05:06 +08:00
|
|
|
</ThemeProvider>
|
|
|
|
|
);
|
2024-05-03 12:29:37 -04:00
|
|
|
}
|
|
|
|
|
|
2024-05-11 22:48:09 +03:30
|
|
|
export default App;
|