"use client"; import { Box, Button, VStack, HStack, Text, Heading, useDisclosure, Modal, ModalOverlay, ModalContent, ModalHeader, ModalCloseButton, ModalBody, FormControl, FormLabel, Input, NumberInput, NumberInputField, NumberInputStepper, NumberIncrementStepper, NumberDecrementStepper, Select, useToast, Badge, IconButton, Tr, Td, Table, Thead, Th, Tbody, } from "@chakra-ui/react"; import { DeleteIcon, AddIcon, EditIcon } from "@chakra-ui/icons"; import { useState } from "react"; import { useSmartWallet } from "../../contexts/SmartWalletContext"; import { SmartWalletType } from "../../types"; import { validateAddress, validateNetworkId } from "../../utils/security"; import { ethers } from "ethers"; import DeployWallet from "./DeployWallet"; export default function WalletManager() { const { smartWallets, activeWallet, setActiveWallet, createWallet, deleteWallet, connectToWallet, } = useSmartWallet(); const { isOpen, onOpen, onClose } = useDisclosure(); const toast = useToast(); const [walletAddress, setWalletAddress] = useState(""); const [networkId, setNetworkId] = useState(1); const [walletType, setWalletType] = useState(SmartWalletType.GNOSIS_SAFE); const handleConnect = async () => { // Validate address const addressValidation = validateAddress(walletAddress); if (!addressValidation.valid) { toast({ title: "Invalid Address", description: addressValidation.error || "Please enter a valid Ethereum address", status: "error", isClosable: true, }); return; } // Validate network ID const networkValidation = validateNetworkId(networkId); if (!networkValidation.valid) { toast({ title: "Invalid Network", description: networkValidation.error || "Network not supported", status: "error", isClosable: true, }); return; } try { const wallet = await connectToWallet( addressValidation.checksummed!, networkId, walletType ); if (wallet) { setActiveWallet(wallet); toast({ title: "Wallet Connected", description: `Connected to ${addressValidation.checksummed!.slice(0, 10)}...`, status: "success", isClosable: true, }); onClose(); } else { throw new Error("Failed to connect to wallet"); } } catch (error: any) { toast({ title: "Connection Failed", description: error.message || "Failed to connect to wallet", status: "error", isClosable: true, }); } }; return ( Smart Wallets {activeWallet && ( Active Wallet: {activeWallet.type} {activeWallet.address} {activeWallet.owners.length} owner(s), threshold: {activeWallet.threshold} )} {smartWallets.map((wallet) => ( ))}
Address Type Network Owners Actions
{wallet.address.slice(0, 10)}... {wallet.type} {wallet.networkId} {wallet.owners.length} ({wallet.threshold}) } size="sm" onClick={() => setActiveWallet(wallet)} isDisabled={activeWallet?.id === wallet.id} /> } size="sm" colorScheme="red" onClick={() => deleteWallet(wallet.id)} />
Connect Smart Wallet Wallet Type Wallet Address setWalletAddress(e.target.value)} placeholder="0x..." /> Network ID setNetworkId(value)} min={1} >
); }