|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { useState } from "react" |
| 4 | +import { Badge } from "@/components/ui/badge" |
| 5 | +import { CheckCircle, Clock } from "lucide-react" |
| 6 | +import { BlockchainTransaction } from "../types/blockchain" |
| 7 | + |
| 8 | +interface Props { |
| 9 | + transaction: BlockchainTransaction |
| 10 | +} |
| 11 | + |
| 12 | +export function TransactionDetailCard({ transaction }: Props) { |
| 13 | + const [showMoreDetails, setShowMoreDetails] = useState(false) |
| 14 | + |
| 15 | + return ( |
| 16 | + <div className="bg-white rounded-2xl shadow-sm overflow-hidden"> |
| 17 | + {/* 거래 해시 */} |
| 18 | + <DetailRow |
| 19 | + label="거래 해시" |
| 20 | + value={transaction.hash} |
| 21 | + /> |
| 22 | + |
| 23 | + {/* 상태 */} |
| 24 | + <DetailRowStatus label="상태" status={transaction.status} /> |
| 25 | + |
| 26 | + {/* 블록 */} |
| 27 | + <DetailRowBlock |
| 28 | + label="블록" |
| 29 | + block={transaction.block} |
| 30 | + confirmations={transaction.confirmations} |
| 31 | + /> |
| 32 | + |
| 33 | + {/* 타임스탬프 */} |
| 34 | + <DetailRowIcon |
| 35 | + label="타임스탬프" |
| 36 | + icon={<Clock className="w-4 h-4 text-gray-400" />} |
| 37 | + value={transaction.timestamp} |
| 38 | + /> |
| 39 | + |
| 40 | + {/* From / To */} |
| 41 | + <DetailRow |
| 42 | + label="보낸 사람" |
| 43 | + value={transaction.from} |
| 44 | + color="orange" |
| 45 | + /> |
| 46 | + <DetailRow |
| 47 | + label="받는 사람" |
| 48 | + value={transaction.to} |
| 49 | + color="orange" |
| 50 | + background |
| 51 | + /> |
| 52 | + |
| 53 | + {/* 금액 */} |
| 54 | + <SimpleRow label="금액" right={<span className="text-[#FFB020] font-medium">{transaction.value}</span>} /> |
| 55 | + |
| 56 | + {/* + 더보기 */} |
| 57 | + <div className="px-4 py-4"> |
| 58 | + <button |
| 59 | + onClick={() => setShowMoreDetails(!showMoreDetails)} |
| 60 | + className="text-sm font-normal text-[#FFB020]" |
| 61 | + > |
| 62 | + 추가 정보: <span className="underline">{showMoreDetails ? "접기" : "+ 더 보기"}</span> |
| 63 | + </button> |
| 64 | + |
| 65 | + {showMoreDetails && ( |
| 66 | + <div className="mt-4 pt-4 border-t border-gray-200 space-y-3 text-sm"> |
| 67 | + <DetailInfo label="Gas 사용량" value={transaction.gasUsed.toLocaleString()} /> |
| 68 | + <DetailInfo label="Gas 한도" value={transaction.gasLimit.toLocaleString()} /> |
| 69 | + <DetailInfo label="Gas 가격" value={`${transaction.gasPrice} Gwei`} /> |
| 70 | + <DetailInfo label="Nonce" value={transaction.nonce} /> |
| 71 | + </div> |
| 72 | + )} |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + ) |
| 76 | +} |
| 77 | + |
| 78 | +// === 내부 컴포넌트 === |
| 79 | + |
| 80 | +function DetailRow({ |
| 81 | + label, |
| 82 | + value, |
| 83 | + background = false, |
| 84 | + color = "default", |
| 85 | + }: { |
| 86 | + label: string |
| 87 | + value: string |
| 88 | + background?: boolean |
| 89 | + color?: "orange" | "default" |
| 90 | +}) { |
| 91 | + return ( |
| 92 | + <div className={`flex flex-col px-4 py-4 border-b border-gray-100 ${background ? "bg-gray-50" : ""}`}> |
| 93 | + <LabelWithIcon text={label} /> |
| 94 | + <div className={`mt-1 break-all font-mono text-xs ${color === "orange" ? "text-[#FFB020]" : "text-[#111827]"}`}> |
| 95 | + {value} |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + ) |
| 99 | +} |
| 100 | + |
| 101 | +function DetailRowStatus({ label, status }: { label: string; status: string }) { |
| 102 | + return ( |
| 103 | + <div className="flex items-center justify-between px-4 py-4 border-b border-gray-100 bg-gray-50"> |
| 104 | + <LabelWithIcon text={label} /> |
| 105 | + <Badge className="bg-green-100 text-green-700 border-green-200 hover:bg-green-100"> |
| 106 | + <CheckCircle className="w-3 h-3 mr-1" /> |
| 107 | + 성공 |
| 108 | + </Badge> |
| 109 | + </div> |
| 110 | + ) |
| 111 | +} |
| 112 | + |
| 113 | +function DetailRowBlock({ label, block, confirmations }: { |
| 114 | + label: string |
| 115 | + block: number |
| 116 | + confirmations: number |
| 117 | +}) { |
| 118 | + return ( |
| 119 | + <div className="flex items-center justify-between px-4 py-4 border-b border-gray-100"> |
| 120 | + <LabelWithIcon text={label} /> |
| 121 | + <div className="flex items-center gap-2"> |
| 122 | + <CheckCircle className="w-4 h-4 text-green-500" /> |
| 123 | + <span className="text-[#FFB020] font-medium text-sm">{block}</span> |
| 124 | + <span className="text-gray-500 text-xs">{confirmations} 확인</span> |
| 125 | + </div> |
| 126 | + </div> |
| 127 | + ) |
| 128 | +} |
| 129 | + |
| 130 | +function DetailRowIcon({ label, icon, value }: { |
| 131 | + label: string |
| 132 | + icon: React.ReactNode |
| 133 | + value: string |
| 134 | +}) { |
| 135 | + return ( |
| 136 | + <div className="flex items-center justify-between px-4 py-4 border-b border-gray-100 bg-gray-50"> |
| 137 | + <LabelWithIcon text={label} /> |
| 138 | + <div className="flex items-center gap-2 text-sm text-[#111827]"> |
| 139 | + {icon} |
| 140 | + <span>{value}</span> |
| 141 | + </div> |
| 142 | + </div> |
| 143 | + ) |
| 144 | +} |
| 145 | + |
| 146 | +function SimpleRow({ label, right, background = false }: { |
| 147 | + label: string |
| 148 | + right: React.ReactNode |
| 149 | + background?: boolean |
| 150 | +}) { |
| 151 | + return ( |
| 152 | + <div className={`flex items-center justify-between px-4 py-4 border-b border-gray-100 ${background ? "bg-gray-50" : ""}`}> |
| 153 | + <LabelWithIcon text={label} /> |
| 154 | + {right} |
| 155 | + </div> |
| 156 | + ) |
| 157 | +} |
| 158 | + |
| 159 | +function DetailInfo({ label, value }: { label: string; value: string | number }) { |
| 160 | + return ( |
| 161 | + <div className="flex items-center justify-between"> |
| 162 | + <span className="text-sm text-[#6B7280]">{label}:</span> |
| 163 | + <span className="text-sm font-medium text-[#111827]">{value}</span> |
| 164 | + </div> |
| 165 | + ) |
| 166 | +} |
| 167 | + |
| 168 | +function LabelWithIcon({ text }: { text: string }) { |
| 169 | + return ( |
| 170 | + <div className="flex items-center gap-2"> |
| 171 | + <div className="w-4 h-4 rounded-full border border-gray-400 flex items-center justify-center"> |
| 172 | + <span className="text-xs text-gray-500">?</span> |
| 173 | + </div> |
| 174 | + <span className="text-sm text-[#6B7280]">{text}:</span> |
| 175 | + </div> |
| 176 | + ) |
| 177 | +} |
0 commit comments