-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
499 lines (463 loc) · 12.1 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
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
import {
MediaRenderer,
useActiveClaimConditionForWallet,
useAddress,
useClaimConditions,
useClaimedNFTSupply,
useClaimerProofs,
useClaimIneligibilityReasons,
useContract,
useContractMetadata,
useUnclaimedNFTSupply,
useTotalCirculatingSupply,
Web3Button,
} from '@thirdweb-dev/react'
import { BigNumber, utils } from 'ethers'
import type { NextPage } from 'next'
import { useMemo, useState } from 'react'
import Timer from '../components/Timer'
import styles from '../styles/Theme.module.css'
import { parseIneligibility } from '../utils/parseIneligibility'
import Navigation from '../components/NavBar'
import { Text, Spacer, Container, Grid, Button } from '@nextui-org/react'
// Put Your NFT Drop Contract address from the dashboard here
const myEditionDropContractAddress =
'0xE1AAa7fAB6bE87D606766B22749Fa588C4aADaB6'
const tokenId = 0
const Home: NextPage = () => {
const address = useAddress()
const [quantity, setQuantity] = useState(1)
const { contract: editionDrop } = useContract(myEditionDropContractAddress)
const { data: contractMetadata } = useContractMetadata(editionDrop)
const claimConditions = useClaimConditions(editionDrop)
const activeClaimCondition = useActiveClaimConditionForWallet(
editionDrop,
address,
tokenId
)
const claimerProofs = useClaimerProofs(editionDrop, address || '', tokenId)
const claimIneligibilityReasons = useClaimIneligibilityReasons(
editionDrop,
{
quantity,
walletAddress: address || '',
},
tokenId
)
const claimedSupply = useTotalCirculatingSupply(editionDrop, tokenId)
const totalAvailableSupply = useMemo(() => {
try {
return BigNumber.from(
activeClaimCondition.data?.availableSupply || 0
)
} catch {
return BigNumber.from(1_000_000)
}
}, [activeClaimCondition.data?.availableSupply])
const numberClaimed = useMemo(() => {
return BigNumber.from(claimedSupply.data || 0).toString()
}, [claimedSupply])
const numberTotal = useMemo(() => {
const n = totalAvailableSupply.add(
BigNumber.from(claimedSupply.data || 0)
)
if (n.gte(1_000_000)) {
return ''
}
return n.toString()
}, [totalAvailableSupply, claimedSupply])
const priceToMint = useMemo(() => {
const bnPrice = BigNumber.from(
activeClaimCondition.data?.currencyMetadata.value || 0
)
return `${utils.formatUnits(
bnPrice.mul(quantity).toString(),
activeClaimCondition.data?.currencyMetadata.decimals || 18
)} ${activeClaimCondition.data?.currencyMetadata.symbol}`
}, [
activeClaimCondition.data?.currencyMetadata.decimals,
activeClaimCondition.data?.currencyMetadata.symbol,
activeClaimCondition.data?.currencyMetadata.value,
quantity,
])
const maxClaimable = useMemo(() => {
let bnMaxClaimable
try {
bnMaxClaimable = BigNumber.from(
activeClaimCondition.data?.maxClaimableSupply || 0
)
} catch (e) {
bnMaxClaimable = BigNumber.from(1_000_000)
}
let perTransactionClaimable
try {
perTransactionClaimable = BigNumber.from(
activeClaimCondition.data?.maxClaimablePerWallet || 0
)
} catch (e) {
perTransactionClaimable = BigNumber.from(1_000_000)
}
if (perTransactionClaimable.lte(bnMaxClaimable)) {
bnMaxClaimable = perTransactionClaimable
}
const snapshotClaimable = claimerProofs.data?.maxClaimable
if (snapshotClaimable) {
if (snapshotClaimable === '0') {
// allowed unlimited for the snapshot
bnMaxClaimable = BigNumber.from(1_000_000)
} else {
try {
bnMaxClaimable = BigNumber.from(snapshotClaimable)
} catch (e) {
// fall back to default case
}
}
}
let max
if (totalAvailableSupply.lt(bnMaxClaimable)) {
max = totalAvailableSupply
} else {
max = bnMaxClaimable
}
if (max.gte(1_000_000)) {
return 1_000_000
}
return max.toNumber()
}, [
claimerProofs.data?.maxClaimable,
totalAvailableSupply,
activeClaimCondition.data?.maxClaimableSupply,
activeClaimCondition.data?.maxClaimablePerWallet,
])
const isSoldOut = useMemo(() => {
try {
return (
(activeClaimCondition.isSuccess &&
BigNumber.from(
activeClaimCondition.data?.availableSupply || 0
).lte(0)) ||
numberClaimed === numberTotal
)
} catch (e) {
return false
}
}, [
activeClaimCondition.data?.availableSupply,
activeClaimCondition.isSuccess,
numberClaimed,
numberTotal,
])
const canClaim = useMemo(() => {
return (
activeClaimCondition.isSuccess &&
claimIneligibilityReasons.isSuccess &&
claimIneligibilityReasons.data?.length === 0 &&
!isSoldOut
)
}, [
activeClaimCondition.isSuccess,
claimIneligibilityReasons.data?.length,
claimIneligibilityReasons.isSuccess,
isSoldOut,
])
const isLoading = useMemo(() => {
return (
activeClaimCondition.isLoading ||
claimedSupply.isLoading ||
!editionDrop
)
}, [activeClaimCondition.isLoading, editionDrop, claimedSupply.isLoading])
const buttonLoading = useMemo(
() => isLoading || claimIneligibilityReasons.isLoading,
[claimIneligibilityReasons.isLoading, isLoading]
)
const buttonText = useMemo(() => {
if (isSoldOut) {
return 'Sold Out'
}
if (canClaim) {
const pricePerToken = BigNumber.from(
activeClaimCondition.data?.currencyMetadata.value || 0
)
if (pricePerToken.eq(0)) {
return 'Mint (Free)'
}
return `Mint (${priceToMint})`
}
if (claimIneligibilityReasons.data?.length) {
return parseIneligibility(claimIneligibilityReasons.data, quantity)
}
if (buttonLoading) {
return 'Checking eligibility...'
}
return 'Claiming not available'
}, [
isSoldOut,
canClaim,
claimIneligibilityReasons.data,
buttonLoading,
activeClaimCondition.data?.currencyMetadata.value,
priceToMint,
quantity,
])
return (
<>
<Navigation />
<div className={styles.container}>
<div className={styles.mintInfoContainer}>
{isLoading ? (
<Text b size={'$3xl'}>
Loading... Letz get crackin!
</Text>
) : (
<>
<Container>
<Grid.Container
css={{
paddingLeft: '10%',
paddingRight: '10%',
paddingTop: '10%',
paddingBottom: '3%',
textAlign: 'left',
}}
>
<Grid>
<Text size={'$3xl'} hideIn={'xs'}>
What‘s crackin? Deez Eggz are
more than your average free range
source of protein. Cultivated from
the greatest wl farmers this side of
the Mississippi, not even Ol‘
McDonald could guess what‘s
inside...
</Text>
<Text size={'$2xl'} showIn={'xs'}>
What‘s crackin? Deez Eggz are
more than your average free range
source of protein. Cultivated from
the greatest wl farmers this side of
the Mississippi, not even Ol‘
McDonald could guess what‘s
inside...
</Text>
</Grid>
</Grid.Container>
<Grid.Container
css={{
paddingLeft: '10%',
paddingRight: '10%',
}}
>
<Grid
css={{
textAlign: 'left',
display: 'block !important',
}}
xs={12}
sm={9}
>
<Text size={'$3xl'} hideIn={'xs'}>
Not your average free range...
</Text>
<Text size={'$3xl'} hideIn={'xs'}>
this is the collection of 6900
generated NFTs of Deez Eggz.
</Text>
<Text b size={'$3xl'} hideIn={'xs'}>
Total Minted
</Text>
<Text
size={'$2xl'}
showIn={'xs'}
css={{ paddingTop: '10%' }}
>
Not your average free range...
</Text>
<Text
css={{ paddingBottom: '10%' }}
size={'$2xl'}
showIn={'xs'}
>
this is the collection of 6900
generated NFTs of Deez Eggz.
</Text>
<Text b size={'$2xl'} showIn={'xs'}>
Total Minted
</Text>
<div>
{claimedSupply ? (
<Text b size={'$3xl'}>
<b>{numberClaimed}</b>
{' / '}
{numberTotal}
</Text>
) : (
<Text b size={'$3xl'}>
Loading... Letz get crackin!
</Text>
)}
</div>
<div>
{/* Amount claimed so far */}
{claimConditions.data?.length ===
0 ||
claimConditions.data?.every(
(cc) =>
cc.maxClaimableSupply ===
'0'
) ? (
<div>
<Text h2 b size={'$3xl'}>
This drop is not ready
to be minted yet. (No
claim condition set)
</Text>
</div>
) : !activeClaimCondition.data &&
claimConditions.data ? (
<div>
<Text h2 b size={'$3xl'}>
Drop starts in:
</Text>
<Timer
date={
claimConditions
.data[0]
.startTime
}
/>
</div>
) : (
<>
<div className="display">
<Button
color="warning"
auto
css={{
marginRight:
'2rem',
}}
onPress={() =>
setQuantity(
quantity - 1
)
}
disabled={
quantity <= 1
}
>
<Text
b
size={'$3xl'}
>
-
</Text>
</Button>
<Text b size={'$3xl'}>
{quantity}
</Text>
<Button
color="warning"
auto
css={{
marginLeft:
'2rem',
}}
onPress={() =>
setQuantity(
quantity + 1
)
}
disabled={
quantity >=
maxClaimable
}
>
<Text
b
size={'$3xl'}
>
+
</Text>
</Button>
</div>
<div>
{isSoldOut ? (
<div>
<Text
h2
b
size={
'$3xl'
}
>
Mint not
live.
</Text>
</div>
) : (
<Web3Button
className="button"
contractAddress={
editionDrop?.getAddress() ||
''
}
action={(
cntr
) =>
cntr.erc1155.claim(
tokenId,
quantity
)
}
isDisabled={
!canClaim ||
buttonLoading
}
onError={(
err
) => {
console.error(
err
)
alert(
'Error claiming NFTs'
)
}}
onSuccess={() => {
setQuantity(
1
)
alert(
'Successfully claimed NFTs'
)
}}
>
{buttonLoading
? 'Loading...'
: buttonText}
</Web3Button>
)}
</div>
</>
)}
</div>
</Grid>
{/* <Spacer x={13} /> */}
<Grid xs={0} sm={3}>
{/* Image */}
<MediaRenderer
src={contractMetadata?.image}
alt={`${contractMetadata?.name} preview image`}
/>
</Grid>
</Grid.Container>
</Container>
</>
)}
</div>
</div>
</>
)
}
export default Home