/
Cells.tsx
187 lines (166 loc) · 5.16 KB
/
Cells.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
import { formatEther } from '@ethersproject/units'
import { SquareArrowDownIcon, SquareArrowUpIcon, VerifiedIcon } from 'nft/components/icons'
import { useIsMobile } from 'nft/hooks'
import { Denomination } from 'nft/types'
import { volumeFormatter } from 'nft/utils'
import styled from 'styled-components/macro'
import { ThemedText } from 'theme'
import { ethNumberStandardFormatter, formatWeiToDecimal } from '../../../utils/currency'
import { formatChange } from '../../../utils/toSignificant'
import { Box } from '../../Box'
import { Column, Row } from '../../Flex'
import * as styles from './Cells.css'
const TruncatedText = styled.div`
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
`
const CollectionNameContainer = styled(TruncatedText)`
display: flex;
padding: 14px 0px 14px 8px;
align-items: center;
`
const CollectionName = styled(TruncatedText)`
margin-left: 8px;
`
const TruncatedSubHeader = styled(ThemedText.SubHeader)`
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
`
const TruncatedSubHeaderSmall = styled(ThemedText.SubHeaderSmall)`
color: ${({ theme }) => `${theme.textPrimary}`};
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
`
const RoundedImage = styled.div<{ src?: string }>`
height: 36px;
width: 36px;
border-radius: 36px;
background: ${({ src, theme }) => (src ? `url(${src})` : theme.backgroundModule)};
background-size: cover;
background-position: center;
flex-shrink: 0;
`
const ChangeCellContainer = styled.div<{ change: number }>`
display: flex;
color: ${({ theme, change }) => (change >= 0 ? theme.accentSuccess : theme.accentFailure)};
justify-content: end;
align-items: center;
gap: 2px;
`
const EthContainer = styled.div`
display: flex;
justify-content: end;
`
interface CellProps {
value: {
logo?: string
name?: string
address?: string
isVerified?: boolean
value?: number
change?: number
}
}
export const CollectionTitleCell = ({ value }: CellProps) => {
const isMobile = useIsMobile()
return (
<CollectionNameContainer>
<RoundedImage src={value.logo} />
<CollectionName>
{isMobile ? (
<TruncatedSubHeaderSmall>{value.name}</TruncatedSubHeaderSmall>
) : (
<TruncatedSubHeader>{value.name}</TruncatedSubHeader>
)}
</CollectionName>
{value.isVerified && (
<span className={styles.verifiedBadge}>
<VerifiedIcon />
</span>
)}
</CollectionNameContainer>
)
}
export const DiscreteNumberCell = ({ value }: CellProps) => (
<span>{value.value ? volumeFormatter(value.value) : '-'}</span>
)
const getDenominatedValue = (denomination: Denomination, inWei: boolean, value?: number, usdPrice?: number) => {
if (denomination === Denomination.ETH) return value
if (usdPrice && value) return usdPrice * (inWei ? parseFloat(formatEther(value)) : value)
return undefined
}
export const EthCell = ({
value,
denomination,
usdPrice,
}: {
value?: number
denomination: Denomination
usdPrice?: number
}) => {
const denominatedValue = getDenominatedValue(denomination, true, value, usdPrice)
const formattedValue = denominatedValue
? denomination === Denomination.ETH
? formatWeiToDecimal(denominatedValue.toString(), true) + ' ETH'
: ethNumberStandardFormatter(denominatedValue, true, false, true)
: '-'
return (
<EthContainer>
<ThemedText.BodyPrimary>{value ? formattedValue : '-'}</ThemedText.BodyPrimary>
</EthContainer>
)
}
export const TextCell = ({ value }: { value: string }) => <ThemedText.BodyPrimary>{value}</ThemedText.BodyPrimary>
export const VolumeCell = ({
value,
denomination,
usdPrice,
}: {
value?: number
denomination: Denomination
usdPrice?: number
}) => {
const denominatedValue = getDenominatedValue(denomination, false, value, usdPrice)
const formattedValue = denominatedValue
? denomination === Denomination.ETH
? ethNumberStandardFormatter(denominatedValue.toString(), false, false, true) + ' ETH'
: ethNumberStandardFormatter(denominatedValue, true, false, true)
: '-'
return (
<EthContainer>
<ThemedText.BodyPrimary>{value ? formattedValue : '-'}</ThemedText.BodyPrimary>
</EthContainer>
)
}
export const ChangeCell = ({ change }: { change?: number }) => (
<ChangeCellContainer change={change ?? 0}>
{!change || change > 0 ? (
<SquareArrowUpIcon width="20px" height="20px" />
) : (
<SquareArrowDownIcon width="20px" height="20px" />
)}
<ThemedText.BodyPrimary color="currentColor">{change ? Math.abs(Math.round(change)) : 0}%</ThemedText.BodyPrimary>
</ChangeCellContainer>
)
export const WeiWithDayChange = ({ value }: CellProps) => (
<Column gap="4">
<Row justifyContent="flex-end" color="textPrimary">
{value && value.value ? <>{formatWeiToDecimal(value.value.toString(), true)} ETH</> : '-'}
</Row>
{value.change ? (
<Box
as="span"
color={value.change > 0 ? 'green' : 'accentFailure'}
fontWeight="normal"
fontSize="12"
position="relative"
>
{value.change > 0 && '+'}
{formatChange(value.change)}%
</Box>
) : null}
</Column>
)