-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path_app.tsx
168 lines (155 loc) · 5.56 KB
/
_app.tsx
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
import '@pancakeswap/ui/css/reset.css'
import { ResetCSS, ScrollToTopButtonV2, ToastListener } from '@pancakeswap/uikit'
import BigNumber from 'bignumber.js'
import { NetworkModal } from 'components/NetworkModal'
import { FixedSubgraphHealthIndicator } from 'components/SubgraphHealthIndicator/FixedSubgraphHealthIndicator'
import TransactionsDetailModal from 'components/TransactionDetailModal'
import { useAccountEventListener } from 'hooks/useAccountEventListener'
import useEagerConnect from 'hooks/useEagerConnect'
import useEagerConnectMP from 'hooks/useEagerConnect.bmp'
import useSentryUser from 'hooks/useSentryUser'
import useThemeCookie from 'hooks/useThemeCookie'
import useUserAgent from 'hooks/useUserAgent'
import { NextPage } from 'next'
import type { AppProps } from 'next/app'
import dynamic from 'next/dynamic'
import Head from 'next/head'
import Script from 'next/script'
import { Fragment } from 'react'
import { DefaultSeo } from 'next-seo'
import { PageMeta } from 'components/Layout/Page'
import { PersistGate } from 'redux-persist/integration/react'
import { persistor, useStore } from 'state'
import { usePollBlockNumber } from 'state/block/hooks'
import { Blocklist, Updaters } from '..'
import { SEO } from '../../next-seo.config'
import { SentryErrorBoundary } from '../components/ErrorBoundary'
import Menu from '../components/Menu'
import Providers from '../Providers'
import GlobalStyle from '../style/Global'
import { BrowserRouter as Router } from 'react-router-dom'
// import "../style/Font.css";
const EasterEgg = dynamic(() => import('components/EasterEgg'), { ssr: false })
// This config is required for number formatting
BigNumber.config({
EXPONENTIAL_AT: 1000,
DECIMAL_PLACES: 80,
})
function GlobalHooks() {
usePollBlockNumber()
useEagerConnect()
useUserAgent()
useAccountEventListener()
useSentryUser()
useThemeCookie()
// useLockedEndNotification()
return null
}
function MPGlobalHooks() {
usePollBlockNumber()
useEagerConnectMP()
useUserAgent()
useAccountEventListener()
useSentryUser()
return null
}
function MyApp(props: AppProps<{ initialReduxState: any }>) {
const { pageProps, Component } = props
const store = useStore(pageProps.initialReduxState)
return (
<>
<Head>
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=5, minimum-scale=1, viewport-fit=cover"
/>
<meta name="description" content="" />
<meta name="theme-color" content="#1FC7D4" />
{(Component as NextPageWithLayout).mp && (
// eslint-disable-next-line @next/next/no-sync-scripts
<script src="https://public.bnbstatic.com/static/js/mp-webview-sdk/webview-v1.0.0.min.js" id="mp-webview" />
)}
<meta name="twitter:image" content="https://melega.finance/main.jpg" />
</Head>
<DefaultSeo {...SEO} />
<Providers store={store}>
<PageMeta />
{(Component as NextPageWithLayout).Meta && (
// @ts-ignore
<Component.Meta {...pageProps} />
)}
<Blocklist>
{(Component as NextPageWithLayout).mp ? <MPGlobalHooks /> : <GlobalHooks />}
<ResetCSS />
<GlobalStyle />
<PersistGate loading={null} persistor={persistor}>
<Updaters />
<Router>
<App {...props} />
</Router>
</PersistGate>
</Blocklist>
</Providers>
<Script
strategy="afterInteractive"
id="google-tag"
dangerouslySetInnerHTML={{
__html: `
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer', '${process.env.NEXT_PUBLIC_GTAG}');
`,
}}
/>
</>
)
}
type NextPageWithLayout = NextPage & {
Layout?: React.FC<React.PropsWithChildren<unknown>>
/** render component without all layouts */
pure?: true
/** is mini program */
mp?: boolean
/**
* allow chain per page, empty array bypass chain block modal
* @default [ChainId.BSC]
* */
chains?: number[]
isShowScrollToTopButton?: true
/**
* Meta component for page, hacky solution for static build page to avoid `PersistGate` which blocks the page from rendering
*/
Meta?: React.FC<React.PropsWithChildren<unknown>>
}
type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout
}
const ProductionErrorBoundary = process.env.NODE_ENV === 'production' ? SentryErrorBoundary : Fragment
const App = ({ Component, pageProps }: AppPropsWithLayout) => {
if (Component.pure) {
return <Component {...pageProps} />
}
// Use the layout defined at the page level, if available
const Layout = Component.Layout || Fragment
const ShowMenu = Component.mp ? Fragment : Menu
const isShowScrollToTopButton = Component.isShowScrollToTopButton || true
return (
<ProductionErrorBoundary>
<ShowMenu>
<Layout>
<Component {...pageProps} />
</Layout>
</ShowMenu>
<EasterEgg iterations={2} />
<ToastListener />
{/* <FixedSubgraphHealthIndicator /> */}
<NetworkModal pageSupportedChains={Component.chains} />
{/* <NetworkModal pageSupportedChains={[42161]} /> */}
<TransactionsDetailModal />
{isShowScrollToTopButton && <ScrollToTopButtonV2 />}
</ProductionErrorBoundary>
)
}
export default MyApp