@@ -4,12 +4,14 @@ import { Box, Button, TextField, NumberField, FieldLabel, Callout } from "@inter
44import React , { useState , useEffect } from "react"
55import { Wallet , ArrowRight , RefreshCw , AlertCircle } from "lucide-react"
66import { SignerFromBrowser } from "@interchainjs/ethereum/signers/SignerFromBrowser"
7+ import { parseEther , formatEther } from "@interchainjs/ethereum/utils/denominations"
78import { MetaMaskInpageProvider } from "@metamask/providers" ;
8- import BigNumber from "bignumber.js" ;
99import { useChain } from '@interchain-kit/react'
1010import { WalletState } from "@interchain-kit/core"
1111import { BSC_TESTNET , HOLESKY_TESTNET , SEPOLIA_TESTNET } from "./provider"
1212
13+ const CHAIN_INFO = SEPOLIA_TESTNET
14+
1315type EthereumProvider = MetaMaskInpageProvider
1416
1517// Alias Card components
@@ -26,16 +28,17 @@ export default function WalletPage() {
2628 const [ recipient , setRecipient ] = useState ( "" )
2729 const [ amount , setAmount ] = useState < number > ( 0 )
2830 const [ error , setError ] = useState ( "" )
31+ const [ txLink , setTxLink ] = useState ( "" ) // ← add success link state
2932 const [ ethereum , setEthereum ] = useState < EthereumProvider > ( )
3033
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
3235
3336 useEffect ( ( ) => {
3437 console . log ( 'status from useChain:' , status )
3538 if ( status === WalletState . Connected ) {
3639 const setEthProviderFromWallet = async ( ) => {
3740 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
3942 console . log ( "Ethereum provider:" , ethProviderFromWallet )
4043 setEthereum ( ethProviderFromWallet )
4144 }
@@ -68,7 +71,7 @@ export default function WalletPage() {
6871 console . log ( 'wallet in getBalance:' , wallet )
6972 const balance = await wallet . getBalance ( )
7073 console . log ( 'balance in getBalance:' , balance )
71- setBalance ( new BigNumber ( balance . toString ( ) ) . div ( 10 ** 18 ) . toString ( ) )
74+ setBalance ( formatEther ( balance ) )
7275 } catch ( err : any ) {
7376 console . error ( "Failed to get balance:" , err )
7477 setError ( err . message || "Failed to get balance" )
@@ -87,6 +90,7 @@ export default function WalletPage() {
8790 const sendTransaction = async ( ) => {
8891 setIsLoading ( true )
8992 setError ( "" )
93+ setTxLink ( "" ) // ← clear old link
9094
9195 try {
9296 if ( ! recipient || amount <= 0 ) {
@@ -98,18 +102,12 @@ export default function WalletPage() {
98102 }
99103
100104 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 ) }
109106 const transaction = await signer . send ( tx )
110107
111108 // Wait for confirmation
112109 await transaction . wait ( )
110+ setTxLink ( `${ CHAIN_INFO . blockExplorerUrls [ 0 ] } /tx/${ transaction . txHash } ` ) // ← set explorer link
113111
114112 // Update balance
115113 await getBalance ( )
@@ -228,6 +226,20 @@ export default function WalletPage() {
228226 { error }
229227 </ Callout >
230228 ) }
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+ ) }
231243 </ main >
232244 )
233245}
0 commit comments