Skip to content

Commit 5cd5850

Browse files
authored
Merge pull request #29 from hyperweb-io/vite-react
Vite react
2 parents 3bc792b + e3f8626 commit 5cd5850

29 files changed

+26545
-21217
lines changed

examples/injective-vue/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
"vite": "^6.0.0",
3232
"vue-tsc": "^2.1.10"
3333
}
34-
}
34+
}

examples/stake-tokens/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
"typescript": "^5.5.4"
4545
},
4646
"packageManager": "[email protected]"
47-
}
47+
}

examples/vite-react/.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

examples/vite-react/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
This is an Interchain App project bootstrapped with [`create-interchain-app`](https://github.com/hyperweb-io/create-interchain-app).
2+
3+
## Getting Started
4+
5+
First, install the packages and run the development server:
6+
7+
```bash
8+
yarn && yarn dev
9+
```
10+
11+
Open [http://localhost:5173](http://localhost:5173) with your browser to see the result.
12+
13+
You can start editing the page by modifying `src/App.tsx`. The page auto-updates as you edit the file.
14+
15+
## Interchain JavaScript Stack
16+
17+
A unified toolkit for building applications and smart contracts in the Interchain ecosystem ⚛️
18+
19+
| Category | Tools | Description |
20+
|----------------------|------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
21+
| **Chain Information** | [**Chain Registry**](https://github.com/hyperweb-io/chain-registry), [**Utils**](https://www.npmjs.com/package/@chain-registry/utils), [**Client**](https://www.npmjs.com/package/@chain-registry/client) | Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application. |
22+
| **Wallet Connectors**| [**Interchain Kit**](https://github.com/hyperweb-io/interchain-kit)<sup>beta</sup>, [**Cosmos Kit**](https://github.com/hyperweb.io/cosmos-kit) | Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface. |
23+
| **Signing Clients** | [**InterchainJS**](https://github.com/hyperweb-io/interchainjs)<sup>beta</sup>, [**CosmJS**](https://github.com/cosmos/cosmjs) | A single, universal signing interface for any network |
24+
| **SDK Clients** | [**Telescope**](https://github.com/hyperweb.io/telescope) | Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules. |
25+
| **Starter Kits** | [**Create Interchain App**](https://github.com/hyperweb-io/create-interchain-app)<sup>beta</sup>, [**Create Cosmos App**](https://github.com/hyperweb.io/create-cosmos-app) | Set up a modern Interchain app by running one command. |
26+
| **UI Kits** | [**Interchain UI**](https://github.com/hyperweb.io/interchain-ui) | The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit. |
27+
| **Testing Frameworks** | [**Starship**](https://github.com/hyperweb.io/starship) | Unified Testing and Development for the Interchain. |
28+
| **TypeScript Smart Contracts** | [**Create Hyperweb App**](https://github.com/hyperweb-io/create-hyperweb-app) | Build and deploy full-stack blockchain applications with TypeScript |
29+
| **CosmWasm Contracts** | [**CosmWasm TS Codegen**](https://github.com/CosmWasm/ts-codegen) | Convert your CosmWasm smart contracts into dev-friendly TypeScript classes. |
30+
31+
## Credits
32+
33+
🛠 Built by Hyperweb (formerly Cosmology) — if you like our tools, please checkout and contribute to [our github ⚛️](https://github.com/hyperweb-io)
34+
35+
## Disclaimer
36+
37+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
38+
39+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.

examples/vite-react/eslint.config.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
7+
export default tseslint.config(
8+
{ ignores: ['dist'] },
9+
{
10+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11+
files: ['**/*.{ts,tsx}'],
12+
languageOptions: {
13+
ecmaVersion: 2020,
14+
globals: globals.browser,
15+
},
16+
plugins: {
17+
'react-hooks': reactHooks,
18+
'react-refresh': reactRefresh,
19+
},
20+
rules: {
21+
...reactHooks.configs.recommended.rules,
22+
'react-refresh/only-export-components': [
23+
'warn',
24+
{ allowConstantExport: true },
25+
],
26+
},
27+
},
28+
)

examples/vite-react/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + TS</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

examples/vite-react/package.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "@hyperweb/vite-react",
3+
"private": true,
4+
"version": "1.0.0",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "tsc -b && vite build",
8+
"lint": "eslint .",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
"@chain-registry/v2": "^1.71.71",
13+
"@chakra-ui/icons": "^2.1.1",
14+
"@chakra-ui/react": "^2.8.2",
15+
"@emotion/react": "^11.11.4",
16+
"@emotion/styled": "^11.11.0",
17+
"@hookform/resolvers": "^3.3.4",
18+
"@interchain-kit/core": "0.2.206",
19+
"@interchain-kit/keplr-extension": "0.2.206",
20+
"@tanstack/react-query": "5.68.0",
21+
"buffer": "^6.0.3",
22+
"framer-motion": "^11.0.8",
23+
"react": "^18.3.1",
24+
"react-dom": "^18.3.1",
25+
"react-hook-form": "^7.51.0",
26+
"zod": "^3.22.4"
27+
},
28+
"devDependencies": {
29+
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
30+
"@eslint/js": "^9.9.1",
31+
"@types/react": "^18.3.5",
32+
"@types/react-dom": "^18.3.0",
33+
"@vitejs/plugin-react": "^4.3.1",
34+
"eslint": "^9.9.1",
35+
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
36+
"eslint-plugin-react-refresh": "^0.4.11",
37+
"globals": "^15.9.0",
38+
"typescript": "^5.5.3",
39+
"typescript-eslint": "^8.3.0",
40+
"vite": "^5.4.2"
41+
},
42+
"packageManager": "[email protected]"
43+
}

examples/vite-react/public/vite.svg

+1
Loading

examples/vite-react/src/App.css

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
transition: filter 300ms;
13+
}
14+
.logo:hover {
15+
filter: drop-shadow(0 0 2em #646cffaa);
16+
}
17+
.logo.react:hover {
18+
filter: drop-shadow(0 0 2em #61dafbaa);
19+
}
20+
21+
@keyframes logo-spin {
22+
from {
23+
transform: rotate(0deg);
24+
}
25+
to {
26+
transform: rotate(360deg);
27+
}
28+
}
29+
30+
@media (prefers-reduced-motion: no-preference) {
31+
a:nth-of-type(2) .logo {
32+
animation: logo-spin infinite 20s linear;
33+
}
34+
}
35+
36+
.card {
37+
padding: 2em;
38+
}
39+
40+
.read-the-docs {
41+
color: #888;
42+
}

examples/vite-react/src/App.tsx

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { useEffect } from 'react';
2+
import {
3+
Box,
4+
Button,
5+
Container,
6+
VStack,
7+
useColorMode,
8+
IconButton,
9+
Heading,
10+
Card,
11+
CardBody,
12+
} from '@chakra-ui/react';
13+
import { SunIcon, MoonIcon } from '@chakra-ui/icons';
14+
import { useForm } from 'react-hook-form';
15+
import { zodResolver } from '@hookform/resolvers/zod';
16+
import WalletDetails from './components/WalletDetails';
17+
import TransferForm from './components/TransferForm';
18+
import { transferFormSchema, type TransferFormData } from './utils/validation';
19+
import { useWalletManager } from './hooks/useWalletManager';
20+
import { useBalance } from './hooks/useBalance';
21+
import { useTransfer } from './hooks/useTransfer';
22+
23+
function App() {
24+
const { colorMode, toggleColorMode } = useColorMode();
25+
const { walletManager, address, connectWallet } = useWalletManager();
26+
const { balance, refetchBalance } = useBalance(address, walletManager);
27+
const transferMutation = useTransfer(address, walletManager, refetchBalance);
28+
29+
const { register, handleSubmit, formState: { errors }, reset } = useForm<TransferFormData>({
30+
resolver: zodResolver(transferFormSchema),
31+
defaultValues: { amount: '0.000001' },
32+
});
33+
34+
const onSubmit = (data: TransferFormData) => {
35+
if (!balance || Number(data.amount) > balance) {
36+
return;
37+
}
38+
transferMutation.mutate(data);
39+
reset();
40+
};
41+
42+
useEffect(() => {
43+
if (walletManager) {
44+
connectWallet();
45+
}
46+
}, [walletManager, connectWallet]);
47+
48+
return (
49+
<Container maxW="container.sm" py={8}>
50+
<VStack spacing={6} align="stretch">
51+
<Box display="flex" justifyContent="flex-end">
52+
<IconButton
53+
aria-label="Toggle color mode"
54+
icon={colorMode === 'light' ? <MoonIcon /> : <SunIcon />}
55+
onClick={toggleColorMode}
56+
/>
57+
</Box>
58+
<Card>
59+
<CardBody>
60+
<VStack spacing={4} align="stretch">
61+
<Heading size="md">Cosmos Wallet</Heading>
62+
{!address ? (
63+
<Button onClick={connectWallet}>Connect Keplr</Button>
64+
) : (
65+
<>
66+
<WalletDetails
67+
address={address}
68+
balance={balance ?? '0'}
69+
onRefresh={refetchBalance}
70+
/>
71+
<TransferForm
72+
register={register}
73+
errors={errors}
74+
handleSubmit={handleSubmit}
75+
onSubmit={onSubmit}
76+
isLoading={transferMutation.isMutating}
77+
/>
78+
</>
79+
)}
80+
</VStack>
81+
</CardBody>
82+
</Card>
83+
</VStack>
84+
</Container>
85+
);
86+
}
87+
88+
export default App;
+1
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { FormControl, FormLabel, Input, Text, VStack, Button } from '@chakra-ui/react';
2+
import { DENOM_DISPLAY } from '../utils/constants';
3+
import { TransferFormData } from '../utils/validation';
4+
5+
interface TransferFormProps {
6+
register: ReturnType<any>;
7+
errors: any;
8+
handleSubmit: (fn: (data: TransferFormData) => void) => (e?: React.BaseSyntheticEvent) => Promise<void>;
9+
onSubmit: (data: TransferFormData) => void;
10+
isLoading: boolean;
11+
}
12+
13+
const TransferForm = ({ register, errors, handleSubmit, onSubmit, isLoading }: TransferFormProps) => {
14+
return (
15+
<form onSubmit={handleSubmit(onSubmit)}>
16+
<VStack spacing={4}>
17+
<FormControl isInvalid={!!errors.recipient}>
18+
<FormLabel>Recipient Address</FormLabel>
19+
<Input {...register('recipient')} />
20+
{errors.recipient && <Text color="red.500">{errors.recipient.message}</Text>}
21+
</FormControl>
22+
<FormControl isInvalid={!!errors.amount}>
23+
<FormLabel>Amount ({DENOM_DISPLAY})</FormLabel>
24+
<Input {...register('amount')} type="number" step="0.000001" />
25+
{errors.amount && <Text color="red.500">{errors.amount.message}</Text>}
26+
</FormControl>
27+
<Button type="submit" colorScheme="blue" isLoading={isLoading} width="100%">
28+
Transfer
29+
</Button>
30+
</VStack>
31+
</form>
32+
);
33+
};
34+
35+
export default TransferForm;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Box, Text, HStack, IconButton } from '@chakra-ui/react';
2+
import { RepeatIcon } from '@chakra-ui/icons';
3+
import { DENOM_DISPLAY } from '../utils/constants';
4+
5+
interface WalletDetailsProps {
6+
address: string;
7+
balance: number | string;
8+
onRefresh: () => void;
9+
}
10+
11+
const WalletDetails = ({ address, balance, onRefresh }: WalletDetailsProps) => {
12+
return (
13+
<Box>
14+
<Text>Address: {address}</Text>
15+
<HStack>
16+
<Text>
17+
Balance: {balance ?? '0'} {DENOM_DISPLAY}
18+
</Text>
19+
<IconButton
20+
aria-label="Refresh balance"
21+
icon={<RepeatIcon />}
22+
size="sm"
23+
onClick={onRefresh}
24+
/>
25+
</HStack>
26+
</Box>
27+
);
28+
};
29+
30+
export default WalletDetails;

0 commit comments

Comments
 (0)