From a5cefeba1ff4f2e4908f02c23f64aa3f79c13895 Mon Sep 17 00:00:00 2001 From: PhilReact Date: Tue, 1 Apr 2025 19:31:37 +0300 Subject: [PATCH] updated trade history --- src/components/history/History.tsx | 52 +++++++++++++++++++++--------- src/pages/Home/Home.tsx | 2 +- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/components/history/History.tsx b/src/components/history/History.tsx index cf039e9..867180d 100644 --- a/src/components/history/History.tsx +++ b/src/components/history/History.tsx @@ -15,10 +15,11 @@ import gameContext from "../../contexts/gameContext"; import HistoryList from "./HistoryList"; import { ShowingFont, Refresh, HistoryButtonRow, HistoryButton } from "./History-styles"; -export const History = ({ qortAddress, show }) => { +export const History = ({ qortAddress, show, userPublicKey }) => { + const [buyHistory, setBuyHistory] = useState({}); const [sellHistory, setSellHistory] = useState({}); - + const [allHistory, setAllHistory] = useState({}); const { selectedCoin } = useContext(gameContext); const [mode, setMode] = useState("buyHistory"); const [open, setOpen] = useState(false); @@ -26,18 +27,21 @@ export const History = ({ qortAddress, show }) => { const selectedHistory = useMemo(() => { if (mode === "buyHistory") return buyHistory[selectedCoin] || []; if (mode === "sellHistory") return sellHistory[selectedCoin] || []; - }, [selectedCoin, buyHistory, sellHistory, mode]); + if (mode === "allHistory") return allHistory[selectedCoin] || []; + }, [selectedCoin, buyHistory, sellHistory, mode, allHistory]); const getBuyHistory = useCallback( - (address, foreignBlockchain, mode, limit = 20) => { + (publicKey, foreignBlockchain, mode, limit = 20) => { setOpen(true); let historyUrl; if (mode === "buyHistory") { - historyUrl = `/crosschain/trades?foreignBlockchain=${foreignBlockchain}&buyerAddress=${address}&limit=${limit}&reverse=true`; + historyUrl = `/crosschain/trades?foreignBlockchain=${foreignBlockchain}&buyerPublicKey=${publicKey}&limit=${limit}&reverse=true`; } if (mode === "sellHistory") { - historyUrl = `/crosschain/trades?foreignBlockchain=${foreignBlockchain}&sellerAddress=${address}&limit=${limit}&reverse=true`; + historyUrl = `/crosschain/trades?foreignBlockchain=${foreignBlockchain}&sellerPublicKey=${publicKey}&limit=${limit}&reverse=true`; + } + if(mode === 'allHistory'){ + historyUrl = `/crosschain/trades?foreignBlockchain=${foreignBlockchain}&limit=${limit}&reverse=true`; } - fetch(historyUrl) .then((response) => { return response.json(); @@ -59,6 +63,14 @@ export const History = ({ qortAddress, show }) => { }; }); } + if (mode === "allHistory") { + setAllHistory((prev) => { + return { + ...prev, + [foreignBlockchain]: data, + }; + }); + } }) .catch(() => {}) .finally(() => { @@ -69,12 +81,12 @@ export const History = ({ qortAddress, show }) => { ); useEffect(() => { - if (!qortAddress || !selectedCoin) return; + if (!userPublicKey || !selectedCoin) return; if (mode === "buyHistory" && buyHistory[selectedCoin]) return; if (mode === "sellHistory" && sellHistory[selectedCoin]) return; - - getBuyHistory(qortAddress, selectedCoin, mode); - }, [qortAddress, selectedCoin, buyHistory, mode]); + if (mode === "allHistory" && allHistory[selectedCoin]) return; + getBuyHistory(userPublicKey, selectedCoin, mode); + }, [userPublicKey, selectedCoin, buyHistory, mode, sellHistory, allHistory]); return ( { display: show ? "block" : "none", }} > - + { setMode("buyHistory"); }} > - Buy History + My Buy History { setMode("sellHistory"); }} > - Sell History + My Sell History + + { + setMode("allHistory"); + }} + > + Historic Trades { - getBuyHistory(qortAddress, selectedCoin, mode); + getBuyHistory(userPublicKey, selectedCoin, mode); }} > diff --git a/src/pages/Home/Home.tsx b/src/pages/Home/Home.tsx index c28d91e..6ee3fc1 100644 --- a/src/pages/Home/Home.tsx +++ b/src/pages/Home/Home.tsx @@ -112,7 +112,7 @@ export const HomePage = () => { - + );