@@ -4,12 +4,14 @@ import { Box, Button, TextField, NumberField, FieldLabel, Callout } from "@inter
4
4
import React , { useState , useEffect } from "react"
5
5
import { Wallet , ArrowRight , RefreshCw , AlertCircle } from "lucide-react"
6
6
import { SignerFromBrowser } from "@interchainjs/ethereum/signers/SignerFromBrowser"
7
+ import { parseEther , formatEther } from "@interchainjs/ethereum/utils/denominations"
7
8
import { MetaMaskInpageProvider } from "@metamask/providers" ;
8
- import BigNumber from "bignumber.js" ;
9
9
import { useChain } from '@interchain-kit/react'
10
10
import { WalletState } from "@interchain-kit/core"
11
11
import { BSC_TESTNET , HOLESKY_TESTNET , SEPOLIA_TESTNET } from "./provider"
12
12
13
+ const CHAIN_INFO = SEPOLIA_TESTNET
14
+
13
15
type EthereumProvider = MetaMaskInpageProvider
14
16
15
17
// Alias Card components
@@ -26,16 +28,17 @@ export default function WalletPage() {
26
28
const [ recipient , setRecipient ] = useState ( "" )
27
29
const [ amount , setAmount ] = useState < number > ( 0 )
28
30
const [ error , setError ] = useState ( "" )
31
+ const [ txLink , setTxLink ] = useState ( "" ) // ← add success link state
29
32
const [ ethereum , setEthereum ] = useState < EthereumProvider > ( )
30
33
31
- const { wallet, status, connect, address : account , disconnect } = useChain ( SEPOLIA_TESTNET . chainName ) // chain name must be same as getProvider chain id
34
+ const { wallet, status, connect, address : account , disconnect } = useChain ( CHAIN_INFO . chainName ) // chain name must be same as getProvider chain id
32
35
33
36
useEffect ( ( ) => {
34
37
console . log ( 'status from useChain:' , status )
35
38
if ( status === WalletState . Connected ) {
36
39
const setEthProviderFromWallet = async ( ) => {
37
40
await new Promise ( resolve => setTimeout ( resolve , 500 ) )
38
- const ethProviderFromWallet = await wallet . getProvider ( SEPOLIA_TESTNET . chainId ) as EthereumProvider
41
+ const ethProviderFromWallet = await wallet . getProvider ( CHAIN_INFO . chainId ) as EthereumProvider
39
42
console . log ( "Ethereum provider:" , ethProviderFromWallet )
40
43
setEthereum ( ethProviderFromWallet )
41
44
}
@@ -68,7 +71,7 @@ export default function WalletPage() {
68
71
console . log ( 'wallet in getBalance:' , wallet )
69
72
const balance = await wallet . getBalance ( )
70
73
console . log ( 'balance in getBalance:' , balance )
71
- setBalance ( new BigNumber ( balance . toString ( ) ) . div ( 10 ** 18 ) . toString ( ) )
74
+ setBalance ( formatEther ( balance ) )
72
75
} catch ( err : any ) {
73
76
console . error ( "Failed to get balance:" , err )
74
77
setError ( err . message || "Failed to get balance" )
@@ -87,6 +90,7 @@ export default function WalletPage() {
87
90
const sendTransaction = async ( ) => {
88
91
setIsLoading ( true )
89
92
setError ( "" )
93
+ setTxLink ( "" ) // ← clear old link
90
94
91
95
try {
92
96
if ( ! recipient || amount <= 0 ) {
@@ -98,18 +102,12 @@ export default function WalletPage() {
98
102
}
99
103
100
104
const signer = new SignerFromBrowser ( ethereum ! )
101
-
102
- // Create transaction
103
- const tx = {
104
- to : recipient ,
105
- value : BigInt ( new BigNumber ( amount ) . shiftedBy ( 18 ) . integerValue ( BigNumber . ROUND_DOWN ) . toString ( ) )
106
- }
107
-
108
- // Send transaction
105
+ const tx = { to : recipient , value : parseEther ( amount ) }
109
106
const transaction = await signer . send ( tx )
110
107
111
108
// Wait for confirmation
112
109
await transaction . wait ( )
110
+ setTxLink ( `${ CHAIN_INFO . blockExplorerUrls [ 0 ] } /tx/${ transaction . txHash } ` ) // ← set explorer link
113
111
114
112
// Update balance
115
113
await getBalance ( )
@@ -228,6 +226,20 @@ export default function WalletPage() {
228
226
{ error }
229
227
</ Callout >
230
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
+ ) }
231
243
</ main >
232
244
)
233
245
}
0 commit comments