diff --git a/examples/vite-react/package.json b/examples/vite-react/package.json index 1a74109a..cfa48866 100644 --- a/examples/vite-react/package.json +++ b/examples/vite-react/package.json @@ -10,13 +10,12 @@ }, "dependencies": { "@chain-registry/v2": "^1.71.71", - "@chakra-ui/icons": "^2.1.1", - "@chakra-ui/react": "^2.8.2", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.0", "@hookform/resolvers": "^3.3.4", "@interchain-kit/core": "0.2.206", "@interchain-kit/keplr-extension": "0.2.206", + "@interchain-ui/react": "1.26.1", "@tanstack/react-query": "5.68.0", "buffer": "^6.0.3", "framer-motion": "^11.0.8", @@ -40,4 +39,4 @@ "vite": "^5.4.2" }, "packageManager": "yarn@4.3.0" -} +} \ No newline at end of file diff --git a/examples/vite-react/src/App.tsx b/examples/vite-react/src/App.tsx index b58ff637..c739de4d 100644 --- a/examples/vite-react/src/App.tsx +++ b/examples/vite-react/src/App.tsx @@ -1,16 +1,5 @@ import { useEffect } from 'react'; -import { - Box, - Button, - Container, - VStack, - useColorMode, - IconButton, - Heading, - Card, - CardBody, -} from '@chakra-ui/react'; -import { SunIcon, MoonIcon } from '@chakra-ui/icons'; +import { Button, Container, Stack, Text, Box } from '@interchain-ui/react'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import WalletDetails from './components/WalletDetails'; @@ -21,7 +10,6 @@ import { useBalance } from './hooks/useBalance'; import { useTransfer } from './hooks/useTransfer'; function App() { - const { colorMode, toggleColorMode } = useColorMode(); const { walletManager, address, connectWallet } = useWalletManager(); const { balance, refetchBalance } = useBalance(address, walletManager); const transferMutation = useTransfer(address, walletManager, refetchBalance); @@ -46,41 +34,43 @@ function App() { }, [walletManager, connectWallet]); return ( - - - - : } - onClick={toggleColorMode} - /> + + + + + Cosmos Wallet + {!address ? ( + + ) : ( + <> + + + + )} + - - - - Cosmos Wallet - {!address ? ( - - ) : ( - <> - - - - )} - - - - + ); } diff --git a/examples/vite-react/src/components/TransferForm.tsx b/examples/vite-react/src/components/TransferForm.tsx index 2137c9b3..ae5403ad 100644 --- a/examples/vite-react/src/components/TransferForm.tsx +++ b/examples/vite-react/src/components/TransferForm.tsx @@ -1,4 +1,4 @@ -import { FormControl, FormLabel, Input, Text, VStack, Button } from '@chakra-ui/react'; +import { Text, Button, Stack, Box } from '@interchain-ui/react'; import { DENOM_DISPLAY } from '../utils/constants'; import { TransferFormData } from '../utils/validation'; @@ -13,21 +13,24 @@ interface TransferFormProps { const TransferForm = ({ register, errors, handleSubmit, onSubmit, isLoading }: TransferFormProps) => { return (
- - - Recipient Address - - {errors.recipient && {errors.recipient.message}} - - - Amount ({DENOM_DISPLAY}) - - {errors.amount && {errors.amount.message}} - - - +
); }; diff --git a/examples/vite-react/src/components/WalletDetails.tsx b/examples/vite-react/src/components/WalletDetails.tsx index ce0df1e3..2bc07c85 100644 --- a/examples/vite-react/src/components/WalletDetails.tsx +++ b/examples/vite-react/src/components/WalletDetails.tsx @@ -1,6 +1,6 @@ -import { Box, Text, HStack, IconButton } from '@chakra-ui/react'; -import { RepeatIcon } from '@chakra-ui/icons'; +import { Box, Text, IconButton } from '@interchain-ui/react'; import { DENOM_DISPLAY } from '../utils/constants'; +import { useState } from 'react'; interface WalletDetailsProps { address: string; @@ -9,20 +9,29 @@ interface WalletDetailsProps { } const WalletDetails = ({ address, balance, onRefresh }: WalletDetailsProps) => { + const [refreshing, setRefreshing] = useState(false); return ( Address: {address} - +
Balance: {balance ?? '0'} {DENOM_DISPLAY} } size="sm" - onClick={onRefresh} + onClick={() => { + if (refreshing) return; + setRefreshing(true); + setTimeout(() => { + setRefreshing(false); + }, 10000); + onRefresh() + }} + icon='restart' + attributes={{ marginLeft: '$4' }} /> - +
); }; diff --git a/examples/vite-react/src/hooks/useBalance.ts b/examples/vite-react/src/hooks/useBalance.ts index eabc793c..de84edd0 100644 --- a/examples/vite-react/src/hooks/useBalance.ts +++ b/examples/vite-react/src/hooks/useBalance.ts @@ -1,10 +1,9 @@ import { useQuery } from '@tanstack/react-query'; -import { useToast } from '@chakra-ui/react'; +import { toast } from '@interchain-ui/react'; import { createGetBalance } from 'interchainjs/cosmos/bank/v1beta1/query.rpc.func'; import { DENOM, DECIMAL, RPC_ENDPOINT } from '../utils/constants'; export const useBalance = (address: string, walletManager: any) => { - const toast = useToast(); const { data, refetch } = useQuery({ queryKey: ['balance', address], queryFn: async () => { @@ -16,15 +15,9 @@ export const useBalance = (address: string, walletManager: any) => { denom: DENOM, }); return Number(atomBalance?.amount || 0) / Math.pow(10, DECIMAL); - } catch (error) { + } catch (error: any) { console.error('Error fetching balance:', error); - toast({ - title: 'Error fetching balance', - description: (error as Error).message, - status: 'error', - duration: 5000, - isClosable: true, - }); + toast.error(error.message) return null; } }, diff --git a/examples/vite-react/src/hooks/useTransfer.tsx b/examples/vite-react/src/hooks/useTransfer.tsx index 0048de30..f60b1410 100644 --- a/examples/vite-react/src/hooks/useTransfer.tsx +++ b/examples/vite-react/src/hooks/useTransfer.tsx @@ -1,13 +1,11 @@ import { useMutation } from '@tanstack/react-query'; -import { useToast, Link } from '@chakra-ui/react'; +import { Link, toast, Text } from '@interchain-ui/react'; import { createSend } from 'interchainjs/cosmos/bank/v1beta1/tx.rpc.func'; import { DENOM, DECIMAL } from '../utils/constants'; import { keplrWallet } from '@interchain-kit/keplr-extension'; -import { chain as cosmoshubChain } from '@chain-registry/v2/mainnet/cosmoshub'; +import { chain } from '@chain-registry/v2/mainnet/cosmoshub'; export const useTransfer = (address: string, walletManager: any, refetchBalance: () => void) => { - const toast = useToast(); - const transferMutation = useMutation({ mutationFn: async (data: { recipient: string; amount: string }) => { if (!window.keplr || !address) throw new Error('Keplr not connected'); @@ -30,41 +28,31 @@ export const useTransfer = (address: string, walletManager: any, refetchBalance: const signingClient = await walletManager?.getSigningClient( keplrWallet.info?.name as string, - cosmoshubChain.chainName + chain.chainName ); const txSend = createSend(signingClient); const res = await txSend(address, message, fee, ''); - // 等待链上确认 await new Promise((resolve) => setTimeout(resolve, 6000)); return (res as any).hash; }, onSuccess: (txHash) => { - toast({ - title: 'Transfer successful', - description: ( - - View transaction details - - ), - status: 'success', - duration: null, - isClosable: true, - }); + toast.success( + + View transaction details + + ) refetchBalance(); }, onError: (error: Error) => { console.error('Error transferring funds:', error); - toast({ - title: 'Transfer failed', - description: error.message, - status: 'error', - duration: 5000, - isClosable: true, - }); + toast.error( + + {error.message} + + ) }, }); diff --git a/examples/vite-react/src/hooks/useWalletManager.ts b/examples/vite-react/src/hooks/useWalletManager.ts index 08f04fbd..2521194b 100644 --- a/examples/vite-react/src/hooks/useWalletManager.ts +++ b/examples/vite-react/src/hooks/useWalletManager.ts @@ -1,14 +1,13 @@ import { useState, useEffect, useCallback } from 'react'; -import { useToast } from '@chakra-ui/react'; import { WalletManager } from '@interchain-kit/core'; import { keplrWallet } from '@interchain-kit/keplr-extension'; import { chain as cosmoshubChain, assetList as cosmoshubAssetList } from '@chain-registry/v2/mainnet/cosmoshub'; import { RPC_ENDPOINT } from '../utils/constants'; +import { toast } from '@interchain-ui/react'; export const useWalletManager = () => { const [walletManager, setWalletManager] = useState(null); const [address, setAddress] = useState(''); - const toast = useToast(); useEffect(() => { (async () => { @@ -27,15 +26,9 @@ export const useWalletManager = () => { } ); setWalletManager(manager); - } catch (error) { + } catch (error: any) { console.error('Error initializing wallet manager:', error); - toast({ - title: 'Wallet initialization failed', - description: (error as Error).message, - status: 'error', - duration: 5000, - isClosable: true, - }); + toast.error(error.message) } })(); }, [toast]); @@ -51,15 +44,9 @@ export const useWalletManager = () => { cosmoshubChain.chainName ); setAddress(account?.address as string); - } catch (error) { + } catch (error: any) { console.error('Error connecting wallet:', error); - toast({ - title: 'Connection failed', - description: (error as Error).message, - status: 'error', - duration: 5000, - isClosable: true, - }); + toast.error(error.message) } }, [walletManager, toast]); diff --git a/examples/vite-react/src/main.tsx b/examples/vite-react/src/main.tsx index f75a7ed4..e3dbb90f 100644 --- a/examples/vite-react/src/main.tsx +++ b/examples/vite-react/src/main.tsx @@ -1,19 +1,22 @@ +import './styles/globals.css'; +import '@interchain-ui/react/styles'; +import { ThemeProvider, Toaster } from '@interchain-ui/react'; + import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import { ChakraProvider, ColorModeScript } from '@chakra-ui/react' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import App from './App.tsx' -import theme from './theme' + const queryClient = new QueryClient() createRoot(document.getElementById('root')!).render( - - - + + - - + + + , ) \ No newline at end of file diff --git a/examples/vite-react/src/styles/globals.css b/examples/vite-react/src/styles/globals.css new file mode 100644 index 00000000..5955056e --- /dev/null +++ b/examples/vite-react/src/styles/globals.css @@ -0,0 +1,102 @@ +html, +body { + padding: 0; + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, + Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; +} + +a { + color: inherit; + text-decoration: none; +} + +* { + box-sizing: border-box; +} + +@media (prefers-color-scheme: dark) { + html { + color-scheme: dark; + } + + body { + color: white; + background: black; + } +} + +/* + 1. Use a more-intuitive box-sizing model. +*/ +*, +*::before, +*::after { + box-sizing: border-box; +} + +/* + 2. Remove default margin +*/ +* { + margin: 0; +} + +/* + Typographic tweaks! + 3. Add accessible line-height + 4. Improve text rendering +*/ +body { + line-height: 1.5; + -webkit-font-smoothing: antialiased; +} + +/* + 5. Improve media defaults +*/ +img, +picture, +video, +canvas, +svg { + display: block; + max-width: 100%; +} + +/* + 6. Remove built-in form typography styles +*/ +input, +button, +textarea, +select { + font: inherit; +} + +/* + 7. Avoid text overflows +*/ +p, +h1, +h2, +h3, +h4, +h5, +h6 { + overflow-wrap: break-word; +} + +/* + 8. Create a root stacking context +*/ +#root, +#__next { + isolation: isolate; +} + +#main { + min-height: 100vh; + display: flex; + flex-direction: column; +} diff --git a/examples/vite-react/src/theme.ts b/examples/vite-react/src/theme.ts deleted file mode 100644 index d2d8fdf2..00000000 --- a/examples/vite-react/src/theme.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { extendTheme, type ThemeConfig } from '@chakra-ui/react' - -const config: ThemeConfig = { - initialColorMode: 'system', - useSystemColorMode: true, -} - -const theme = extendTheme({ config }) - -export default theme \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index f8b7a186..3df605e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4251,6 +4251,7 @@ __metadata: "@hookform/resolvers": "npm:^3.3.4" "@interchain-kit/core": "npm:0.2.206" "@interchain-kit/keplr-extension": "npm:0.2.206" + "@interchain-ui/react": "npm:1.26.1" "@tanstack/react-query": "npm:5.68.0" "@types/react": "npm:^18.3.5" "@types/react-dom": "npm:^18.3.0"