Skip to content

Commit 0c16591

Browse files
committed
fix: keep mint success ui after rerender
1 parent 44e747c commit 0c16591

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

app/[locale]/10years/_components/NFTMintCard/Mint.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useEffect } from "react"
12
import { Address } from "viem"
23
import {
34
useEnsName,
@@ -14,7 +15,12 @@ import Connected from "./Connected"
1415
import { useNetworkContract } from "@/hooks/useNetworkContract"
1516
import { getErrorMessage } from "@/lib/torch"
1617

17-
export default function Mint({ address }: { address: Address }) {
18+
interface MintProps {
19+
address: Address
20+
onSuccess?: (txHash: string) => void
21+
}
22+
23+
export default function Mint({ address, onSuccess }: MintProps) {
1824
const { data: ensName } = useEnsName({ address })
1925
const { contractData, isSupportedNetwork } = useNetworkContract()
2026

@@ -39,6 +45,12 @@ export default function Mint({ address }: { address: Address }) {
3945
},
4046
})
4147

48+
useEffect(() => {
49+
if (isConfirmed && hash && onSuccess) {
50+
onSuccess(hash)
51+
}
52+
}, [isConfirmed, hash, onSuccess])
53+
4254
const handleMintClick = async () => {
4355
mint({
4456
address: contractData.address as `0x${string}`,

app/[locale]/10years/_components/NFTMintCard/Prechecks.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import { useState } from "react"
12
import { Address } from "viem"
23
import { useReadContract } from "wagmi"
34

45
import MintAlreadyMinted from "./views/MintAlreadyMinted"
6+
import MintSuccess from "./views/MintSuccess"
57
import Mint from "./Mint"
68

79
import { useNetworkContract } from "@/hooks/useNetworkContract"
810

911
export default function Prechecks({ address }: { address: Address }) {
1012
const { contractData, isSupportedNetwork } = useNetworkContract()
13+
const [successTxHash, setSuccessTxHash] = useState<string | null>(null)
1114

1215
const { data: hasMinted, error: hasMintedError } = useReadContract({
1316
address: contractData.address,
@@ -19,13 +22,21 @@ export default function Prechecks({ address }: { address: Address }) {
1922
},
2023
})
2124

25+
const handleMintSuccess = (txHash: string) => {
26+
setSuccessTxHash(txHash)
27+
}
28+
2229
if (hasMintedError) {
2330
return <div className="flex justify-center">Error checking minted</div>
2431
}
2532

33+
if (successTxHash) {
34+
return <MintSuccess txHash={successTxHash} />
35+
}
36+
2637
if (hasMinted) {
2738
return <MintAlreadyMinted />
2839
}
2940

30-
return <Mint address={address} />
41+
return <Mint address={address} onSuccess={handleMintSuccess} />
3142
}

0 commit comments

Comments
 (0)