@@ -4,7 +4,6 @@ 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"
8
7
import { MetaMaskInpageProvider } from "@metamask/providers" ;
9
8
import { useChain } from '@interchain-kit/react'
10
9
import { WalletState } from "@interchain-kit/core"
@@ -64,14 +63,15 @@ export default function WalletPage() {
64
63
if ( ! ethereum ) return
65
64
try {
66
65
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 ) )
75
75
} catch ( err : any ) {
76
76
console . error ( "Failed to get balance:" , err )
77
77
setError ( err . message || "Failed to get balance" )
@@ -107,7 +107,7 @@ export default function WalletPage() {
107
107
108
108
// Wait for confirmation
109
109
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
111
111
112
112
// Update balance
113
113
await getBalance ( )
@@ -243,3 +243,22 @@ export default function WalletPage() {
243
243
</ main >
244
244
)
245
245
}
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