/** * HardwareWalletSupport Component - Hardware wallet connection and management */ import { useState } from 'react' import { useAccount, useConnect, useDisconnect } from 'wagmi' import { useAdmin } from '../../contexts/AdminContext' import toast from 'react-hot-toast' interface HardwareWalletInfo { type: 'ledger' | 'trezor' | 'other' name: string address: string connected: boolean } export default function HardwareWalletSupport() { const { address, isConnected, connector } = useAccount() const { connect, connectors } = useConnect() const { disconnect } = useDisconnect() const { addAuditLog } = useAdmin() const [walletInfo, setWalletInfo] = useState(null) // Filter for hardware wallet connectors const hardwareConnectors = connectors.filter((c) => { const name = c.name.toLowerCase() return name.includes('ledger') || name.includes('trezor') || name.includes('hardware') }) const handleConnect = async (connectorId: string) => { try { const connector = connectors.find((c) => c.id === connectorId) if (!connector) { toast.error('Connector not found') return } await connect({ connector }) // Detect hardware wallet type const walletType = detectHardwareWalletType(connector.name) if (walletType) { setWalletInfo({ type: walletType, name: connector.name, address: address || '', connected: true, }) addAuditLog({ user: address || 'unknown', action: 'connect_hardware_wallet', resourceType: 'wallet', resourceId: connectorId, details: { type: walletType, name: connector.name }, status: 'success', }) toast.success(`Connected to ${connector.name}`) } } catch (error: any) { toast.error(`Connection failed: ${error.message}`) console.error('Hardware wallet connection error:', error) } } const handleDisconnect = () => { disconnect() setWalletInfo(null) toast.success('Hardware wallet disconnected') } const detectHardwareWalletType = (connectorName: string): 'ledger' | 'trezor' | 'other' | null => { const name = connectorName.toLowerCase() if (name.includes('ledger')) return 'ledger' if (name.includes('trezor')) return 'trezor' if (name.includes('hardware')) return 'other' return null } const isHardwareWallet = walletInfo !== null || (connector && detectHardwareWalletType(connector.name) !== null) return (

Hardware Wallet Support

Connect and use hardware wallets (Ledger, Trezor) for enhanced security in admin operations.

{/* Connection Status */} {isConnected && isHardwareWallet && (

Hardware Wallet Connected

{connector?.name || 'Hardware Wallet'} - {address?.slice(0, 10)}...{address?.slice(-8)}

)} {/* Hardware Wallet Connectors */} {hardwareConnectors.length > 0 ? (
{hardwareConnectors.map((connector) => { const isActive = isConnected && connector.id === connector.id const walletType = detectHardwareWalletType(connector.name) return (
{walletType === 'ledger' && '🔷'} {walletType === 'trezor' && '🔶'} {!walletType && '💼'}

{connector.name}

{walletType === 'ledger' && 'Hardware wallet - Ledger'} {walletType === 'trezor' && 'Hardware wallet - Trezor'} {!walletType && 'Hardware wallet'}

{!isActive ? ( ) : ( Connected )}
) })}
) : (

No hardware wallet connectors detected

To enable hardware wallet support:

  • Install Ledger Live or Trezor Bridge
  • Install browser extensions if available
  • Connect your hardware wallet to your computer
  • Unlock your hardware wallet
  • Refresh this page
)} {/* Instructions */}

Hardware Wallet Instructions

For Ledger:
  • Install Ledger Live application
  • Connect your Ledger device via USB
  • Unlock your device and open Ethereum app
  • Enable "Contract Data" in Ethereum app settings
  • Click Connect above
For Trezor:
  • Install Trezor Bridge or use Trezor Connect
  • Connect your Trezor device via USB
  • Unlock your device
  • Click Connect above
Security Note: Hardware wallets provide the highest level of security for admin operations. All transactions will require physical confirmation on your device.
{/* Current Connection Info */} {isConnected && address && (

Current Connection

Address:{' '} {address}
Connector: {connector?.name || 'Unknown'}
{walletInfo && (
Type: {walletInfo.type}
)}
)}
) }