Cosmos DEX Frontend
A modern React frontend for the Cosmos DEX built with Vite, TypeScript, and Tailwind CSS.
๐ Quick Start
Prerequisites
- Node.js 18+
- npm or yarn
Installation
npm installDevelopment
npm run startBuild for Production
npm run build๐ Deployment to Cloudflare Pages
Method 1: GitHub Integration (Recommended)
-
Push to GitHub
git add . git commit -m "Deploy frontend" git push origin main
-
Connect to Cloudflare Pages
- Go to Cloudflare Pages
- Click "Create a project"
- Connect your GitHub repository
- Select the
cosmos-dexrepository
-
Configure Build Settings
- Framework preset: Vite
- Build command:
cd frontend && npm install && npm run build - Build output directory:
frontend/dist - Root directory:
/(leave empty)
-
Environment Variables
Add these environment variables in Cloudflare Pages settings:REACT_APP_CHAIN_ID=cosmoshub-4 REACT_APP_CHAIN_NAME=Cosmos Hub REACT_APP_RPC_ENDPOINT=https://cosmos-rpc.polkachu.com REACT_APP_REST_ENDPOINT=https://cosmos-rest.polkachu.com REACT_APP_CONTRACT_ADDRESS=cosmos1svd8fpfwrf237qprqt33ajylg302s05neruqt37p3ju2qktkt6wqytq4ez REACT_APP_CODE_ID=250 REACT_APP_DENOM=uatom REACT_APP_COIN_DECIMALS=6 REACT_APP_COIN_MINIMAL_DENOM=uatom REACT_APP_COIN_DISPLAY_NAME=ATOM REACT_APP_GAS_PRICES=0.025uatom REACT_APP_GAS_ADJUSTMENT=1.3 REACT_APP_APP_NAME=Cosmos DEX REACT_APP_APP_VERSION=1.0.0 REACT_APP_ENVIRONMENT=production -
Deploy
- Click "Save and Deploy"
- Your site will be available at
https://your-project.pages.dev
Method 2: Direct Upload
-
Build the project
npm run build
-
Upload to Cloudflare Pages
- Go to Cloudflare Pages dashboard
- Click "Upload assets"
- Upload the
distfolder contents
Method 3: Wrangler CLI
-
Install Wrangler
npm install -g wrangler
-
Login to Cloudflare
wrangler login
-
Deploy
npm run build wrangler pages deploy dist --project-name cosmos-dex
๐ง Configuration
Environment Variables
The app uses minimal environment variables since most network information comes from Keplr's built-in chain registry.
Required Variables:
VITE_CONTRACT_ADDRESS=cosmos1svd8fpfwrf237qprqt33ajylg302s05neruqt37p3ju2qktkt6wqytq4ez
VITE_CODE_ID=250Optional Variables:
VITE_APP_NAME=Cosmos DEX
VITE_APP_VERSION=1.0.0
# Only needed if you want to override Keplr's default endpoints
VITE_RPC_ENDPOINT=https://cosmos-rpc.polkachu.com
VITE_REST_ENDPOINT=https://cosmos-rest.polkachu.com
VITE_GAS_PRICES=0.025uatom
VITE_GAS_ADJUSTMENT=1.3What Keplr Provides Automatically:
- Chain ID (cosmoshub-4)
- Chain name (Cosmos Hub)
- RPC/REST endpoints
- Native token info (ATOM, uatom, 6 decimals)
- Gas price suggestions
- Bech32 prefix (cosmos)
Copy .env.example to .env and update the contract address:
cp .env.example .envKey Configuration Options
- REACT_APP_CONTRACT_ADDRESS: Your deployed contract address
- REACT_APP_RPC_ENDPOINT: Cosmos Hub RPC endpoint
- REACT_APP_REST_ENDPOINT: Cosmos Hub REST API endpoint
- REACT_APP_CHAIN_ID: Chain ID (cosmoshub-4 for mainnet)
๐ Project Structure
frontend/
โโโ public/ # Static assets
โโโ src/
โ โโโ components/ # React components
โ โโโ hooks/ # Custom React hooks
โ โโโ pages/ # Page components
โ โโโ services/ # API services
โ โโโ types/ # TypeScript types
โ โโโ utils/ # Utility functions
โ โโโ main.tsx # App entry point
โโโ _headers # Cloudflare Pages headers
โโโ _redirects # Cloudflare Pages redirects
โโโ .env # Environment variables
โโโ .env.example # Environment template
โโโ package.json # Dependencies
โโโ tailwind.config.js # Tailwind CSS config
โโโ tsconfig.json # TypeScript config
โโโ vite.config.ts # Vite config
๐จ Features
Core Features
- Wallet Connection: Keplr wallet integration
- Token Swapping: Intuitive swap interface
- Liquidity Management: Add/remove liquidity
- Pool Creation: Create new trading pairs
- Portfolio Tracking: View your positions
UI/UX Features
- Responsive Design: Mobile-first approach
- Dark Mode: Toggle between light/dark themes
- Real-time Updates: Live price and balance updates
- Toast Notifications: User feedback system
- Loading States: Smooth loading indicators
Technical Features
- TypeScript: Type-safe development
- Vite: Fast build tool and dev server
- Tailwind CSS: Utility-first styling
- CosmJS: Cosmos blockchain interaction
- React Router: Client-side routing
๐ Security
Content Security Policy
The app includes a strict CSP header that only allows:
- Scripts from self and inline (required for React)
- Styles from self, inline, and Google Fonts
- Images from self, data URLs, and HTTPS
- Connections to Cosmos RPC/REST endpoints
Headers
Security headers are configured in _headers:
- X-Frame-Options: DENY
- X-Content-Type-Options: nosniff
- X-XSS-Protection: 1; mode=block
- Referrer-Policy: strict-origin-when-cross-origin
๐ Performance
Optimization Features
- Code Splitting: Automatic chunk splitting
- Tree Shaking: Remove unused code
- Asset Optimization: Minified CSS/JS
- Caching: Long-term caching for static assets
- Preloading: Critical resource preloading
Bundle Analysis
npm run build
npx vite-bundle-analyzer dist๐งช Testing
Unit Tests
npm testType Checking
npm run type-checkLinting
npm run lint๐ CI/CD
The project is configured for automatic deployment on Cloudflare Pages:
- Trigger: Push to main branch
- Build:
cd frontend && npm install && npm run build - Deploy: Automatic deployment to Cloudflare Pages
- Preview: Preview deployments for pull requests
๐ฑ PWA Support
The app includes PWA manifest for mobile installation:
- Installable on mobile devices
- Offline support (coming soon)
- Native app-like experience
๐ Browser Support
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+
๐ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
๐ License
MIT License - see LICENSE file for details.