The NetworkSelector component is a custom dropdown for network selection in the TradeFlow Web application. It supports switching between Stellar Mainnet and Stellar Testnet, providing a professional multi-chain interface for future expansion.
- Custom Dropdown Component: Built as
NetworkSelector.tsxwith full dropdown functionality - Stellar Branding: Features a custom Stellar logo next to network names
- Network Options: Supports "Stellar Mainnet" and "Stellar Testnet"
- React State Management: Uses
useStateto track the currently selected network - Testnet Warning Badge: Displays a yellow warning badge when Testnet is selected
- Click Outside to Close: Dropdown closes when clicking outside the component
- Hover Effects: Smooth transitions and hover states for better UX
- Responsive Design: Works well on different screen sizes
- Accessibility: Proper ARIA labels and keyboard navigation support
- Selected State Indicator: Visual indicator for the currently selected network
interface NetworkSelectorProps {
onNetworkChange?: (network: Network) => void;
}export type Network = "mainnet" | "testnet";- Component:
src/components/NetworkSelector.tsx - Integration: Added to
Navbar.tsxnext to the wallet button
import NetworkSelector, { Network } from "./src/components/NetworkSelector";
// In your component
<NetworkSelector
onNetworkChange={(network) => {
console.log("Network changed to:", network);
// Handle network change logic
}}
/>- Custom gradient design (blue to purple)
- Circular shape with white center dot
- Consistent with Stellar branding
- Yellow background with dark text
- Alert triangle icon
- Positioned at top-right of the selector
- Only visible when testnet is selected
- Dark theme matching the app design
- Slate color palette
- Smooth transitions and hover effects
- Z-index management for proper layering
const [selectedNetwork, setSelectedNetwork] = useState<Network>("mainnet");
const [isOpen, setIsOpen] = useState(false);useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
setIsOpen(false);
}
};
// Event listener setup and cleanup
}, []);const networks = [
{
id: "mainnet" as Network,
name: "Stellar Mainnet",
description: "Production network"
},
{
id: "testnet" as Network,
name: "Stellar Testnet",
description: "Development network"
}
];A standalone test file has been created: test-network-selector.html
- Opens in browser to test component functionality
- Demonstrates all features without requiring the full app setup
- Shows real-time network selection changes
- Dropdown opens and closes correctly
- Network selection updates state
- Testnet warning badge appears/disappears
- Click outside closes dropdown
- Hover effects work properly
- Responsive design on different screen sizes
The component is designed for easy expansion to support additional networks:
// Easy to add new networks
const networks = [
// Existing networks...
{
id: "ethereum" as Network,
name: "Ethereum Mainnet",
description: "Ethereum network"
},
{
id: "polygon" as Network,
name: "Polygon",
description: "Polygon network"
}
];- Network Status Indicators: Show network health/status
- Custom Networks: Allow users to add custom RPC endpoints
- Network Switching Confirmation: Add confirmation modal for network changes
- Network-Specific Features: Show/hide features based on selected network
- Persistence: Save network preference to localStorage
src/components/NetworkSelector.tsx- Main componenttest-network-selector.html- Standalone test fileNetworkSelector-README.md- This documentation
Navbar.tsx- Integrated NetworkSelector next to wallet button
The component uses:
reactandreact-dom- Core React functionalitylucide-react- Icons (ChevronDown, AlertTriangle)- Tailwind CSS - Styling
All dependencies are already included in the project's package.json.
The NetworkSelector component successfully fulfills all requirements:
- ✅ Custom dropdown with network selection
- ✅ Stellar logo integration
- ✅ React state management
- ✅ Testnet warning badge
- ✅ Professional multi-chain interface ready for future expansion
The component is production-ready and follows the existing codebase patterns and styling conventions.