diff --git a/server/server.ts b/server/server.ts index e19f2c6..59e549d 100644 --- a/server/server.ts +++ b/server/server.ts @@ -1119,23 +1119,23 @@ async function waitForDb() { const entitiesToExclude = [ "lastUpdated", - "btc", - "eth", + "btc", + "eth", "ltc", - "bch", + "bch", "bnb", - "eos", + "eos", "xrp", - "xlm", + "xlm", "link", - "dot", - "yfi", + "dot", + "yfi", ] for (const entity of entitiesToExclude) { delete fiatPrices[entity]; } - + return fiatPrices; } @@ -1312,6 +1312,16 @@ async function waitForDb() { })) + app.get('/api/explorer_status', exceptionHandler(async (req, res) => { + + res.json({ + success: true, + data: { + explorer_status: state.explorer_status, + } + }); + })); + app.get('/api/get_matrix_addresses', exceptionHandler(async (req, res) => { const { page, items } = req.query; @@ -1583,6 +1593,10 @@ async function waitForDb() { let count = (blockInfo?.height || 0) - lastBlock.height + 1; if (count > 100) { + setState({ + ...state, + explorer_status: 'syncing' + }); count = 100; } if (count < 0) { @@ -1854,15 +1868,33 @@ async function waitForDb() { const getInfoTimer = async () => { console.log('Called git info timer'); + // chech explorer status + + const infoResponse = await get_info().then(r => r.data).catch(_ => null); + + if (!infoResponse || !infoResponse?.result?.height) { + setState({ + ...state, + explorer_status: "offline" + }) + } else { + setState({ + ...state, + explorer_status: "online" + }); + } + if (!state.now_delete_offers) { try { const response = await get_info(); const databaseHeight = await Block.max('height') || 0; - console.log('databaseHeight', databaseHeight) + console.log('databaseHeight', databaseHeight); + console.log('blockchain height', response.data?.result?.height); + setBlockInfo({ ...response.data.result, database_height: databaseHeight diff --git a/server/utils/states.ts b/server/utils/states.ts index c2097a3..24165dc 100644 --- a/server/utils/states.ts +++ b/server/utils/states.ts @@ -49,6 +49,7 @@ export interface State { [key: string]: number } zanoBurned?: number; + explorer_status: "online" | "offline" | "syncing"; } export let state: State = { @@ -61,6 +62,7 @@ export let state: State = { pools_array: [], priceData: {}, fiat_rates: {}, + explorer_status: "offline", } export function setState(newState: State) { diff --git a/src/components/default/LatestBlocks/LatestBlocks.tsx b/src/components/default/LatestBlocks/LatestBlocks.tsx index c1f06b8..6b30455 100644 --- a/src/components/default/LatestBlocks/LatestBlocks.tsx +++ b/src/components/default/LatestBlocks/LatestBlocks.tsx @@ -19,6 +19,7 @@ function LatestBlocks({ fetchedInfo, fetchedLatestBlocks }: { fetchedInfo: Info const [info, setInfo] = useState(fetchedInfo); const prevTxCount = useRef(0); const [headerStatus, setHeaderStatus] = useState(null); + const [lastUpdated, setLastUpdated] = useState(null); useEffect(() => { async function fetchInfo() { @@ -71,6 +72,7 @@ function LatestBlocks({ fetchedInfo, fetchedLatestBlocks }: { fetchedInfo: Info async function fetchBlocks() { try { setHeaderStatus(<>Scanning new transactions...); + await new Promise(resolve => setTimeout(resolve, 1000)); const items = parseInt(itemsOnPage, 10) || 0; const pageNumber = parseInt(page, 10) || 0; @@ -100,6 +102,8 @@ function LatestBlocks({ fetchedInfo, fetchedLatestBlocks }: { fetchedInfo: Info } else { setHeaderStatus(null); } + + setLastUpdated(+Date.now()); } catch (error) { console.error(error); setHeaderStatus(null); @@ -129,10 +133,15 @@ function LatestBlocks({ fetchedInfo, fetchedLatestBlocks }: { fetchedInfo: Info ] }); + const lastUpdatedText = lastUpdated ? Utils.timeElapsedString(lastUpdated) : undefined; + return (

- Latest Blocks Last updated 26 mins ago + Latest Blocks + {lastUpdated && ( + Last updated {lastUpdatedText} + )}

(fetchedVisibilityInfo); - const [explorerStatus, setExplorerStatus] = useState(fetchedIsOnline ? "online" : "offline"); + const [explorerStatus, setExplorerStatus] = useState(ssrExplorerStatus); useEffect(() => { async function fetchVisibilityInfo() { @@ -34,18 +40,17 @@ function MainPage({ visibilityInfo: fetchedVisibilityInfo, isOnline: fetchedIsOn } async function checkOnline() { - try { - setExplorerStatus("syncing"); - const result = await Fetch.getInfo(); - if (result.status === "OK") { - setExplorerStatus("online"); - } else { + const explorerStatus = await Fetch.getExplorerStatus(); + + if (explorerStatus.success === false) { setExplorerStatus("offline"); + } else { + setExplorerStatus(explorerStatus.data.explorer_status); } + } catch (error) { - console.log(error); - setExplorerStatus("offline"); + console.error("Error checking online status:", error); } } diff --git a/src/utils/methods.ts b/src/utils/methods.ts index 88f2387..0f0a731 100644 --- a/src/utils/methods.ts +++ b/src/utils/methods.ts @@ -19,6 +19,10 @@ class Fetch { return await fetch(this.proxyPath + "/get_info").then(res => res.json()); } + static async getExplorerStatus() { + return await fetch(this.proxyPath + "/explorer_status").then(res => res.json()); + } + static async getBlockDetails(page: number, blocksAmount: number) { return await fetch(this.proxyPath + `/get_blocks_details/${page}/${blocksAmount}`).then(res => res.json()); } diff --git a/src/utils/ssr.ts b/src/utils/ssr.ts index 23fb440..c32b329 100644 --- a/src/utils/ssr.ts +++ b/src/utils/ssr.ts @@ -15,7 +15,7 @@ export async function getMainPageProps() { let visibilityInfo: VisibilityInfo | null = null; let info: Info | null = null; let latestBlocks: Block[] = []; - let isOnline: boolean = false; + let explorerStatus: "online" | "offline" | "syncing" = "offline"; let txPoolElements: PoolElement[] = []; try { @@ -36,16 +36,25 @@ export async function getMainPageProps() { if (response.success === false) { info = null; - isOnline = false; } else { info = response; - isOnline = response.status === "OK"; } } catch { - isOnline = false; info = null; } + + try { + const status = await Fetch.getExplorerStatus(); + + + explorerStatus = status?.data?.explorer_status || "offline"; + + } catch (error) { + console.error("Error fetching explorer status:", error); + explorerStatus = "offline"; + } + try { if (info) { const { height, database_height } = info; @@ -78,7 +87,7 @@ export async function getMainPageProps() { return { props: { visibilityInfo, - isOnline, + explorerStatus, info, latestBlocks, txPoolElements,