Skip to content

Commit 5085005

Browse files
authored
Merge pull request #15959 from ethereum/fix-perisist-success
fix: keep mint success UI after rerender
2 parents b117431 + 0c16591 commit 5085005

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,
@@ -15,7 +16,12 @@ import GasPriceDisplay from "./GasPriceDisplay"
1516
import { useNetworkContract } from "@/hooks/useNetworkContract"
1617
import { getErrorMessage } from "@/lib/torch"
1718

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) {
1925
const { data: ensName } = useEnsName({ address })
2026
const { contractData, isSupportedNetwork } = useNetworkContract()
2127

@@ -40,6 +46,12 @@ export default function Mint({ address }: { address: Address }) {
4046
},
4147
})
4248

49+
useEffect(() => {
50+
if (isConfirmed && hash && onSuccess) {
51+
onSuccess(hash)
52+
}
53+
}, [isConfirmed, hash, onSuccess])
54+
4355
const handleMintClick = async () => {
4456
mint({
4557
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)