From 0652d85f56e05cc38580633f88d8ecc399accdeb Mon Sep 17 00:00:00 2001 From: crowetic Date: Tue, 10 Jun 2025 13:11:53 -0700 Subject: [PATCH] modified api URL so that it will always pass the correct path when calling fetch for trades --- src/App.tsx | 32 ++++++++++++++++++++++++++++++-- src/utils/qortTrades.ts | 9 ++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 126e9ec..ca16c47 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -60,6 +60,9 @@ export default function App() { const [cacheLoaded, setCacheLoaded] = useState(false); const [needsUpdate, setNeedsUpdate] = useState>({}); const [isFetching, setIsFetching] = useState>({}); + const [fetchProgress, setFetchProgress] = useState>( + {} + ); // --- Helpers --- const getLatest = (trades: Trade[]) => @@ -141,6 +144,7 @@ export default function App() { reverse: true, }); all = all.concat(batch); + setFetchProgress((m) => ({ ...m, [chain]: all.length })); setAllChainTrades((m) => ({ ...m, [chain]: all })); if (batch.length < BATCH) break; offset += BATCH; @@ -170,6 +174,7 @@ export default function App() { reverse: true, }); newTrades = newTrades.concat(batch); + setFetchProgress((m) => ({ ...m, [chain]: newTrades.length })); if (batch.length < BATCH) break; offset += BATCH; } @@ -201,17 +206,40 @@ export default function App() { }); } - if (!cacheLoaded) + if (!cacheLoaded) { + const prog = fetchProgress[selectedChain] || 0; return ( - + Loading trades… + + Fetched: {prog.toLocaleString()} trades + + + {prog > 0 && ( + + + + )} ); + } const tradesCount = (allChainTrades[selectedChain] || []).length; const latestTS = getLatest(allChainTrades[selectedChain] || []); diff --git a/src/utils/qortTrades.ts b/src/utils/qortTrades.ts index 3dc0349..682d949 100644 --- a/src/utils/qortTrades.ts +++ b/src/utils/qortTrades.ts @@ -37,8 +37,15 @@ export async function fetchTrades({ if (minimumTimestamp === 0) { params.delete('minimumTimestamp'); } + function getApiRoot() { + const { origin, pathname } = window.location; + // if path contains “/render”, cut from there + const i = pathname.indexOf('/render/'); + return i === -1 ? origin : origin + pathname.slice(0, i); + } + const API_ROOT = getApiRoot(); - const url = `crosschain/trades?${params.toString()}`; + const url = `${API_ROOT}/crosschain/trades?${params.toString()}`; const resp = await fetch(url); if (!resp.ok) throw new Error(`HTTP ${resp.status}`); return await resp.json();