'use client'; import { StablecoinType, FilterState } from '@/types'; import { X, Filter, ChevronDown } from 'lucide-react'; import { useState } from 'react'; interface FiltersProps { filters: FilterState; onFilterChange: (filters: Partial) => void; availableChains: string[]; } const STABLECOINS: { type: StablecoinType; label: string; color: string }[] = [ { type: 'USDC', label: 'USDC', color: 'bg-blue-500/20 text-blue-400 border-blue-500/30' }, { type: 'USDT', label: 'USDT', color: 'bg-emerald-500/20 text-emerald-400 border-emerald-500/30' }, { type: 'USDT0', label: 'USDT0', color: 'bg-teal-500/20 text-teal-400 border-teal-500/30' }, { type: 'DAI', label: 'DAI', color: 'bg-yellow-500/20 text-yellow-400 border-yellow-500/30' }, { type: 'USDS', label: 'USDS', color: 'bg-sky-500/20 text-sky-400 border-sky-500/30' }, { type: 'PYUSD', label: 'PYUSD', color: 'bg-blue-600/20 text-blue-300 border-blue-600/30' }, { type: 'EURe', label: 'EURe', color: 'bg-purple-500/20 text-purple-400 border-purple-500/30' }, { type: 'EURC', label: 'EURC', color: 'bg-indigo-500/20 text-indigo-400 border-indigo-500/30' }, ]; const CHAINS: { name: string; color: string }[] = [ { name: 'Ethereum', color: 'bg-slate-500/20 text-slate-300 border-slate-500/30' }, { name: 'Arbitrum', color: 'bg-blue-600/20 text-blue-400 border-blue-600/30' }, { name: 'Optimism', color: 'bg-red-500/20 text-red-400 border-red-500/30' }, { name: 'Base', color: 'bg-blue-500/20 text-blue-300 border-blue-500/30' }, { name: 'Polygon', color: 'bg-purple-500/20 text-purple-400 border-purple-500/30' }, { name: 'BSC', color: 'bg-yellow-500/20 text-yellow-400 border-yellow-500/30' }, { name: 'Avalanche', color: 'bg-red-600/20 text-red-400 border-red-600/30' }, { name: 'Solana', color: 'bg-gradient-to-r from-purple-500/20 to-teal-500/20 text-purple-300 border-purple-500/30' }, { name: 'Gnosis', color: 'bg-emerald-600/20 text-emerald-400 border-emerald-600/30' }, { name: 'Linea', color: 'bg-slate-400/20 text-slate-300 border-slate-400/30' }, ]; export function Filters({ filters, onFilterChange, availableChains }: FiltersProps) { const [showAdvanced, setShowAdvanced] = useState(false); const toggleStablecoin = (stablecoin: StablecoinType) => { const current = filters.stablecoins || []; const updated = current.includes(stablecoin) ? current.filter(s => s !== stablecoin) : [...current, stablecoin]; onFilterChange({ stablecoins: updated }); }; const toggleChain = (chain: string) => { const current = filters.chains || []; const updated = current.includes(chain) ? current.filter(c => c !== chain) : [...current, chain]; onFilterChange({ chains: updated }); }; const clearFilters = () => { onFilterChange({ stablecoins: [], chains: [], minApy: 0, minTvl: 0, minSecurityScore: 0, }); }; const hasActiveFilters = (filters.stablecoins?.length || 0) > 0 || (filters.chains?.length || 0) > 0 || filters.minApy > 0 || filters.minTvl > 0 || filters.minSecurityScore > 0; return (
{/* Header */}
Filtres {hasActiveFilters && ( {(filters.stablecoins?.length || 0) + (filters.chains?.length || 0)} actifs )}
{hasActiveFilters && ( )}
{/* Stablecoins */}
Stablecoins
{STABLECOINS.map(({ type, label, color }) => { const isActive = filters.stablecoins?.includes(type); return ( ); })}
{/* Chains */}
Réseaux
{CHAINS.filter(c => availableChains.includes(c.name)).map(({ name, color }) => { const isActive = filters.chains?.includes(name); return ( ); })}
{/* Advanced filters toggle */} {/* Advanced filters */} {showAdvanced && (
{/* Min APY */}
onFilterChange({ minApy: Number(e.target.value) || 0 })} placeholder="0%" className="w-full bg-white/5 border border-white/10 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-safe-500/50 transition-colors" />
{/* Min TVL */}
{/* Min Security Score */}
)}
); }