Skip to content

Commit 0e346bb

Browse files
committed
add Callout to show tx result
1 parent 9973592 commit 0e346bb

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

examples/ethereum/app/page.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function WalletPage() {
2828
const [recipient, setRecipient] = useState("")
2929
const [amount, setAmount] = useState<number>(0)
3030
const [error, setError] = useState("")
31+
const [txLink, setTxLink] = useState("") // ← add success link state
3132
const [ethereum, setEthereum] = useState<EthereumProvider>()
3233

3334
const { wallet, status, connect, address: account, disconnect } = useChain(CHAIN_INFO.chainName) // chain name must be same as getProvider chain id
@@ -89,6 +90,7 @@ export default function WalletPage() {
8990
const sendTransaction = async () => {
9091
setIsLoading(true)
9192
setError("")
93+
setTxLink("") // ← clear old link
9294

9395
try {
9496
if (!recipient || amount <= 0) {
@@ -100,18 +102,12 @@ export default function WalletPage() {
100102
}
101103

102104
const signer = new SignerFromBrowser(ethereum!)
103-
104-
// Create transaction
105-
const tx = {
106-
to: recipient,
107-
value: parseEther(amount)
108-
}
109-
110-
// Send transaction
105+
const tx = { to: recipient, value: parseEther(amount) }
111106
const transaction = await signer.send(tx)
112107

113108
// Wait for confirmation
114109
await transaction.wait()
110+
setTxLink(`${CHAIN_INFO.blockExplorerUrls[0]}/tx/${transaction.txHash}`) // ← set explorer link
115111

116112
// Update balance
117113
await getBalance()
@@ -230,6 +226,20 @@ export default function WalletPage() {
230226
{error}
231227
</Callout>
232228
)}
229+
230+
{txLink && ( // ← success message
231+
<Callout title="Success" className="mt-6" intent="success">
232+
Transaction sent.{" "}
233+
<a
234+
href={txLink}
235+
target="_blank"
236+
rel="noopener noreferrer"
237+
className="underline"
238+
>
239+
View on Explorer
240+
</a>
241+
</Callout>
242+
)}
233243
</main>
234244
)
235245
}

0 commit comments

Comments
 (0)