-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
index.tsx
344 lines (325 loc) · 9.81 KB
/
index.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
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
import * as React from 'react'
import * as Kb from '../../../common-adapters'
import * as Types from '../../../constants/types/wallets'
import * as Constants from '../../../constants/wallets'
import * as Styles from '../../../styles'
import shallowEqual from 'shallowequal'
type Props = {
state: Types.AirdropState
onCancel: () => void
onLoad: () => void
onSubmit: () => void
rows: ReadonlyArray<{
title: string
subTitle: string
valid: boolean
}>
}
const Accepted = p =>
Styles.isMobile && p.state !== 'accepted' ? null : (
<Kb.ScrollView
style={styles.scrollView}
className={Styles.classNames({
'fade-anim-enter': true,
'fade-anim-enter-active': p.state === 'accepted',
})}
>
<Kb.Box2 noShrink={true} fullWidth={true} direction="vertical" style={styles.content} gap="medium">
<Kb.Box2 direction="vertical" style={styles.grow} />
<Kb.Icon type="icon-fancy-airdrop-star-shining-happy-120" style={styles.star} />
<Kb.Box2 direction="vertical" gap="xtiny" fullWidth={true} alignItems="center">
<Kb.Text negative={true} center={true} type="Header">
You're in!
</Kb.Text>
<Kb.Text negative={true} center={true} type="Body">
Your Lumens will show up in your default wallet account.
</Kb.Text>
</Kb.Box2>
<Kb.Box2 direction="vertical" style={styles.grow} />
<Kb.Divider />
<Kb.Box2 direction="vertical" style={styles.grow} />
<Kb.Box2 direction="vertical" gap="xtiny" fullWidth={true} alignItems="center">
<Kb.Text negative={true} center={true} type="BodySemibold">
Now bring your friends!
</Kb.Text>
<Kb.Box2 direction={Styles.isMobile ? 'vertical' : 'horizontal'}>
<Kb.Text negative={true} center={true} type="Body" style={styles.friendText}>
Share this link:{' '}
</Kb.Text>
<Kb.Text
negative={true}
center={true}
type="BodyPrimaryLink"
onClickURL="https://keybase.io/airdrop"
>
https://keybase.io/airdrop
</Kb.Text>
</Kb.Box2>
</Kb.Box2>
<Kb.Box2 direction="vertical" style={styles.grow} />
<Kb.Button
onClick={p.onCancel}
fullWidth={true}
type="Wallet"
label="Close"
style={styles.buttonClose}
/>
</Kb.Box2>
</Kb.ScrollView>
)
const Row = p => (
<Kb.Box2
noShrink={true}
direction="vertical"
fullWidth={true}
style={Styles.collapseStyles([styles.row, !p.first && styles.rowBorder])}
>
<Kb.Box2 noShrink={true} direction="horizontal" fullWidth={true}>
<Kb.Text type="BodySemibold" style={styles.rowText}>
{p.title}
</Kb.Text>
{p.loading && <Kb.ProgressIndicator style={styles.progress} white={true} />}
{!p.loading && (
<Kb.Icon
type={p.valid ? 'iconfont-check' : 'iconfont-close'}
color={p.valid ? Styles.globalColors.green : Styles.globalColors.red}
sizeType={'Default'}
/>
)}
</Kb.Box2>
{!p.loading && !!p.subTitle && (
<Kb.Text type="Body" style={styles.rowText}>
{p.subTitle}
</Kb.Text>
)}
</Kb.Box2>
)
type State = {
rowIdxLoaded: number
}
class Qualified extends React.PureComponent<Props, State> {
state = {
rowIdxLoaded: -1,
}
_loadingTimerID: NodeJS.Timeout | null
_kickNextLoad = () => {
if (__STORYSHOT__) {
return
}
this._loadingTimerID && clearTimeout(this._loadingTimerID)
this._loadingTimerID = undefined
if (this.state.rowIdxLoaded >= this.props.rows.length - 1) {
return
}
// wait extra long on last row
if (this.state.rowIdxLoaded === this.props.rows.length - 2) {
this._loadingTimerID = setTimeout(() => this.setState(p => ({rowIdxLoaded: p.rowIdxLoaded + 1})), 2500)
} else {
this._loadingTimerID = setTimeout(() => this.setState(p => ({rowIdxLoaded: p.rowIdxLoaded + 1})), 1000)
}
}
componentWillUnmount() {
this._loadingTimerID && clearTimeout(this._loadingTimerID)
this._loadingTimerID = undefined
}
componentDidMount() {
this._kickNextLoad()
}
componentDidUpdate(prevProps, prevState) {
// got new rows or more to load
if (!shallowEqual(this.props.rows, prevProps.rows)) {
this.setState({rowIdxLoaded: -1})
this._kickNextLoad()
} else if (this.state.rowIdxLoaded < this.props.rows.length) {
this._kickNextLoad()
}
}
render() {
const rows = this.props.rows
const loadingRows = !!rows.length && this.state.rowIdxLoaded < rows.length - 1
const loading = this.props.state === 'loading' || !!loadingRows
if (Styles.isMobile && this.props.state === 'accepted') {
return null
}
let starIcon
let description
if (loading) {
starIcon = 'icon-fancy-airdrop-star-faded-loading-120'
description = 'Analyzing your account...'
} else {
starIcon =
this.props.state === 'qualified'
? 'icon-fancy-airdrop-star-shining-happy-120'
: 'icon-fancy-airdrop-star-faded-sad-120'
description =
this.props.state === 'qualified'
? 'You are qualified to join!'
: 'Sorry, you are not qualified to join.'
}
return (
<Kb.ScrollView
style={styles.scrollView}
className={Styles.classNames({
'fade-anim-enter': true,
'fade-anim-enter-active': this.props.state !== 'accepted',
})}
>
<Kb.Box2 noShrink={true} direction="vertical" fullWidth={true} gap="tiny" style={styles.content}>
<>
<Kb.Icon type={starIcon} style={styles.star} />
</>
<Kb.Box2 direction="vertical" style={styles.titleBox}>
<Kb.Text
center={true}
type={loading ? 'BodySmallSemibold' : 'Header'}
style={loading ? styles.loadingText : styles.headerText}
>
{description}
</Kb.Text>
</Kb.Box2>
<Kb.Box2
direction="vertical"
className={Styles.classNames({
growFadeInBig: rows.length,
growFadeInSmall: true,
})}
>
{rows.map((r, idx) => (
<Row key={r.title} {...r} first={idx === 0} loading={idx > this.state.rowIdxLoaded} />
))}
</Kb.Box2>
<Kb.Box2 direction="vertical" style={styles.grow} />
{this.props.state === 'qualified' && (
<Kb.WaitingButton
onClick={this.props.onSubmit}
fullWidth={true}
type="Success"
label="Become a lucky airdropee"
disabled={loadingRows}
waitingKey={Constants.airdropWaitingKey}
style={loading ? styles.buttonAcceptLoading : styles.buttonAccept}
/>
)}
<Kb.Button
onClick={this.props.onCancel}
fullWidth={true}
type="Wallet"
label="Close"
style={styles.buttonClose}
/>
</Kb.Box2>
</Kb.ScrollView>
)
}
}
class Qualify extends React.PureComponent<Props> {
componentDidMount() {
this.props.onLoad()
}
render() {
return (
<Kb.MaybePopup
onClose={this.props.onCancel}
styleContainer={Styles.isMobile ? undefined : styles.popupContainer}
>
<Kb.Box2 direction="vertical" fullWidth={true} fullHeight={true} style={styles.container}>
<Accepted {...this.props} />
<Qualified {...this.props} />
</Kb.Box2>
</Kb.MaybePopup>
)
}
}
const styles = Styles.styleSheetCreate({
buttonAccept: {flexGrow: 0},
buttonAcceptLoading: {flexGrow: 0, opacity: 0},
buttonClose: {
backgroundColor: Styles.globalColors.black_20,
flexGrow: 0,
},
container: Styles.platformStyles({
common: {backgroundColor: Styles.globalColors.purple},
isElectron: {
height: 550,
width: 400,
},
isMobile: {
height: '100%',
width: '100%',
},
}),
content: Styles.platformStyles({
isElectron: {
minHeight: 550,
padding: Styles.globalMargins.medium,
},
isMobile: {
minHeight: '100%',
padding: Styles.globalMargins.small,
},
}),
friendText: Styles.platformStyles({
isElectron: {whiteSpace: 'pre'},
}),
grow: {
flexGrow: 1,
flexShrink: 1,
width: 100,
},
headerText: {color: Styles.globalColors.white},
loadingText: {color: Styles.globalColors.white_40},
popupContainer: {backgroundColor: Styles.globalColors.purple},
progress: Styles.platformStyles({
common: {
color: Styles.globalColors.white_75,
},
isElectron: {
height: 16,
width: 16,
},
isMobile: {
height: 22,
width: 22,
},
}),
row: Styles.platformStyles({
common: {
paddingLeft: Styles.globalMargins.tiny,
paddingRight: Styles.globalMargins.tiny,
},
isElectron: {
minHeight: Styles.globalMargins.large,
paddingBottom: Styles.globalMargins.xsmall,
paddingTop: Styles.globalMargins.xsmall,
},
isMobile: {
paddingBottom: Styles.globalMargins.xsmall,
paddingTop: Styles.globalMargins.xsmall,
},
}),
rowBorder: {
borderStyle: 'solid',
borderTopColor: Styles.globalColors.black_10,
borderTopWidth: 1,
},
rowText: {
color: Styles.globalColors.white,
flexGrow: 1,
flexShrink: 1,
marginRight: Styles.globalMargins.medium,
},
scrollView: {...Styles.globalStyles.fillAbsolute},
star: {
alignSelf: 'center',
height: 120,
marginTop: Styles.globalMargins.medium,
width: 120,
},
titleBox: {
height: 28,
justifyContent: 'center',
marginBottom: Styles.globalMargins.small,
marginTop: Styles.globalMargins.medium,
},
})
export default Qualify