@@ -4,7 +4,6 @@ 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"
87import { MetaMaskInpageProvider } from "@metamask/providers" ;
98import { useChain } from '@interchain-kit/react'
109import { WalletState } from "@interchain-kit/core"
@@ -64,14 +63,15 @@ export default function WalletPage() {
6463 if ( ! ethereum ) return
6564 try {
6665 console . log ( 'ethereum in getBalance:' , ethereum )
67- const wallet = new SignerFromBrowser (
68- ethereum !
69- // window.ethereum as EthereumProvider
70- )
71- console . log ( 'wallet in getBalance:' , wallet )
72- const balance = await wallet . getBalance ( )
73- console . log ( 'balance in getBalance:' , balance )
74- setBalance ( formatEther ( balance ) )
66+ // Use EIP-1193 provider directly to fetch balance
67+ const addr = account
68+ if ( ! addr ) throw new Error ( 'No connected account' )
69+ const hexBalance = await ( ethereum as any ) . request ( {
70+ method : 'eth_getBalance' ,
71+ params : [ addr , 'latest' ]
72+ } ) as string
73+ const wei = BigInt ( hexBalance )
74+ setBalance ( formatEther ( wei ) )
7575 } catch ( err : any ) {
7676 console . error ( "Failed to get balance:" , err )
7777 setError ( err . message || "Failed to get balance" )
@@ -107,7 +107,7 @@ export default function WalletPage() {
107107
108108 // Wait for confirmation
109109 await transaction . wait ( )
110- setTxLink ( `${ CHAIN_INFO . blockExplorerUrls [ 0 ] } /tx/${ transaction . txHash } ` ) // ← set explorer link
110+ setTxLink ( `${ CHAIN_INFO . blockExplorerUrls [ 0 ] } /tx/${ transaction . transactionHash } ` ) // ← set explorer link
111111
112112 // Update balance
113113 await getBalance ( )
@@ -243,3 +243,22 @@ export default function WalletPage() {
243243 </ main >
244244 )
245245}
246+
247+ // Minimal helpers for ETH denominations (18 decimals)
248+ const WEI_PER_ETHER = 10n ** 18n
249+ function parseEther ( value : number | string ) : bigint {
250+ const str = typeof value === 'number' ? value . toString ( ) : value
251+ if ( ! str . includes ( '.' ) ) return BigInt ( str ) * WEI_PER_ETHER
252+ const [ whole , fracRaw ] = str . split ( '.' )
253+ const frac = ( fracRaw || '' ) . slice ( 0 , 18 ) . padEnd ( 18 , '0' )
254+ return BigInt ( whole || '0' ) * WEI_PER_ETHER + BigInt ( frac || '0' )
255+ }
256+
257+ function formatEther ( wei : bigint ) : string {
258+ const negative = wei < 0n
259+ const n = negative ? - wei : wei
260+ const whole = n / WEI_PER_ETHER
261+ const frac = n % WEI_PER_ETHER
262+ const fracStr = frac . toString ( ) . padStart ( 18 , '0' ) . replace ( / 0 + $ / , '' )
263+ return `${ negative ? '-' : '' } ${ whole . toString ( ) } ${ fracStr ? '.' + fracStr : '' } `
264+ }
0 commit comments