1+ import React from 'react' ;
2+ import { Box , Text , Button } from '@interchain-ui/react' ;
3+ import { useGetBalance } from './codegen/cosmos/bank/v1beta1/query.rpc.react' ;
4+
5+ export const BalanceTestStandalone : React . FC = ( ) => {
6+ // Hardcoded test wallet address
7+ const testAddress = 'osmo1hcp508gngdnpls4z76nlx78zuadqpyypq8t6as' ;
8+ const [ selectedDenom , setSelectedDenom ] = React . useState < string > ( 'uosmo' ) ;
9+
10+ // Use the codegen hook to get balance
11+ const {
12+ data : balanceData ,
13+ isLoading,
14+ error,
15+ refetch,
16+ isRefetching
17+ } = useGetBalance ( {
18+ request : {
19+ address : testAddress ,
20+ denom : selectedDenom ,
21+ } ,
22+ options : {
23+ enabled : true ,
24+ refetchInterval : 30000 , // Refetch every 30 seconds
25+ } ,
26+ } ) ;
27+
28+ const denomOptions = [ 'uosmo' , 'uion' , 'uusdc' , 'uatom' ] ;
29+
30+ return (
31+ < Box
32+ p = "$6"
33+ borderRadius = "$lg"
34+ backgroundColor = "$cardBg"
35+ border = "1px solid $borderColor"
36+ maxWidth = "600px"
37+ mx = "auto"
38+ mt = "$8"
39+ >
40+ < Text fontSize = "$xl" fontWeight = "$bold" mb = "$4" >
41+ Standalone Balance Test (No Wallet Connection)
42+ </ Text >
43+
44+ < Box mb = "$4" p = "$3" backgroundColor = "$gray50" borderRadius = "$md" >
45+ < Text fontSize = "$sm" color = "$textSecondary" mb = "$1" >
46+ Test Address (Osmosis Testnet):
47+ </ Text >
48+ < Text fontSize = "$xs" fontFamily = "$mono" wordBreak = "break-all" >
49+ { testAddress }
50+ </ Text >
51+ </ Box >
52+
53+ < Box mb = "$4" >
54+ < Text fontSize = "$sm" fontWeight = "$medium" mb = "$2" >
55+ Select Denomination:
56+ </ Text >
57+ < Box display = "flex" gap = "$2" flexWrap = "wrap" >
58+ { denomOptions . map ( ( denom ) => (
59+ < Button
60+ key = { denom }
61+ size = "sm"
62+ variant = { selectedDenom === denom ? 'primary' : 'secondary' }
63+ onClick = { ( ) => setSelectedDenom ( denom ) }
64+ >
65+ { denom }
66+ </ Button >
67+ ) ) }
68+ </ Box >
69+ </ Box >
70+
71+ < Box mb = "$4" >
72+ < Text fontSize = "$sm" fontWeight = "$medium" mb = "$2" >
73+ Query Status:
74+ </ Text >
75+
76+ { isLoading && (
77+ < Text color = "$blue500" fontSize = "$sm" >
78+ 🔄 Loading balance for { selectedDenom } ...
79+ </ Text >
80+ ) }
81+
82+ { isRefetching && ! isLoading && (
83+ < Text color = "$blue500" fontSize = "$sm" >
84+ 🔄 Refreshing...
85+ </ Text >
86+ ) }
87+
88+ { error && (
89+ < Box p = "$3" backgroundColor = "$red50" borderRadius = "$md" >
90+ < Text color = "$red500" fontSize = "$sm" >
91+ ❌ Error: { error . message || 'Failed to fetch balance' }
92+ </ Text >
93+ </ Box >
94+ ) }
95+
96+ { balanceData && ! isLoading && (
97+ < Box p = "$3" backgroundColor = "$green50" borderRadius = "$md" >
98+ < Text color = "$green600" fontSize = "$sm" mb = "$2" >
99+ ✅ Balance Query Successful
100+ </ Text >
101+ < Box p = "$2" backgroundColor = "white" borderRadius = "$sm" >
102+ < Text fontSize = "$sm" fontFamily = "$mono" >
103+ Denom: { balanceData . balance ?. denom || selectedDenom }
104+ </ Text >
105+ < Text fontSize = "$sm" fontFamily = "$mono" >
106+ Amount: { balanceData . balance ?. amount || '0' }
107+ </ Text >
108+ { balanceData . balance ?. amount && balanceData . balance . amount !== '0' && (
109+ < Text fontSize = "$xs" color = "$textSecondary" mt = "$1" >
110+ = { ( parseInt ( balanceData . balance . amount ) / 1_000_000 ) . toFixed ( 6 ) } { selectedDenom . replace ( 'u' , '' ) . toUpperCase ( ) }
111+ </ Text >
112+ ) }
113+ </ Box >
114+ </ Box >
115+ ) }
116+
117+ { balanceData && ! error && ! balanceData . balance && (
118+ < Box p = "$3" backgroundColor = "$gray100" borderRadius = "$md" >
119+ < Text fontSize = "$sm" color = "$textSecondary" >
120+ No balance found for { selectedDenom }
121+ </ Text >
122+ </ Box >
123+ ) }
124+ </ Box >
125+
126+ < Box display = "flex" gap = "$2" >
127+ < Button
128+ size = "sm"
129+ variant = "primary"
130+ onClick = { ( ) => refetch ( ) }
131+ disabled = { isLoading || isRefetching }
132+ >
133+ { isRefetching ? 'Refreshing...' : 'Refresh Balance' }
134+ </ Button >
135+ </ Box >
136+
137+ < Box mt = "$4" p = "$3" backgroundColor = "$gray50" borderRadius = "$md" >
138+ < Text fontSize = "$xs" color = "$textSecondary" mb = "$1" >
139+ < strong > Test Details:</ strong >
140+ </ Text >
141+ < Text fontSize = "$xs" color = "$textSecondary" >
142+ • Using codegen hook: useGetBalance
143+ </ Text >
144+ < Text fontSize = "$xs" color = "$textSecondary" >
145+ • No wallet connection required
146+ </ Text >
147+ < Text fontSize = "$xs" color = "$textSecondary" >
148+ • Direct RPC query to Osmosis testnet
149+ </ Text >
150+ < Text fontSize = "$xs" color = "$textSecondary" >
151+ • Auto-refresh every 30 seconds
152+ </ Text >
153+ </ Box >
154+ </ Box >
155+ ) ;
156+ } ;
0 commit comments