/** * Feature Flags Management * Toggle features on/off per tier, A/B tests, kill switches */ import { useState } from 'react'; import { useQuery, useMutation } from '@tanstack/react-query'; // import { db } from '../../services/supabase'; import { ToggleLeft, ToggleRight, FlaskConical, AlertTriangle, Zap, RefreshCw, Plus, Trash2, Edit3, Percent, Flag, Power, Search, Rocket, } from 'lucide-react'; const TIERS = ['FREE', 'BASIC', 'PRO', 'ELITE', 'ENTERPRISE']; const FEATURE_CATEGORIES = ['Core', 'AI/OSINT', 'Analytics', 'Trenches', 'Rehab', 'API']; interface FeatureFlag { id: string; name: string; description: string; category: string; enabled: boolean; tierAccess: Record; beta: boolean; killSwitch: boolean; rolloutPercentage: number; createdAt: string; updatedAt: string; } const DEFAULT_FEATURES: FeatureFlag[] = [ { id: 'wallet_scanner', name: 'Wallet Scanner', description: 'Basic wallet analysis and risk scoring', category: 'Core', enabled: true, tierAccess: { FREE: true, BASIC: true, PRO: true, ELITE: true, ENTERPRISE: true }, beta: false, killSwitch: false, rolloutPercentage: 100, createdAt: '2024-01-01', updatedAt: '2024-01-01', }, { id: 'ai_osint', name: 'AI/OSINT Analysis', description: 'Advanced AI-powered blockchain analysis', category: 'AI/OSINT', enabled: true, tierAccess: { FREE: false, BASIC: true, PRO: true, ELITE: true, ENTERPRISE: true }, beta: false, killSwitch: false, rolloutPercentage: 100, createdAt: '2024-01-01', updatedAt: '2024-01-01', }, { id: 'cross_chain_tracing', name: 'Cross-Chain Tracing', description: 'Track transactions across multiple blockchains', category: 'Analytics', enabled: true, tierAccess: { FREE: false, BASIC: false, PRO: true, ELITE: true, ENTERPRISE: true }, beta: false, killSwitch: false, rolloutPercentage: 100, createdAt: '2024-01-01', updatedAt: '2024-01-01', }, { id: 'trenches_posting', name: 'Trenches Community Posting', description: 'Post to The Trenches message board', category: 'Trenches', enabled: true, tierAccess: { FREE: true, BASIC: true, PRO: true, ELITE: true, ENTERPRISE: true }, beta: false, killSwitch: false, rolloutPercentage: 100, createdAt: '2024-01-01', updatedAt: '2024-01-01', }, { id: 'rug_rehab_booking', name: 'Rug Pull Rehab Booking', description: 'Book live rehab sessions with experts', category: 'Rehab', enabled: true, tierAccess: { FREE: true, BASIC: true, PRO: true, ELITE: true, ENTERPRISE: true }, beta: false, killSwitch: false, rolloutPercentage: 100, createdAt: '2024-01-01', updatedAt: '2024-01-01', }, { id: 'api_access', name: 'API Access', description: 'Generate and use API keys', category: 'API', enabled: true, tierAccess: { FREE: false, BASIC: false, PRO: true, ELITE: true, ENTERPRISE: true }, beta: false, killSwitch: false, rolloutPercentage: 100, createdAt: '2024-01-01', updatedAt: '2024-01-01', }, { id: 'advanced_visualization', name: 'Advanced Visualization (WebGL)', description: '3D network graph visualization', category: 'Analytics', enabled: true, tierAccess: { FREE: false, BASIC: false, PRO: false, ELITE: true, ENTERPRISE: true }, beta: true, killSwitch: true, rolloutPercentage: 50, createdAt: '2024-01-15', updatedAt: '2024-01-15', }, { id: 'whale_alerts', name: 'Real-Time Whale Alerts', description: 'Instant notifications for large transactions', category: 'Core', enabled: true, tierAccess: { FREE: false, BASIC: true, PRO: true, ELITE: true, ENTERPRISE: true }, beta: false, killSwitch: false, rolloutPercentage: 100, createdAt: '2024-01-01', updatedAt: '2024-01-01', }, ]; export default function FeatureFlags() { const [searchQuery, setSearchQuery] = useState(''); const [categoryFilter, setCategoryFilter] = useState('all'); const [_selectedFeature, setSelectedFeature] = useState(null); const [_showEditModal, setShowEditModal] = useState(false); const [showCreateModal, setShowCreateModal] = useState(false); const [activeTab, setActiveTab] = useState<'features' | 'ab_tests' | 'rollouts'>('features'); // Fetch features from database (mocked) const { data: features, isLoading, refetch } = useQuery({ queryKey: ['feature-flags'], queryFn: async () => { // Mock for now - database integration coming soon return DEFAULT_FEATURES; }, }); // Update feature mutation const updateFeature = useMutation({ mutationFn: async ({ id, updates }: { id: string; updates: Partial }) => { // Mock for now - database integration coming soon console.log('Update feature', id, updates); return { id, ...updates }; }, onSuccess: () => refetch(), }); // Create feature mutation const createFeature = useMutation({ mutationFn: async (feature: Partial) => { // Mock for now - database integration coming soon console.log('Create feature', feature); return feature; }, onSuccess: () => { refetch(); setShowCreateModal(false); }, }); // Delete feature mutation const deleteFeature = useMutation({ mutationFn: async (id: string) => { // Mock for now - database integration coming soon console.log('Delete feature', id); return { id }; }, onSuccess: () => refetch(), }); const filteredFeatures = features?.filter((f: FeatureFlag) => { const matchesSearch = f.name.toLowerCase().includes(searchQuery.toLowerCase()) || f.description.toLowerCase().includes(searchQuery.toLowerCase()); const matchesCategory = categoryFilter === 'all' || f.category === categoryFilter; return matchesSearch && matchesCategory; }); const stats = { total: features?.length || 0, enabled: features?.filter((f: FeatureFlag) => f.enabled).length || 0, beta: features?.filter((f: FeatureFlag) => f.beta).length || 0, killSwitches: features?.filter((f: FeatureFlag) => f.killSwitch).length || 0, }; const toggleFeature = (feature: FeatureFlag, field: keyof FeatureFlag) => { updateFeature.mutate({ id: feature.id, updates: { [field]: !feature[field] }, }); }; const toggleTierAccess = (feature: FeatureFlag, tier: string) => { const newTierAccess = { ...feature.tierAccess, [tier]: !feature.tierAccess[tier] }; updateFeature.mutate({ id: feature.id, updates: { tierAccess: newTierAccess }, }); }; return (
{/* Header Stats */}
{/* Tabs */}
{[ { id: 'features', label: 'Feature Flags', icon: Flag }, { id: 'ab_tests', label: 'A/B Tests', icon: Percent }, { id: 'rollouts', label: 'Gradual Rollouts', icon: Rocket }, ].map((tab) => ( ))}
{/* Filters & Actions */}
setSearchQuery(e.target.value)} className="bg-crypto-card border border-crypto-border rounded-lg pl-10 pr-4 py-2 text-white" />
{/* Features Table */} {activeTab === 'features' && (
{isLoading ? (
Loading features...
) : (
{filteredFeatures?.map((feature: FeatureFlag) => ( ))}
Feature Category Status Beta Kill Switch Tier Access Actions

{feature.name}

{feature.description}

{feature.category}
{TIERS.map((tier) => ( ))}
)}
)} {/* A/B Tests Tab */} {activeTab === 'ab_tests' && (

A/B Test configuration coming soon

Configure experiments and track conversion rates

)} {/* Gradual Rollouts Tab */} {activeTab === 'rollouts' && (

Gradual rollout controls coming soon

Roll out features to specific user percentages

)} {/* Create Feature Modal */} {showCreateModal && (

Create Feature Flag

{ e.preventDefault(); const formData = new FormData(e.currentTarget); createFeature.mutate({ id: formData.get('id') as string, name: formData.get('name') as string, description: formData.get('description') as string, category: formData.get('category') as string, enabled: false, tierAccess: { FREE: false, BASIC: false, PRO: false, ELITE: false, ENTERPRISE: false }, beta: true, killSwitch: false, rolloutPercentage: 0, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), }); }} className="space-y-4" >