Skip to content

Commit efc6aee

Browse files
test pr
1 parent e8bf330 commit efc6aee

File tree

6 files changed

+500
-55
lines changed

6 files changed

+500
-55
lines changed

templates/chain-template/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ yarn-error.log*
3434
# typescript
3535
*.tsbuildinfo
3636
next-env.d.ts
37+
38+
# codegen
39+
/components/codegen
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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+
};

templates/chain-template/next.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,16 @@ module.exports = {
2121
},
2222
],
2323
},
24+
async headers() {
25+
return [
26+
{
27+
source: '/api/:path*',
28+
headers: [
29+
{ key: 'Access-Control-Allow-Origin', value: '*' },
30+
{ key: 'Access-Control-Allow-Methods', value: 'GET, POST, PUT, DELETE, OPTIONS' },
31+
{ key: 'Access-Control-Allow-Headers', value: 'Content-Type, Authorization' },
32+
],
33+
},
34+
];
35+
},
2436
};

templates/chain-template/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"@interchain-kit/react": "0.3.41",
3030
"@interchain-ui/react": "1.23.31",
3131
"@interchain-ui/react-no-ssr": "0.1.2",
32-
"@interchainjs/cosmos": "1.11.2",
33-
"@interchainjs/react": "1.11.2",
32+
"@interchainjs/cosmos": "1.13.0",
33+
"@interchainjs/react": "1.13.0",
3434
"@keplr-wallet/cosmos": "^0.12.44",
3535
"@tanstack/react-query": "4.32.0",
3636
"ace-builds": "1.35.0",

templates/chain-template/pages/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useChain } from '@interchain-kit/react';
55
import { Button } from '@/components';
66
import { useChainStore } from '@/contexts';
77
import { useDetectBreakpoints } from '@/hooks';
8+
import { BalanceTestStandalone } from '@/components/balance-test-standalone';
89

910
export default function Home() {
1011
const { isMobile } = useDetectBreakpoints();
@@ -34,6 +35,9 @@ export default function Home() {
3435
<HighlightText>Next.js</HighlightText>
3536
</Text>
3637
<ConnectButton />
38+
{/* Standalone Balance Test Component */}
39+
<BalanceTestStandalone />
40+
3741
<Box
3842
display="flex"
3943
justifyContent="center"

0 commit comments

Comments
 (0)