This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
ClaimsTable.tsx
173 lines (163 loc) · 4.97 KB
/
ClaimsTable.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
import {
ClaimType,
useAirdropDeadline,
useClaimState,
useDeploymentTimestamp,
useInvestmentDeadline,
} from 'state/claim/hooks'
import styled from 'styled-components/macro'
import { ClaimTable, ClaimBreakdown, TokenLogo } from 'pages/Claim/styled'
import CowProtocolLogo from 'components/CowProtocolLogo'
import { ClaimStatus } from 'state/claim/actions'
// import { UserClaimDataDetails } from './types' TODO: fix in another PR
import { formatSmart } from 'utils/format'
import { EnhancedUserClaimData } from './types'
import { useAllClaimingTransactionIndices } from 'state/enhancedTransactions/hooks'
import { CustomLightSpinner } from 'theme'
import Circle from 'assets/images/blue-loader.svg'
import { Countdown } from 'pages/Claim/Countdown'
type ClaimsTableProps = {
handleSelectAll: (event: React.ChangeEvent<HTMLInputElement>) => void
handleSelect: (event: React.ChangeEvent<HTMLInputElement>, index: number) => void
userClaimData: EnhancedUserClaimData[]
isAirdropOnly: boolean
hasClaims: boolean
}
// TODO: fix in other pr
type ClaimsTableRowProps = EnhancedUserClaimData &
Pick<ClaimsTableProps, 'handleSelect'> & {
selected: number[]
start: number | null
end: number | null
isPendingClaim: boolean
}
const ClaimTr = styled.tr<{ isPending?: boolean }>`
> td {
background-color: ${({ isPending }) => (isPending ? '#221954' : 'rgb(255 255 255 / 6%)')};
cursor: ${({ isPending }) => (isPending ? 'pointer' : 'initial')};
&:first-child {
border-radius: 8px 0 0 8px;
}
&:last-child {
border-radius: 0 8px 8px 0;
}
}
`
const ClaimsTableRow = ({
index,
type,
isFree,
isPendingClaim,
claimAmount,
currencyAmount,
price,
cost,
handleSelect,
selected,
start,
end,
}: ClaimsTableRowProps) => {
return (
<ClaimTr key={index} isPending={isPendingClaim}>
<td>
{' '}
<label className="checkAll">
{isPendingClaim ? (
<CustomLightSpinner src={Circle} title="Claiming in progress..." alt="loader" size="24px" />
) : (
<input
onChange={(event) => handleSelect(event, index)}
type="checkbox"
name="check"
checked={isFree || selected.includes(index)}
disabled={isFree}
/>
)}
</label>
</td>
<td>
{' '}
<TokenLogo symbol={`${currencyAmount?.currency?.symbol}`} size={32} />
<CowProtocolLogo size={32} />
<span>
<b>{isFree ? ClaimType[type] : 'Buy vCOW'}</b>
{!isFree && <i>with {currencyAmount?.currency?.symbol}</i>}
</span>
</td>
<td>{formatSmart(claimAmount) || 0} vCOW</td>
<td>
<span>
Price:{' '}
<b>{isFree || !price ? '-' : `${formatSmart(price) || 0} vCoW per ${currencyAmount?.currency?.symbol}`}</b>
</span>
<span>
Cost:{' '}
<b>
{' '}
{isFree ? (
<span className="green">Free!</span>
) : (
`${formatSmart(cost) || 0} ${currencyAmount?.currency?.symbol}`
)}
</b>
</span>
<span>
Vesting: <b>{type === ClaimType.Airdrop ? 'No' : '4 years (linear)'}</b>
</span>
<span>
Ends in: <b>{start && end && <Countdown start={start} end={end} />}</b>
</span>
</td>
</ClaimTr>
)
}
export default function ClaimsTable({
handleSelectAll,
handleSelect,
userClaimData,
isAirdropOnly,
hasClaims,
}: ClaimsTableProps) {
const { selectedAll, selected, activeClaimAccount, claimStatus, isInvestFlowActive } = useClaimState()
const pendingClaimsSet = useAllClaimingTransactionIndices()
const hideTable =
isAirdropOnly || !hasClaims || !activeClaimAccount || claimStatus !== ClaimStatus.DEFAULT || isInvestFlowActive
const start = useDeploymentTimestamp()
const investmentEnd = useInvestmentDeadline()
const airdropEnd = useAirdropDeadline()
if (hideTable) return null
return (
<ClaimBreakdown>
<h2>vCOW claim breakdown</h2>
<ClaimTable>
<table>
<thead>
<tr>
<th>
<label className="checkAll">
<input checked={selectedAll} onChange={handleSelectAll} type="checkbox" name="check" />
</label>
</th>
<th>Type of Claim</th>
<th>Amount</th>
<th>Details</th>
</tr>
</thead>
<tbody>
{userClaimData.map((claim: EnhancedUserClaimData) => (
<ClaimsTableRow
key={claim.index}
{...claim}
isPendingClaim={pendingClaimsSet.has(claim.index)}
selected={selected}
handleSelect={handleSelect}
start={start}
end={claim.isFree ? airdropEnd : investmentEnd}
/>
))}
</tbody>
</table>
</ClaimTable>
</ClaimBreakdown>
)
}