import React, { useEffect } from 'react' import { Box, Text } from 'ink' import { useConfig } from '../hooks/index.js' import { Header, KeyValue, Spinner } from '../components/index.js' import { theme } from '../theme.js' import { getConfigStore } from '../../storage/config-store.js' export interface ConfigShowScreenProps { /** * Optional callback when the screen is ready to exit */ onExit?: () => void } /** * Helper function to obfuscate API keys for display */ function obfuscateApiKey(key: string): string { if (key.length <= 12) { return '*'.repeat(key.length) } return key.slice(0, 8) + '...' + key.slice(-4) } /** * ConfigShowScreen displays the current CLI configuration. * This replaces the imperative console.log implementation in commands/config/show.ts * * Features: * - Shows all configured chains with details * - Displays default settings * - Shows API keys (obfuscated) * - Shows config file path */ export function ConfigShowScreen({ onExit }: ConfigShowScreenProps): React.ReactElement { const { config, loading, error } = useConfig() // Auto-exit after rendering useEffect(() => { if (!loading && onExit) { onExit() } }, [loading, onExit]) // Loading state if (loading) { return } // Error state if (error || !config) { return ( Error: {error || 'Failed to load configuration'} ) } const configStore = getConfigStore() const chains = Object.values(config.chains) return (
{/* Chains section */} Chains: {chains.length === 0 ? ( No chains configured ) : ( {chains.map((chain) => ( {chain.name} ({chain.chainId}) ))} )} {/* Defaults section */} {/* API Configuration section */} {/* Config file path */} Config file: {configStore.getConfigPath()} {/* Success message */} Configuration displayed successfully ) }