Files
impersonator/components/TransactionExecution/TransactionApproval.tsx
defiQUG 55fe7d10eb feat: comprehensive project improvements and fixes
- Fix all TypeScript compilation errors (40+ fixes)
  - Add missing type definitions (TransactionRequest, SafeInfo)
  - Fix TransactionRequestStatus vs TransactionStatus confusion
  - Fix import paths and provider type issues
  - Fix test file errors and mock providers

- Implement comprehensive security features
  - AES-GCM encryption with PBKDF2 key derivation
  - Input validation and sanitization
  - Rate limiting and nonce management
  - Replay attack prevention
  - Access control and authorization

- Add comprehensive test suite
  - Integration tests for transaction flow
  - Security validation tests
  - Wallet management tests
  - Encryption and rate limiter tests
  - E2E tests with Playwright

- Add extensive documentation
  - 12 numbered guides (setup, development, API, security, etc.)
  - Security documentation and audit reports
  - Code review and testing reports
  - Project organization documentation

- Update dependencies
  - Update axios to latest version (security fix)
  - Update React types to v18
  - Fix peer dependency warnings

- Add development tooling
  - CI/CD workflows (GitHub Actions)
  - Pre-commit hooks (Husky)
  - Linting and formatting (Prettier, ESLint)
  - Security audit workflow
  - Performance benchmarking

- Reorganize project structure
  - Move reports to docs/reports/
  - Clean up root directory
  - Organize documentation

- Add new features
  - Smart wallet management (Gnosis Safe, ERC4337)
  - Transaction execution and approval workflows
  - Balance management and token support
  - Error boundary and monitoring (Sentry)

- Fix WalletConnect configuration
  - Handle missing projectId gracefully
  - Add environment variable template
2026-01-14 02:17:26 -08:00

246 lines
7.6 KiB
TypeScript

"use client";
import React from "react";
import {
Box,
VStack,
HStack,
Text,
Heading,
Button,
useDisclosure,
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalCloseButton,
ModalBody,
ModalFooter,
Badge,
Progress,
Table,
Thead,
Tr,
Th,
Tbody,
Td,
Code,
} from "@chakra-ui/react";
import { useTransaction } from "../../contexts/TransactionContext";
import { TransactionRequestStatus } from "../../types";
import { formatEther } from "ethers/lib/utils";
export default function TransactionApproval() {
const { pendingTransactions, approveTransaction, rejectTransaction, executeTransaction } =
useTransaction();
const { isOpen, onOpen, onClose } = useDisclosure();
const [selectedTx, setSelectedTx] = React.useState<string | null>(null);
const selectedTransaction = pendingTransactions.find((ptx) => ptx.id === selectedTx);
const handleApprove = async () => {
if (!selectedTx) return;
// Get approver address from active wallet or use a placeholder
// In production, this would get from the connected wallet
const approver = typeof window !== "undefined" && (window as any).ethereum
? await (window as any).ethereum.request({ method: "eth_accounts" }).then((accounts: string[]) => accounts[0])
: "0x0000000000000000000000000000000000000000";
await approveTransaction(selectedTx, approver || "0x0000000000000000000000000000000000000000");
onClose();
};
const handleReject = async () => {
if (!selectedTx) return;
const approver = typeof window !== "undefined" && (window as any).ethereum
? await (window as any).ethereum.request({ method: "eth_accounts" }).then((accounts: string[]) => accounts[0])
: "0x0000000000000000000000000000000000000000";
await rejectTransaction(selectedTx, approver || "0x0000000000000000000000000000000000000000");
onClose();
};
const handleExecute = async () => {
if (!selectedTx) return;
const hash = await executeTransaction(selectedTx);
if (hash) {
// Transaction executed successfully
}
onClose();
};
return (
<Box>
<Heading size="md" mb={4}>
Pending Transactions
</Heading>
{pendingTransactions.length === 0 ? (
<Box p={4} textAlign="center" color="gray.400">
<Text>No pending transactions</Text>
</Box>
) : (
<Table variant="simple" size="sm">
<Thead>
<Tr>
<Th>ID</Th>
<Th>To</Th>
<Th>Value</Th>
<Th>Approvals</Th>
<Th>Status</Th>
<Th>Actions</Th>
</Tr>
</Thead>
<Tbody>
{pendingTransactions.map((ptx) => (
<Tr key={ptx.id}>
<Td>
<Text fontSize="xs">{ptx.id.slice(0, 10)}...</Text>
</Td>
<Td>
<Text fontSize="sm">{ptx.transaction.to.slice(0, 10)}...</Text>
</Td>
<Td>
<Text fontSize="sm">
{parseFloat(formatEther(ptx.transaction.value || "0")).toFixed(4)} ETH
</Text>
</Td>
<Td>
<Text fontSize="sm">
{ptx.approvalCount} / {ptx.requiredApprovals}
</Text>
<Progress
value={(ptx.approvalCount / ptx.requiredApprovals) * 100}
size="sm"
colorScheme="green"
mt={1}
/>
</Td>
<Td>
<Badge
colorScheme={
ptx.transaction.status === TransactionRequestStatus.APPROVED
? "green"
: "yellow"
}
>
{ptx.transaction.status}
</Badge>
</Td>
<Td>
<HStack>
<Button
size="xs"
onClick={() => {
setSelectedTx(ptx.id);
onOpen();
}}
>
View
</Button>
{ptx.canExecute && (
<Button
size="xs"
colorScheme="green"
onClick={() => handleExecute()}
>
Execute
</Button>
)}
</HStack>
</Td>
</Tr>
))}
</Tbody>
</Table>
)}
<Modal isOpen={isOpen} onClose={onClose} size="xl">
<ModalOverlay />
<ModalContent>
<ModalHeader>Transaction Details</ModalHeader>
<ModalCloseButton />
<ModalBody>
{selectedTransaction && (
<VStack align="stretch" spacing={4}>
<Box>
<Text fontSize="sm" color="gray.400">
Transaction ID
</Text>
<Code>{selectedTransaction.id}</Code>
</Box>
<Box>
<Text fontSize="sm" color="gray.400">
To
</Text>
<Text>{selectedTransaction.transaction.to}</Text>
</Box>
<Box>
<Text fontSize="sm" color="gray.400">
Value
</Text>
<Text>
{parseFloat(formatEther(selectedTransaction.transaction.value || "0")).toFixed(
6
)}{" "}
ETH
</Text>
</Box>
<Box>
<Text fontSize="sm" color="gray.400">
Data
</Text>
<Code fontSize="xs" p={2} display="block" whiteSpace="pre-wrap">
{selectedTransaction.transaction.data || "0x"}
</Code>
</Box>
<Box>
<Text fontSize="sm" color="gray.400">
Approvals
</Text>
<Text>
{selectedTransaction.approvalCount} / {selectedTransaction.requiredApprovals}
</Text>
<Progress
value={
(selectedTransaction.approvalCount /
selectedTransaction.requiredApprovals) *
100
}
size="sm"
colorScheme="green"
mt={2}
/>
</Box>
<Box>
<Text fontSize="sm" color="gray.400">
Execution Method
</Text>
<Badge>{selectedTransaction.transaction.method}</Badge>
</Box>
</VStack>
)}
</ModalBody>
<ModalFooter>
<HStack>
<Button variant="ghost" onClick={onClose}>
Close
</Button>
{selectedTransaction && !selectedTransaction.canExecute && (
<>
<Button colorScheme="red" onClick={handleReject}>
Reject
</Button>
<Button colorScheme="blue" onClick={handleApprove}>
Approve
</Button>
</>
)}
</HStack>
</ModalFooter>
</ModalContent>
</Modal>
</Box>
);
}