-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy path_app.js
202 lines (181 loc) · 6.85 KB
/
_app.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
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
import { useRouter } from 'next/router'
import { useState, useEffect } from 'react'
import Head from 'next/head'
import axios from 'axios'
import { appWithTranslation } from 'next-i18next'
import dynamic from 'next/dynamic'
import { GoogleAnalytics } from '@next/third-parties/google'
import Header from '../components/Layout/Header'
import Footer from '../components/Layout/Footer'
import ScrollToTop from '../components/Layout/ScrollToTop'
import BackgroundImage from '../components/Layout/BackgroundImage'
const SignForm = dynamic(() => import('../components/SignForm'), { ssr: false })
const TopLinks = dynamic(() => import('../components/Layout/TopLinks'), { ssr: false })
const TopProgressBar = dynamic(() => import('../components/TopProgressBar'), { ssr: false })
import { IsSsrMobileContext } from '../utils/mobile'
import { isValidUUID, network, server, useLocalStorage, useCookie, xahauNetwork, networkId } from '../utils'
import { getAppMetadata } from '@walletconnect/utils'
import { WalletConnectModalSign } from '@walletconnect/modal-sign-react'
import '../styles/ui.scss'
import '../styles/components/nprogress.css'
import { ThemeProvider } from '../components/Layout/ThemeContext'
import { fetchCurrentFiatRate } from '../utils/common'
const MyApp = ({ Component, pageProps }) => {
const [account, setAccount] = useLocalStorage('account')
const [sessionToken, setSessionToken] = useLocalStorage('sessionToken')
const [selectedCurrency, setSelectedCurrency] = useCookie('currency', 'usd')
const [fiatRate, setFiatRate] = useState(0)
const [proExpire, setProExpire] = useCookie('pro-expire')
const [subscriptionExpired, setSubscriptionExpired] = useState(
proExpire ? Number(proExpire) < new Date().getTime() : true
)
const [signRequest, setSignRequest] = useState(false)
const [refreshPage, setRefreshPage] = useState('')
const [wcSession, setWcSession] = useState(null)
const router = useRouter()
useEffect(() => {
//pages where we need to show the latest fiat price
const allowedRoutes = ['/', '/account/[[...id]]', '/amms', '/distribution', '/admin/watchlist']
if (allowedRoutes.includes(router.pathname)) {
fetchCurrentFiatRate(selectedCurrency, setFiatRate)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedCurrency, router.pathname])
useEffect(() => {
setSubscriptionExpired(proExpire ? Number(proExpire) < new Date().getTime() : true)
}, [proExpire])
useEffect(() => {
if (sessionToken) {
axios.defaults.headers.common['Authorization'] = 'Bearer ' + sessionToken?.replace(/['"]+/g, '')
}
}, [sessionToken])
const { uuid } = router.query
const signOut = () => {
localStorage.removeItem('xamanUserToken')
setWcSession(null)
setAccount({
...account,
address: null,
username: null,
wallet: null
})
}
const signOutPro = () => {
setSessionToken('')
setProExpire('0')
setAccount({
...account,
pro: null
})
}
const saveAddressData = async ({ address, wallet }) => {
//&service=true&verifiedDomain=true&blacklist=true&payString=true&twitterImageUrl=true&nickname=true
const response = await axios('v2/address/' + address + '?username=true')
if (response.data) {
const { username } = response.data
setAccount({ ...account, address, username, wallet })
} else {
setAccount({
...account,
address: null,
username: null,
wallet: null
})
}
}
if (process.env.NODE_ENV === 'development') {
axios.defaults.headers.common['x-bithomp-token'] = process.env.NEXT_PUBLIC_BITHOMP_API_TEST_KEY
axios.defaults.baseURL = server + '/api/'
} else {
axios.defaults.baseURL = server + '/api/cors/'
}
const pathname = router.pathname
const pagesWithoutWrapper = ['/social-share']
const showAds = (subscriptionExpired || !account?.pro) && !xahauNetwork
let showTopAds = showAds // change here when you want to see TOP ADS
const pagesWithNoTopAdds = [
'/',
'/username',
'/eaas',
'/build-unl',
'/disclaimer',
'/privacy-policy',
'/terms-and-conditions',
'/press',
'/404'
]
if (showTopAds) {
showTopAds = !pagesWithNoTopAdds.includes(pathname) && !pathname.includes('/admin')
}
if (pagesWithoutWrapper.includes(pathname)) {
return <Component />
}
return (
<>
<Head>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta charSet="utf-8" />
</Head>
<IsSsrMobileContext.Provider value={pageProps.isSsrMobile}>
<ThemeProvider>
<div className="body" data-network={network}>
<Header
setSignRequest={setSignRequest}
account={account}
signOut={signOut}
signOutPro={signOutPro}
selectedCurrency={selectedCurrency}
setSelectedCurrency={setSelectedCurrency}
/>
<ScrollToTop />
{/* available only on the mainnet and testnet */}
{(networkId === 0 || networkId === 1) && (
<WalletConnectModalSign projectId={process.env.NEXT_PUBLIC_WALLETCONNECT} metadata={getAppMetadata()} />
)}
{(signRequest || isValidUUID(uuid)) && (
<SignForm
setSignRequest={setSignRequest}
account={account}
setAccount={setAccount}
signRequest={signRequest}
uuid={uuid}
setRefreshPage={setRefreshPage}
saveAddressData={saveAddressData}
wcSession={wcSession}
setWcSession={setWcSession}
/>
)}
<div className="content">
<TopProgressBar />
{showTopAds && <TopLinks />}
<Component
{...pageProps}
refreshPage={refreshPage}
setSignRequest={setSignRequest}
account={account}
setAccount={setAccount}
signOut={signOut}
selectedCurrency={selectedCurrency}
setSelectedCurrency={setSelectedCurrency}
showAds={showAds}
setProExpire={setProExpire}
signOutPro={signOutPro}
subscriptionExpired={subscriptionExpired}
setSubscriptionExpired={setSubscriptionExpired}
sessionToken={sessionToken}
setSessionToken={setSessionToken}
fiatRate={fiatRate}
/>
</div>
<BackgroundImage />
<Footer setSignRequest={setSignRequest} account={account} />
</div>
</ThemeProvider>
{process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID && (
<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID} />
)}
</IsSsrMobileContext.Provider>
</>
)
}
export default appWithTranslation(MyApp)