@@ -28,6 +28,7 @@ export default function WalletPage() {
28
28
const [ recipient , setRecipient ] = useState ( "" )
29
29
const [ amount , setAmount ] = useState < number > ( 0 )
30
30
const [ error , setError ] = useState ( "" )
31
+ const [ txLink , setTxLink ] = useState ( "" ) // ← add success link state
31
32
const [ ethereum , setEthereum ] = useState < EthereumProvider > ( )
32
33
33
34
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() {
89
90
const sendTransaction = async ( ) => {
90
91
setIsLoading ( true )
91
92
setError ( "" )
93
+ setTxLink ( "" ) // ← clear old link
92
94
93
95
try {
94
96
if ( ! recipient || amount <= 0 ) {
@@ -100,18 +102,12 @@ export default function WalletPage() {
100
102
}
101
103
102
104
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 ) }
111
106
const transaction = await signer . send ( tx )
112
107
113
108
// Wait for confirmation
114
109
await transaction . wait ( )
110
+ setTxLink ( `${ CHAIN_INFO . blockExplorerUrls [ 0 ] } /tx/${ transaction . txHash } ` ) // ← set explorer link
115
111
116
112
// Update balance
117
113
await getBalance ( )
@@ -230,6 +226,20 @@ export default function WalletPage() {
230
226
{ error }
231
227
</ Callout >
232
228
) }
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
+ ) }
233
243
</ main >
234
244
)
235
245
}
0 commit comments