File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
app/[locale]/10years/_components/NFTMintCard Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { useEffect } from "react"
1
2
import { Address } from "viem"
2
3
import {
3
4
useEnsName ,
@@ -15,7 +16,12 @@ import GasPriceDisplay from "./GasPriceDisplay"
15
16
import { useNetworkContract } from "@/hooks/useNetworkContract"
16
17
import { getErrorMessage } from "@/lib/torch"
17
18
18
- export default function Mint ( { address } : { address : Address } ) {
19
+ interface MintProps {
20
+ address : Address
21
+ onSuccess ?: ( txHash : string ) => void
22
+ }
23
+
24
+ export default function Mint ( { address, onSuccess } : MintProps ) {
19
25
const { data : ensName } = useEnsName ( { address } )
20
26
const { contractData, isSupportedNetwork } = useNetworkContract ( )
21
27
@@ -40,6 +46,12 @@ export default function Mint({ address }: { address: Address }) {
40
46
} ,
41
47
} )
42
48
49
+ useEffect ( ( ) => {
50
+ if ( isConfirmed && hash && onSuccess ) {
51
+ onSuccess ( hash )
52
+ }
53
+ } , [ isConfirmed , hash , onSuccess ] )
54
+
43
55
const handleMintClick = async ( ) => {
44
56
mint ( {
45
57
address : contractData . address as `0x${string } `,
Original file line number Diff line number Diff line change
1
+ import { useState } from "react"
1
2
import { Address } from "viem"
2
3
import { useReadContract } from "wagmi"
3
4
4
5
import MintAlreadyMinted from "./views/MintAlreadyMinted"
6
+ import MintSuccess from "./views/MintSuccess"
5
7
import Mint from "./Mint"
6
8
7
9
import { useNetworkContract } from "@/hooks/useNetworkContract"
8
10
9
11
export default function Prechecks ( { address } : { address : Address } ) {
10
12
const { contractData, isSupportedNetwork } = useNetworkContract ( )
13
+ const [ successTxHash , setSuccessTxHash ] = useState < string | null > ( null )
11
14
12
15
const { data : hasMinted , error : hasMintedError } = useReadContract ( {
13
16
address : contractData . address ,
@@ -19,13 +22,21 @@ export default function Prechecks({ address }: { address: Address }) {
19
22
} ,
20
23
} )
21
24
25
+ const handleMintSuccess = ( txHash : string ) => {
26
+ setSuccessTxHash ( txHash )
27
+ }
28
+
22
29
if ( hasMintedError ) {
23
30
return < div className = "flex justify-center" > Error checking minted</ div >
24
31
}
25
32
33
+ if ( successTxHash ) {
34
+ return < MintSuccess txHash = { successTxHash } />
35
+ }
36
+
26
37
if ( hasMinted ) {
27
38
return < MintAlreadyMinted />
28
39
}
29
40
30
- return < Mint address = { address } />
41
+ return < Mint address = { address } onSuccess = { handleMintSuccess } />
31
42
}
You can’t perform that action at this time.
0 commit comments