-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathMainRouter.js
64 lines (57 loc) · 2.12 KB
/
MainRouter.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
import React, { useEffect } from 'react';
import { withRouter } from 'react-router';
import { Route, Switch } from 'react-router-dom';
import { addSearchParamsToUrl, removeSearchParamsFromUrl } from 'src/utils/searchParams';
import { useEvents } from '@libs/wcm/hooks/useEvents';
import { EVENTS } from '@libs/wcm/constants/lifeCycle';
import { SIGNING_METHODS } from '@libs/wcm/constants/permissions';
import routesMap from 'src/routes/routesMap';
import NotFound from '@common/components/NotFound';
import CustomRoute from '@common/components/customRoute';
import RewardsNotification from '@common/components/notification/rewardsNotification';
import routes from 'src/routes/routes';
import styles from './app.css';
const MainRouter = ({ history }) => {
const { events } = useEvents();
const routesList = Object.keys(routes);
const showRequestModal = (modalName, event) => {
removeSearchParamsFromUrl(history, ['modal', 'eventId']);
setTimeout(() => {
addSearchParamsToUrl(history, { modal: modalName, eventId: event.meta.id });
}, 100);
};
useEffect(() => {
const event = events.length && events[events.length - 1];
if (event.name === EVENTS.SESSION_REQUEST) {
const method = event.meta?.params?.request?.method;
if (
method === SIGNING_METHODS.SIGN_MESSAGE.key ||
method === SIGNING_METHODS.SIGN_RAW_MESSAGE.key
) {
showRequestModal('requestSignMessageDialog', event);
} else {
showRequestModal('requestView', event);
}
}
}, [events]);
return (
<div className={`${styles.mainContent} ${styles.mainBox}`}>
<RewardsNotification />
<Switch>
{routesList.map((route) => (
<CustomRoute
key={routes[route].path}
path={routes[route].path}
exact={routes[route].exact}
isPrivate={routes[route].isPrivate}
forbiddenTokens={routes[route].forbiddenTokens}
component={routesMap[route]}
history={history}
/>
))}
<Route path="*" component={NotFound} />
</Switch>
</div>
);
};
export default withRouter(MainRouter);