-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTokenPage.js
More file actions
400 lines (371 loc) · 14.1 KB
/
TokenPage.js
File metadata and controls
400 lines (371 loc) · 14.1 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
import React, { useState } from 'react'
import 'feather-icons'
import { withRouter } from 'react-router-dom'
import { Text } from 'rebass'
import styled from 'styled-components'
import Link from '../components/Link'
import Panel from '../components/Panel'
import TokenLogo from '../components/TokenLogo'
import PairList from '../components/PairList'
import Loader from '../components/LocalLoader'
import { AutoRow, RowBetween, RowFixed } from '../components/Row'
import Column, { AutoColumn } from '../components/Column'
import { ButtonLight, ButtonDark } from '../components/ButtonStyled'
import TxnList from '../components/TxnList'
import TokenChart from '../components/TokenChart'
import { BasicLink } from '../components/Link'
import Search from '../components/Search'
import { formattedNum, formattedPercent, getPoolLink, getSwapLink, localNumber } from '../utils'
import { useTokenData, useTokenTransactions, useTokenPairs } from '../contexts/TokenData'
import { TYPE, ThemedBackground } from '../Theme'
import { transparentize } from 'polished'
import { useColor } from '../hooks'
import CopyHelper from '../components/Copy'
import { useMedia } from 'react-use'
import { useDataForList } from '../contexts/PairData'
import { useEffect } from 'react'
import Warning from '../components/Warning'
import { usePathDismissed, useSavedTokens } from '../contexts/LocalStorage'
import { Hover, PageWrapper, ContentWrapper, StyledIcon } from '../components'
import { PlusCircle, Bookmark } from 'react-feather'
import FormattedName from '../components/FormattedName'
import { useListedTokens } from '../contexts/Application'
const DashboardWrapper = styled.div`
width: 100%;
`
const PanelWrapper = styled.div`
grid-template-columns: repeat(3, 1fr);
grid-template-rows: max-content;
gap: 6px;
display: inline-grid;
width: 100%;
align-items: start;
@media screen and (max-width: 1024px) {
grid-template-columns: 1fr;
align-items: stretch;
> * {
grid-column: 1 / 4;
}
> * {
&:first-child {
width: 100%;
}
}
}
`
const TokenDetailsLayout = styled.div`
display: inline-grid;
width: 100%;
grid-template-columns: auto auto auto 1fr;
column-gap: 30px;
align-items: start;
&:last-child {
align-items: center;
justify-items: end;
}
@media screen and (max-width: 1024px) {
grid-template-columns: 1fr;
align-items: stretch;
> * {
grid-column: 1 / 4;
margin-bottom: 1rem;
}
&:last-child {
align-items: start;
justify-items: start;
}
}
`
const WarningGrouping = styled.div`
opacity: ${({ disabled }) => disabled && '0.4'};
pointer-events: ${({ disabled }) => disabled && 'none'};
`
function TokenPage({ address, history }) {
const {
id,
name,
symbol,
priceUSD,
oneDayVolumeUSD,
totalLiquidityUSD,
volumeChangeUSD,
oneDayVolumeUT,
volumeChangeUT,
priceChangeUSD,
liquidityChangeUSD,
oneDayTxns,
txnChange,
} = useTokenData(address)
useEffect(() => {
document.querySelector('body').scrollTo(0, 0)
}, [])
// detect color from token
const backgroundColor = useColor(id, symbol)
const allPairs = useTokenPairs(address)
// pairs to show in pair list
const fetchedPairsList = useDataForList(allPairs)
// all transactions with this token
const transactions = useTokenTransactions(address)
// price
const price = priceUSD ? formattedNum(priceUSD, true) : ''
const priceChange = priceChangeUSD ? formattedPercent(priceChangeUSD) : ''
// volume
const volume =
oneDayVolumeUSD || oneDayVolumeUSD === 0
? formattedNum(oneDayVolumeUSD === 0 ? oneDayVolumeUT : oneDayVolumeUSD, true)
: oneDayVolumeUSD === 0
? '$0'
: '-'
// mark if using untracked volume
const [usingUtVolume, setUsingUtVolume] = useState(false)
useEffect(() => {
setUsingUtVolume(oneDayVolumeUSD === 0 ? true : false)
}, [oneDayVolumeUSD])
const volumeChange = formattedPercent(!usingUtVolume ? volumeChangeUSD : volumeChangeUT)
// liquidity
const liquidity = totalLiquidityUSD ? formattedNum(totalLiquidityUSD, true) : totalLiquidityUSD === 0 ? '$0' : '-'
const liquidityChange = formattedPercent(liquidityChangeUSD)
// transactions
const txnChangeFormatted = formattedPercent(txnChange)
const below1080 = useMedia('(max-width: 1080px)')
const below800 = useMedia('(max-width: 800px)')
const below600 = useMedia('(max-width: 600px)')
const below500 = useMedia('(max-width: 500px)')
// format for long symbol
const LENGTH = below1080 ? 10 : 16
const formattedSymbol = symbol?.length > LENGTH ? symbol.slice(0, LENGTH) + '...' : symbol
const [dismissed, markAsDismissed] = usePathDismissed(history.location.pathname)
const [savedTokens, addToken] = useSavedTokens()
const listedTokens = useListedTokens()
useEffect(() => {
window.scrollTo({
behavior: 'smooth',
top: 0,
})
}, [])
return (
<PageWrapper>
<ThemedBackground backgroundColor={transparentize(0.6, backgroundColor)} />
<Warning
type={'token'}
show={!dismissed && listedTokens && !listedTokens.includes(address)}
setShow={markAsDismissed}
address={address}
/>
<ContentWrapper>
<RowBetween style={{ flexWrap: 'wrap', alingItems: 'start' }}>
<AutoRow align="flex-end" style={{ width: 'fit-content' }}>
<TYPE.body>
<BasicLink to="/tokens">{'Tokens '}</BasicLink>→ {symbol}
{' '}
</TYPE.body>
<Link
style={{ width: 'fit-content' }}
color={backgroundColor}
external
href={'https://polygonscan.com/address/' + address}
>
<Text style={{ marginLeft: '.15rem' }} fontSize={'14px'} fontWeight={400}>
({address.slice(0, 8) + '...' + address.slice(36, 42)})
</Text>
</Link>
</AutoRow>
{!below600 && <Search small={true} />}
</RowBetween>
<WarningGrouping disabled={!dismissed && listedTokens && !listedTokens.includes(address)}>
<DashboardWrapper style={{ marginTop: below1080 ? '0' : '1rem' }}>
<RowBetween
style={{
flexWrap: 'wrap',
marginBottom: '2rem',
alignItems: 'flex-start',
}}
>
<RowFixed style={{ flexWrap: 'wrap' }}>
<RowFixed style={{ alignItems: 'baseline' }}>
<TokenLogo address={address} size="32px" style={{ alignSelf: 'center' }} />
<TYPE.main fontSize={below1080 ? '1.5rem' : '2rem'} fontWeight={500} style={{ margin: '0 1rem' }}>
<RowFixed gap="6px">
<FormattedName text={name ? name + ' ' : ''} maxCharacters={16} style={{ marginRight: '6px' }} />{' '}
{formattedSymbol ? `(${formattedSymbol})` : ''}
</RowFixed>
</TYPE.main>{' '}
{!below1080 && (
<>
<TYPE.main fontSize={'1.5rem'} fontWeight={500} style={{ marginRight: '1rem' }}>
{price}
</TYPE.main>
{priceChange}
</>
)}
</RowFixed>
</RowFixed>
<span>
<RowFixed ml={below500 ? '0' : '2.5rem'} mt={below500 ? '1rem' : '0'}>
{!!!savedTokens[address] && !below800 ? (
<Hover onClick={() => addToken(address, symbol)}>
<StyledIcon>
<PlusCircle style={{ marginRight: '0.5rem' }} />
</StyledIcon>
</Hover>
) : !below1080 ? (
<StyledIcon>
<Bookmark style={{ marginRight: '0.5rem', opacity: 0.4 }} />
</StyledIcon>
) : (
<></>
)}
<Link href={getPoolLink(address)} target="_blank">
<ButtonLight color={backgroundColor}>+ Add Liquidity</ButtonLight>
</Link>
<Link href={getSwapLink(address)} target="_blank">
<ButtonDark ml={'.5rem'} mr={below1080 && '.5rem'} color={backgroundColor}>
Trade
</ButtonDark>
</Link>
</RowFixed>
</span>
</RowBetween>
<>
<PanelWrapper style={{ marginTop: below1080 ? '0' : '1rem' }}>
{below1080 && price && (
<Panel>
<AutoColumn gap="20px">
<RowBetween>
<TYPE.main>Price</TYPE.main>
<div />
</RowBetween>
<RowBetween align="flex-end">
{' '}
<TYPE.main fontSize={'1.5rem'} lineHeight={1} fontWeight={500}>
{price}
</TYPE.main>
<TYPE.main>{priceChange}</TYPE.main>
</RowBetween>
</AutoColumn>
</Panel>
)}
<Panel>
<AutoColumn gap="20px">
<RowBetween>
<TYPE.main>Total Liquidity</TYPE.main>
<div />
</RowBetween>
<RowBetween align="flex-end">
<TYPE.main fontSize={'1.5rem'} lineHeight={1} fontWeight={500}>
{liquidity}
</TYPE.main>
<TYPE.main>{liquidityChange}</TYPE.main>
</RowBetween>
</AutoColumn>
</Panel>
<Panel>
<AutoColumn gap="20px">
<RowBetween>
<TYPE.main>Volume (24hrs) {usingUtVolume && '(Untracked)'}</TYPE.main>
<div />
</RowBetween>
<RowBetween align="flex-end">
<TYPE.main fontSize={'1.5rem'} lineHeight={1} fontWeight={500}>
{volume}
</TYPE.main>
<TYPE.main>{volumeChange}</TYPE.main>
</RowBetween>
</AutoColumn>
</Panel>
<Panel>
<AutoColumn gap="20px">
<RowBetween>
<TYPE.main>Transactions (24hrs)</TYPE.main>
<div />
</RowBetween>
<RowBetween align="flex-end">
<TYPE.main fontSize={'1.5rem'} lineHeight={1} fontWeight={500}>
{oneDayTxns ? localNumber(oneDayTxns) : oneDayTxns === 0 ? 0 : '-'}
</TYPE.main>
<TYPE.main>{txnChangeFormatted}</TYPE.main>
</RowBetween>
</AutoColumn>
</Panel>
<Panel
style={{
gridColumn: below1080 ? '1' : '2/4',
gridRow: below1080 ? '' : '1/4',
}}
>
<TokenChart address={address} color={backgroundColor} base={priceUSD} />
</Panel>
</PanelWrapper>
</>
<span>
<TYPE.main fontSize={'1.125rem'} style={{ marginTop: '3rem' }}>
Top Pairs
</TYPE.main>
</span>
<Panel
rounded
style={{
marginTop: '1.5rem',
padding: '1.125rem 0 ',
}}
>
{address && fetchedPairsList ? (
<PairList color={backgroundColor} address={address} pairs={fetchedPairsList} />
) : (
<Loader />
)}
</Panel>
<RowBetween mt={40} mb={'1rem'}>
<TYPE.main fontSize={'1.125rem'}>Transactions</TYPE.main> <div />
</RowBetween>
<Panel rounded>
{transactions ? <TxnList color={backgroundColor} transactions={transactions} /> : <Loader />}
</Panel>
<>
<RowBetween style={{ marginTop: '3rem' }}>
<TYPE.main fontSize={'1.125rem'}>Token Information</TYPE.main>{' '}
</RowBetween>
<Panel
rounded
style={{
marginTop: '1.5rem',
}}
p={20}
>
<TokenDetailsLayout>
<Column>
<TYPE.main>Symbol</TYPE.main>
<Text style={{ marginTop: '.5rem' }} fontSize={24} fontWeight="500">
<FormattedName text={symbol} maxCharacters={12} />
</Text>
</Column>
<Column>
<TYPE.main>Name</TYPE.main>
<TYPE.main style={{ marginTop: '.5rem' }} fontSize={24} fontWeight="500">
<FormattedName text={name} maxCharacters={16} />
</TYPE.main>
</Column>
<Column>
<TYPE.main>Address</TYPE.main>
<AutoRow align="flex-end">
<TYPE.main style={{ marginTop: '.5rem' }} fontSize={24} fontWeight="500">
{address.slice(0, 8) + '...' + address.slice(36, 42)}
</TYPE.main>
<CopyHelper toCopy={address} />
</AutoRow>
</Column>
<ButtonLight color={backgroundColor}>
<Link color={backgroundColor} external href={'https://polygonscan.com/address/' + address}>
View on Explorer ↗
</Link>
</ButtonLight>
</TokenDetailsLayout>
</Panel>
</>
</DashboardWrapper>
</WarningGrouping>
</ContentWrapper>
</PageWrapper>
)
}
export default withRouter(TokenPage)