-
Notifications
You must be signed in to change notification settings - Fork 21
/
RequestDetail.js
359 lines (350 loc) · 10.5 KB
/
RequestDetail.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
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
import React, { useCallback } from 'react'
import styled from 'styled-components'
import {
BackButton,
Bar,
Box,
GU,
Split,
textStyle,
useLayout,
useTheme,
Text,
IconCheck,
IconCross,
IconConnect,
Button,
Info,
TokenBadge,
RADIUS,
} from '@aragon/ui'
import { useConnectedAccount, useNetwork } from '@aragon/api-react'
import LocalIdentityBadge from '../components/LocalIdentityBadge/LocalIdentityBadge'
import RequestText from '../components/RequestText'
import { requestStatus } from '../lib/constants'
import { addressesEqual } from '../lib/web3-utils'
import { formatTokenAmountSymbol } from '../lib/token-utils'
import { formatTokenAmount } from '../lib/math-utils'
import { format } from 'date-fns'
const RequestDetail = ({ request, token, onBack, onSubmit, onWithdraw }) => {
const { layoutName } = useLayout()
const theme = useTheme()
const connectedAccount = useConnectedAccount()
const network = useNetwork()
const {
requestId,
requesterAddress,
depositAmount,
depositSymbol,
requestAmount,
depositDecimals,
depositToken,
reference,
date,
status,
} = request
const depositFormated = formatTokenAmount(depositAmount, false, depositDecimals, token.decimals)
const requestFormated = formatTokenAmount(requestAmount, false, token.decimals, token.decimals)
const requestRounded = formatTokenAmountSymbol(token.symbol, requestAmount, token.decimals)
const title = `#${requestId} - ${requestRounded} requested by`
const formatDate = date => `${format(date, 'do MMM yy, HH:mm')} UTC`
const statusColor = getStatusColor(status, theme).toString()
const handleWithdraw = useCallback(
requestId => {
onWithdraw(requestId)
},
[onWithdraw]
)
const handleSubmit = useCallback(
requestId => {
onSubmit(requestId)
},
[onSubmit]
)
return (
<React.Fragment>
<Bar>
<BackButton onClick={onBack} />
</Bar>
<Split
primary={
<Box>
<section
css={`
display: grid;
grid-template-columns: auto;
grid-gap: ${2.5 * GU}px;
margin-top: ${2.5 * GU}px;
`}
>
<h1
css={`
${textStyle('title2')};
`}
>
<div
css={`
font-weight: bold;
display: flex;
align-items: center;
`}
>
{title}
<LocalIdentityBadge
css={`
margin-left: ${1 * GU}px;
`}
connectedAccount={addressesEqual(requesterAddress, connectedAccount)}
entity={requesterAddress}
/>
</div>
</h1>
<div
css={`
display: grid;
grid-template-columns: ${layoutName === 'large' ? '1fr minmax(300px, auto)' : 'auto'};
grid-gap: ${layoutName === 'large' ? 5 * GU : 2.5 * GU}px;
`}
>
<div>
<h2
css={`
${textStyle('label2')};
color: ${theme.surfaceContentSecondary};
margin-bottom: ${2 * GU}px;
`}
>
Description
</h2>
<RequestText
text={reference}
css={`
${textStyle('body2')};
`}
/>
</div>
<div>
<h2
css={`
${textStyle('label2')};
color: ${theme.surfaceContentSecondary};
margin-bottom: ${2 * GU}px;
`}
>
Created By
</h2>
<div
css={`
display: flex;
align-items: flex-start;
`}
>
<LocalIdentityBadge
connectedAccount={addressesEqual(requesterAddress, connectedAccount)}
entity={requesterAddress}
/>
</div>
</div>
</div>
<div>
{connectedAccount ? (
status === requestStatus.PENDING && (
<React.Fragment>
<Buttons
requesterAddress={requesterAddress}
connectedAccount={connectedAccount}
onClickSubmit={() => {
handleSubmit(requestId)
}}
onClickWithdraw={() => {
handleWithdraw(requestId)
}}
/>
<Info.Permissions>
This request is pending, A user with permission to initiate the approval process must take
action. The status will not update unless it is approved or withdrawn by the requestor.
</Info.Permissions>
</React.Fragment>
)
) : (
<div
css={`
border-radius: ${RADIUS}px;
background: ${theme.background};
padding: ${3.5 * GU}px ${10 * GU}px;
text-align: center;
`}
>
<div
css={`
${textStyle('body1')};
`}
>
You must enable your account to be able to act on this request
</div>
<div
css={`
${textStyle('body2')};
color: ${theme.surfaceContentSecondary};
margin-top: ${2 * GU}px;
`}
>
Connect to your Ethereum provider by clicking on the{' '}
<strong
css={`
display: inline-flex;
align-items: center;
position: relative;
top: 7px;
`}
>
<IconConnect /> Enable account
</strong>{' '}
button on the header. You may be temporarily redirected to a new screen.
</div>
</div>
)}
</div>
</section>
</Box>
}
secondary={
<React.Fragment>
<Box heading='Request info'>
<Status color={statusColor}>{`${status}`}</Status>
<div
css={`
margin-top: ${1 * GU}px;
display: inline-grid;
grid-template-columns: auto auto;
grid-gap: ${1 * GU}px;
align-items: center;
color: ${theme.surfaceContentSecondary};
${textStyle('body2')};
`}
>
{formatDate(date)}
</div>
</Box>
<Box heading='Requested Amount'>
<div
css={`
display: relative;
align-items: center;
color: ${theme.surfaceContentSecondary};
${textStyle('body2')};
`}
>
<div>
<TokenBadge
address={token.address}
symbol={token.symbol}
name={token.name}
networkType={network && network.type}
/>
</div>
<div
css={`
margin-top: ${1 * GU}px;
`}
>
{requestFormated}
</div>
</div>
</Box>
<Box heading='Offered Amount'>
<div
css={`
display: relative;
align-items: center;
color: ${theme.surfaceContentSecondary};
${textStyle('body2')};
`}
>
<div>
<TokenBadge address={depositToken} symbol={depositSymbol} networkType={network && network.type} />
</div>
<div
css={`
margin-top: ${1 * GU}px;
`}
>
{depositFormated}
</div>
</div>
</Box>
</React.Fragment>
}
/>
</React.Fragment>
)
}
const Status = styled(Text)`
font-weight: 600;
color: ${({ color }) => {
color
}}};
`
const ActionButton = styled(Button)`
${textStyle('body2')};
width: ${({ requesterConnected }) => {
requesterConnected ? '50%' : '100%'
}};
&:first-child {
margin-right: ${1 * GU}px;
}
`
const ButtonsContainer = styled.div`
display: flex;
margin-bottom: ${2 * GU}px;
`
const Buttons = ({
requesterAddress,
connectedAccount,
onClickSubmit = noop,
onClickWithdraw = noop,
disabled = false,
}) => {
const requesterConnected = addressesEqual(requesterAddress, connectedAccount)
return (
<ButtonsContainer>
<ActionButton
requesterConnected={requesterConnected}
mode='positive'
wide
disabled={disabled}
onClick={onClickSubmit}
>
<IconCheck
size='small'
css={`
margin-right: ${1 * GU}px;
`}
/>
Submit
</ActionButton>
{requesterConnected && (
<ActionButton mode='negative' wide disabled={disabled} onClick={onClickWithdraw}>
<IconCross
size='small'
css={`
margin-right: ${1 * GU}px;
`}
/>
Withdraw
</ActionButton>
)}
</ButtonsContainer>
)
}
const getStatusColor = (status, theme) => {
switch (status) {
case requestStatus.PENDING:
return theme.yellow
case requestStatus.APPROVED:
return theme.positive
default:
return theme.positive
}
}
export default RequestDetail