@@ -22,6 +22,7 @@ import {
22
22
} from "@chakra-ui/react" ;
23
23
import { css , Global } from "@emotion/react" ;
24
24
import { BigNumber , BigNumberish } from "ethers" ;
25
+ import { formatUnits , parseUnits } from "ethers/lib/utils" ;
25
26
import React , { useEffect , useMemo , useState } from "react" ;
26
27
import ReactDOM from "react-dom" ;
27
28
import { IoDiamondOutline } from "react-icons/io5" ;
@@ -31,19 +32,18 @@ import {
31
32
useMutation ,
32
33
useQuery ,
33
34
} from "react-query" ;
34
- import { ConnectedWallet } from "../shared/connected-wallet" ;
35
35
import { Provider , useNetwork } from "wagmi" ;
36
36
import { ConnectWalletButton } from "../shared/connect-wallet-button" ;
37
+ import { ConnectedWallet } from "../shared/connected-wallet" ;
37
38
import { Footer } from "../shared/footer" ;
38
39
import { NftCarousel } from "../shared/nft-carousel" ;
40
+ import { parseError } from "../shared/parseError" ;
39
41
import { DropSvg } from "../shared/svg/drop" ;
40
42
import chakraTheme from "../shared/theme" ;
41
43
import { fontsizeCss } from "../shared/theme/typography" ;
42
- import { useFormatedValue } from "../shared/tokenHooks" ;
43
44
import { useAddress } from "../shared/useAddress" ;
44
45
import { useConnectors } from "../shared/useConnectors" ;
45
46
import { useSDKWithSigner } from "../shared/useSdkWithSigner" ;
46
- import { parseError } from "../shared/parseError" ;
47
47
48
48
function parseHugeNumber ( totalAvailable : BigNumberish = 0 ) {
49
49
const bn = BigNumber . from ( totalAvailable ) ;
@@ -82,7 +82,7 @@ interface HeaderProps extends ModuleInProps {
82
82
}
83
83
84
84
const Header : React . FC < HeaderProps > = ( {
85
- sdk,
85
+ sdk,
86
86
tokenAddress,
87
87
activeTab,
88
88
setActiveTab,
@@ -94,7 +94,7 @@ const Header: React.FC<HeaderProps> = ({
94
94
const [ { data : network } ] = useNetwork ( ) ;
95
95
const chainId = useMemo ( ( ) => network ?. chain ?. id , [ network ] ) ;
96
96
97
- const isEnabled = ! ! module && ! ! address && chainId === expectedChainId
97
+ const isEnabled = ! ! module && ! ! address && chainId === expectedChainId ;
98
98
99
99
const activeButtonProps : ButtonProps = {
100
100
borderBottom : "4px solid" ,
@@ -176,36 +176,38 @@ const ClaimButton: React.FC<ClaimPageProps> = ({
176
176
const [ { data : network } ] = useNetwork ( ) ;
177
177
const chainId = useMemo ( ( ) => network ?. chain ?. id , [ network ] ) ;
178
178
const [ claimSuccess , setClaimSuccess ] = useState ( false ) ;
179
+ const [ quantity , setQuantity ] = useState ( 1 ) ;
179
180
180
- const isEnabled = ! ! module && ! ! address && chainId === expectedChainId
181
+ const isEnabled = ! ! module && ! ! address && chainId === expectedChainId ;
181
182
182
183
const activeClaimCondition = useQuery (
183
184
[ "claim-condition" , { tokenId } ] ,
184
185
( ) => module ?. claimConditions . getActive ( tokenId ) ,
185
186
{ enabled : isEnabled && tokenId . length > 0 } ,
186
187
) ;
187
188
188
- const [ quantity , setQuantity ] = useState ( 1 ) ;
189
- const priceToMint = BigNumber . from (
190
- activeClaimCondition ?. data ?. price || 0 ,
191
- ) . mul ( quantity ) ;
192
- const currency = activeClaimCondition ?. data ?. currencyAddress ;
193
- const claimed = activeClaimCondition . data ?. availableSupply || "0" ;
194
- const totalAvailable = activeClaimCondition . data ?. maxQuantity ?. toString ( ) || "0" ;
195
-
196
- const tokenModule = useMemo ( ( ) => {
197
- if ( ! currency || ! sdk ) {
198
- return undefined ;
199
- }
200
- return sdk . getTokenContract ( currency ) ;
201
- } , [ currency , sdk ] ) ;
189
+ const claimConditionReasons = useQuery (
190
+ [ "ineligiblereasons" , { tokenId, quantity, address } ] ,
191
+ ( ) =>
192
+ module ?. claimConditions . getClaimIneligibilityReasons (
193
+ tokenId ,
194
+ quantity ,
195
+ address ,
196
+ ) ,
197
+ { enabled : ! ! module && ! ! address } ,
198
+ ) ;
202
199
203
- const formatedPrice = useFormatedValue (
204
- priceToMint ,
205
- tokenModule ,
206
- expectedChainId ,
200
+ const bnPrice = parseUnits (
201
+ activeClaimCondition . data ?. currencyMetadata . displayValue || "0" ,
202
+ activeClaimCondition . data ?. currencyMetadata . decimals ,
207
203
) ;
208
204
205
+ const priceToMint = bnPrice . mul ( quantity ) ;
206
+
207
+ const claimed = activeClaimCondition . data ?. availableSupply || "0" ;
208
+ const totalAvailable =
209
+ activeClaimCondition . data ?. maxQuantity ?. toString ( ) || "0" ;
210
+
209
211
const isNotSoldOut = parseInt ( claimed ) < parseInt ( totalAvailable ) ;
210
212
211
213
useEffect ( ( ) => {
@@ -244,9 +246,11 @@ const ClaimButton: React.FC<ClaimPageProps> = ({
244
246
} ,
245
247
) ;
246
248
247
- const isLoading = activeClaimCondition . isLoading ;
249
+ const isLoading =
250
+ activeClaimCondition . isLoading || claimConditionReasons . isLoading ;
248
251
249
- const canClaim = isNotSoldOut && address ;
252
+ const canClaim =
253
+ ! ! isNotSoldOut && ! ! address && ! claimConditionReasons . data ?. length ;
250
254
251
255
const quantityLimit =
252
256
activeClaimCondition ?. data ?. quantityLimitPerTransaction || 1 ;
@@ -269,9 +273,7 @@ const ClaimButton: React.FC<ClaimPageProps> = ({
269
273
quantityLimitBigNumber . lte ( 1000 ) ;
270
274
271
275
if ( ! isEnabled ) {
272
- return (
273
- < ConnectWalletButton expectedChainId = { expectedChainId } />
274
- )
276
+ return < ConnectWalletButton expectedChainId = { expectedChainId } /> ;
275
277
}
276
278
277
279
return (
@@ -311,13 +313,18 @@ const ClaimButton: React.FC<ClaimPageProps> = ({
311
313
{ ! isNotSoldOut
312
314
? "Sold out"
313
315
: canClaim
314
- ? `Mint${
315
- priceToMint . eq ( 0 )
316
+ ? `Mint${ showQuantityInput ? ` ${ quantity } ` : "" } ${
317
+ activeClaimCondition . data ?. price . eq ( 0 )
316
318
? " (Free)"
317
- : formatedPrice
318
- ? ` (${ formatedPrice } )`
319
+ : activeClaimCondition . data ?. currencyMetadata . displayValue
320
+ ? ` (${ formatUnits (
321
+ priceToMint ,
322
+ activeClaimCondition . data . currencyMetadata . decimals ,
323
+ ) } ${ activeClaimCondition . data ?. currencyMetadata . symbol } )`
319
324
: ""
320
325
} `
326
+ : claimConditionReasons . data ?. length
327
+ ? claimConditionReasons . data [ 0 ]
321
328
: "Minting Unavailable" }
322
329
</ Button >
323
330
</ Flex >
@@ -496,7 +503,8 @@ const DropWidget: React.FC<DropWidgetProps> = ({
496
503
) ;
497
504
498
505
const claimed = activeClaimCondition . data ?. availableSupply || "0" ;
499
- const totalAvailable = BigNumber . from ( activeClaimCondition . data ?. maxQuantity ) . toString ( ) || "0" ;
506
+ const totalAvailable =
507
+ BigNumber . from ( activeClaimCondition . data ?. maxQuantity ) . toString ( ) || "0" ;
500
508
501
509
const owned = useQuery (
502
510
[ "numbers" , "owned" , { address } ] ,
0 commit comments