"use client"; import { useState } from "react"; import Layout from "@/components/kokonutui/layout"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem, } from "@/components/ui/select"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Send } from "lucide-react"; export default function WithdrawalsPageClient({ balances, withdrawals }) { const [withdrawalData, setWithdrawalData] = useState({ currency: "bitcoin", address: "", amount: "", }); const handleWithdraw = async () => { const { currency, address, amount } = withdrawalData; if (!currency || !address || !amount || parseFloat(amount) <= 0) { alert("Please provide valid withdrawal details."); return; } try { const authToken = document.cookie.split("authToken=")[1]; const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/withdraw`, { method: "POST", headers: { Authorization: `Bearer ${authToken}`, "Content-Type": "application/json", }, credentials: "include", body: JSON.stringify({ currency, address, amount }), }); if (!res.ok) throw new Error("Failed to process withdrawal"); alert("Withdrawal request submitted successfully!"); setWithdrawalData({ currency: "bitcoin", address: "", amount: "" }); } catch (error) { console.error("Error processing withdrawal:", error); alert("Failed to process withdrawal. Please try again."); } }; const handleChange = (e) => { const { name, value } = e.target; setWithdrawalData({ ...withdrawalData, [name]: value }); }; return (

Withdraw Funds

{/* Balances Display */}
Bitcoin Balance

{balances.bitcoin} BTC

Litecoin Balance

{balances.litecoin} LTC

Monero Balance

{balances.monero} XMR

{/* Withdrawal Form */}

Request Withdrawal

{/* Withdrawals History */}

Withdrawals History

Date Currency Amount Address Status {withdrawals.length > 0 ? ( withdrawals.map((withdrawal) => ( {withdrawal.date} {withdrawal.currency.toUpperCase()} {withdrawal.amount} {withdrawal.address} {withdrawal.status} )) ) : ( No withdrawals found. )}
); }