-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy path_app.tsx
208 lines (194 loc) · 7.64 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { ResetCSS, ScrollToTopButtonV2, ToastListener } from '@pancakeswap/uikit'
import BigNumber from 'bignumber.js'
import { SentryErrorBoundary } from 'components/ErrorBoundary'
import GlobalCheckClaimStatus from 'components/GlobalCheckClaimStatus'
import { PageMeta } from 'components/Layout/Page'
import { AffiliateExpiredModal } from 'components/Modal/AffiliateExpiredModal'
import { AffiliateSunsetModal } from 'components/Modal/AffiliateSunsetModal'
import { SimpleStakingSunsetModal } from 'components/Modal/SimpleStakingSunsetModal'
import { NetworkModal } from 'components/NetworkModal'
import { FixedSubgraphHealthIndicator } from 'components/SubgraphHealthIndicator/FixedSubgraphHealthIndicator'
import TransactionsDetailModal from 'components/TransactionDetailModal'
import { VercelToolbar } from 'components/VercelToolbar'
import 'core-js/features/array/to-sorted'
import 'core-js/features/string/replace-all'
import { useAccountEventListener } from 'hooks/useAccountEventListener'
import useEagerConnect from 'hooks/useEagerConnect'
import useLockedEndNotification from 'hooks/useLockedEndNotification'
import useSentryUser from 'hooks/useSentryUser'
import useThemeCookie from 'hooks/useThemeCookie'
import useUserAgent from 'hooks/useUserAgent'
import { NextPage } from 'next'
import { DefaultSeo } from 'next-seo'
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 { PersistGate } from 'redux-persist/integration/react'
import 'utils/abortcontroller-polyfill'
import { V4CakeIcon } from 'views/Home/components/V4CakeIcon'
import { AdPanel } from 'components/AdPanel'
import { layoutDesktopAdIgnoredPages, layoutMobileAdIgnoredPages } from 'components/AdPanel/config'
import { shouldRenderOnPages } from 'components/AdPanel/renderConditions'
import { ZKSyncAirdropModalWithAutoPopup } from 'components/ClaimZksyncAirdropModal'
import { useDataDogRUM } from 'hooks/useDataDogRUM'
import { useLoadExperimentalFeatures } from 'hooks/useExperimentalFeatureEnabled'
import useInitNotificationsClient from 'hooks/useInitNotificationsClient'
import { useVercelFeatureFlagOverrides } from 'hooks/useVercelToolbar'
import { useWeb3WalletView } from 'hooks/useWeb3WalletView'
import { useInitGlobalWorker } from 'hooks/useWorker'
import { persistor, useStore } from 'state'
import { usePollBlockNumber } from 'state/block/hooks'
import { Blocklist, Updaters } from '..'
import { SEO } from '../../next-seo.config'
import Providers from '../Providers'
import Menu from '../components/Menu'
import GlobalStyle from '../style/Global'
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() {
useInitGlobalWorker()
useDataDogRUM()
useWeb3WalletView()
useLoadExperimentalFeatures()
useVercelFeatureFlagOverrides()
usePollBlockNumber()
useEagerConnect()
useUserAgent()
useAccountEventListener()
useSentryUser()
useThemeCookie()
useLockedEndNotification()
useInitNotificationsClient()
return null
}
function MPGlobalHooks() {
usePollBlockNumber()
useUserAgent()
useAccountEventListener()
useSentryUser()
useLockedEndNotification()
useInitNotificationsClient()
return null
}
function MyApp(props: AppProps<{ initialReduxState: any; dehydratedState: 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="Cheaper and faster than Uniswap? Discover PancakeSwap, the leading DEX on BNB Smart Chain (BSC) with the best farms in DeFi and a lottery for CAKE."
/>
<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"
integrity="sha384-PV6Pqh2oiQNNl9jwtcTIue3fwDnP5k80+DaPY8/AS4qxGA91MsE3G91BQ2jQ81oT"
crossOrigin="anonymous"
id="mp-webview"
/>
)}
</Head>
<DefaultSeo {...SEO} />
<Providers store={store} dehydratedState={pageProps.dehydratedState}>
<PageMeta />
{(Component as NextPageWithLayout).Meta && (
// @ts-ignore
<Component.Meta {...pageProps} />
)}
{(Component as NextPageWithLayout).mp ? <MPGlobalHooks /> : <GlobalHooks />}
<ResetCSS />
<GlobalStyle />
<GlobalCheckClaimStatus excludeLocations={[]} />
<PersistGate loading={null} persistor={persistor}>
<Updaters />
<App {...props} />
</PersistGate>
</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_NEW_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
screen?: true
isShowV4IconButton?: false
/**
* 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
const shouldScreenWallet = Component.screen || false
const isShowV4IconButton = Component.isShowV4IconButton || false
return (
<ProductionErrorBoundary>
<ShowMenu>
<Layout>
<Component {...pageProps} />
<AdPanel.MobileCard shouldRender={!shouldRenderOnPages(layoutMobileAdIgnoredPages)} mt="4px" mb="12px" />
<AdPanel.DesktopCard shouldRender={!shouldRenderOnPages(layoutDesktopAdIgnoredPages)} />
</Layout>
</ShowMenu>
<EasterEgg iterations={2} />
<ToastListener />
<FixedSubgraphHealthIndicator />
<NetworkModal pageSupportedChains={Component.chains} />
<TransactionsDetailModal />
{isShowScrollToTopButton && <ScrollToTopButtonV2 />}
{shouldScreenWallet && <Blocklist />}
{isShowV4IconButton && <V4CakeIcon />}
<ZKSyncAirdropModalWithAutoPopup />
<AffiliateExpiredModal />
<AffiliateSunsetModal />
<SimpleStakingSunsetModal />
<VercelToolbar />
</ProductionErrorBoundary>
)
}
export default MyApp