diff --git a/bidv.html b/bidv.html
deleted file mode 100644
index 134926c..0000000
--- a/bidv.html
+++ /dev/null
@@ -1,266 +0,0 @@
-
-
-
- Please select both start and end dates.
");
+ return;
+ }
+ if (startDate > endDate) {
+ setStatus("Start date must be before or equal to end date.
");
+ return;
+ }
+ setStatus("Fetching data, please wait...
");
+ setLoading(true);
+ setResults([]);
+ const dates = getDateRange(startDate, endDate);
+ const newResults = [];
+ for (let i = 0; i < dates.length; i++) {
+ const dateObj = dates[i];
+ const dateStr = formatDate(dateObj);
+ setStatus(`No data found for the selected range.
");
+ setLoading(false);
+ }
+
+ return (
+
-
-
-
- -
- Get started by editing
src/app/page.js.
-
- - Save and see your changes instantly.
-
+ const router = useRouter();
+ const [bank, setBank] = useState("bidv");
+ const [startDate, setStartDate] = useState("");
+ const [endDate, setEndDate] = useState("");
-
-
-
+ function handleBankChange(e) {
+ setBank(e.target.value);
+ if (e.target.value === "bidv") {
+ router.push("/bidv");
+ } else if (e.target.value === "tcb") {
+ router.push("/tcb");
+ }
+ }
+
+ return (
+
);
}
diff --git a/src/app/tcb/page.jsx b/src/app/tcb/page.jsx
new file mode 100644
index 0000000..55c296f
--- /dev/null
+++ b/src/app/tcb/page.jsx
@@ -0,0 +1,163 @@
+"use client";
+import { useState } from "react";
+
+export default function TcbPage() {
+ const [startDate, setStartDate] = useState("");
+ const [endDate, setEndDate] = useState("");
+ const [status, setStatus] = useState("");
+ const [results, setResults] = useState([]);
+ const [loading, setLoading] = useState(false);
+
+ function formatDate(date) {
+ const d = new Date(date);
+ const day = String(d.getDate()).padStart(2, "0");
+ const month = String(d.getMonth() + 1).padStart(2, "0");
+ const year = d.getFullYear();
+ return `${day}/${month}/${year}`;
+ }
+
+ function getDateRange(start, end) {
+ const dates = [];
+ let current = new Date(start);
+ const last = new Date(end);
+ while (current <= last) {
+ dates.push(new Date(current));
+ current.setDate(current.getDate() + 1);
+ }
+ return dates;
+ }
+
+ async function fetchUSD(dateObj) {
+ const yyyy = dateObj.getFullYear();
+ const mm = String(dateObj.getMonth() + 1).padStart(2, "0");
+ const dd = String(dateObj.getDate()).padStart(2, "0");
+ const dateStr = `${yyyy}-${mm}-${dd}`;
+ const url = `https://techcombank.com/content/techcombank/web/vn/vi/cong-cu-tien-ich/ty-gia/_jcr_content.exchange-rates.${dateStr}.integration.json`;
+ try {
+ const res = await fetch(url);
+ if (!res.ok) throw new Error("API error");
+ const data = await res.json();
+ if (!data.exchangeRate || !data.exchangeRate.data) return null;
+ const usd = data.exchangeRate.data.find((item) => item.label === "USD (50,100)");
+ if (!usd) return null;
+ return {
+ date: formatDate(dateObj),
+ label: usd.label,
+ askRate: usd.askRate,
+ bidRateCK: usd.bidRateCK,
+ bidRateTM: usd.bidRateTM,
+ askRateTM: usd.askRateTM,
+ sourceCurrency: usd.sourceCurrency,
+ targetCurrency: usd.targetCurrency,
+ };
+ } catch (e) {
+ return null;
+ }
+ }
+
+ function renderTable(data) {
+ return (
+
+
+
+ | Date |
+ label |
+ askRate |
+ bidRateCK |
+ bidRateTM |
+ askRateTM |
+ sourceCurrency |
+ targetCurrency |
+
+
+
+ {data.map((row, i) => (
+
+ | {row.date} |
+ {row.label} |
+ {row.askRate || ""} |
+ {row.bidRateCK || ""} |
+ {row.bidRateTM || ""} |
+ {row.askRateTM || ""} |
+ {row.sourceCurrency} |
+ {row.targetCurrency} |
+
+ ))}
+
+
+ );
+ }
+
+ function exportCSV(data) {
+ const header = ["Date", "label", "askRate", "bidRateCK", "bidRateTM", "askRateTM", "sourceCurrency", "targetCurrency"];
+ const rows = [header];
+ for (const row of data) {
+ rows.push([
+ row.date,
+ row.label,
+ row.askRate,
+ row.bidRateCK,
+ row.bidRateTM,
+ row.askRateTM,
+ row.sourceCurrency,
+ row.targetCurrency,
+ ]);
+ }
+ const csvContent = rows
+ .map((r) => r.map((cell) => '"' + String(cell || "").replace(/"/g, '""') + '"').join(","))
+ .join("\r\n");
+ const blob = new Blob([csvContent], { type: "text/csv" });
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = "usd_exchange_rates_tcb.csv";
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ URL.revokeObjectURL(url);
+ }
+
+ async function handleFetch() {
+ if (!startDate || !endDate) {
+ setStatus("
Please select both start and end dates.
");
+ return;
+ }
+ if (startDate > endDate) {
+ setStatus("
Start date must be before or equal to end date.
");
+ return;
+ }
+ setStatus("
Fetching data, please wait...
");
+ setLoading(true);
+ setResults([]);
+ const dates = getDateRange(startDate, endDate);
+ const newResults = [];
+ for (let i = 0; i < dates.length; i++) {
+ const dateObj = dates[i];
+ const dateStr = formatDate(dateObj);
+ setStatus(`
Fetching: ${dateStr} (${i + 1}/${dates.length})
`);
+ const usd = await fetchUSD(dateObj);
+ if (usd) {
+ newResults.push(usd);
+ setResults([...newResults]);
+ }
+ }
+ setStatus(newResults.length ? "" : "
No data found for the selected range.
");
+ setLoading(false);
+ }
+
+ return (
+
+
Exchange Rate Export (USD, Techcombank)
+
+
+ setStartDate(e.target.value)} />
+
+ setEndDate(e.target.value)} />
+
+
+
+
+ {renderTable(results)}
+
+ );
+}
\ No newline at end of file
diff --git a/tcb.html b/tcb.html
deleted file mode 100644
index fdbe1e4..0000000
--- a/tcb.html
+++ /dev/null
@@ -1,242 +0,0 @@
-
-
-
-
-
-
Exchange Rate Export - Techcombank
-
-
-
-
-
Exchange Rate Export (USD, Techcombank)
-
-
-
-
-
-
-
-
-
-
-
-
- | Date |
- label |
- askRate |
- bidRateCK |
- bidRateTM |
- askRateTM |
- sourceCurrency |
- targetCurrency |
-
-
-
-
-
-
-
-
\ No newline at end of file