setup explorer states
This commit is contained in:
parent
2f0364c0d8
commit
9c849193a4
6 changed files with 86 additions and 25 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ function LatestBlocks({ fetchedInfo, fetchedLatestBlocks }: { fetchedInfo: Info
|
|||
const [info, setInfo] = useState<Info | null>(fetchedInfo);
|
||||
const prevTxCount = useRef<number>(0);
|
||||
const [headerStatus, setHeaderStatus] = useState<JSX.Element | null>(null);
|
||||
const [lastUpdated, setLastUpdated] = useState<number | null>(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 (
|
||||
<div className={classes(styles["blockchain__latest_blocks"], styles["custom-scroll"])}>
|
||||
<h3 className={styles["blockchain__latest_blocks__title"]}>
|
||||
Latest Blocks <span className={styles["status__badge"]}><InfoIcon /> Last updated 26 mins ago</span>
|
||||
Latest Blocks
|
||||
{lastUpdated && (
|
||||
<span className={styles["status__badge"]}><InfoIcon /> Last updated {lastUpdatedText}</span>
|
||||
)}
|
||||
</h3>
|
||||
|
||||
<Table
|
||||
|
|
|
|||
|
|
@ -18,13 +18,19 @@ export interface MainPageProps {
|
|||
info: Info | null;
|
||||
latestBlocks: Block[];
|
||||
txPoolElements: PoolElement[]
|
||||
explorerStatus: ExplorerStatusType;
|
||||
}
|
||||
|
||||
function MainPage({ visibilityInfo: fetchedVisibilityInfo, isOnline: fetchedIsOnline, info, latestBlocks, txPoolElements }: MainPageProps) {
|
||||
function MainPage({ visibilityInfo: fetchedVisibilityInfo, explorerStatus: ssrExplorerStatus, info, latestBlocks, txPoolElements }: MainPageProps) {
|
||||
|
||||
|
||||
console.log('ssrExplorerStatus', ssrExplorerStatus);
|
||||
|
||||
|
||||
const [burgerOpened, setBurgerOpened] = useState(false);
|
||||
|
||||
const [visibilityInfo, setVisibilityInfo] = useState<VisibilityInfo | null>(fetchedVisibilityInfo);
|
||||
const [explorerStatus, setExplorerStatus] = useState<ExplorerStatusType>(fetchedIsOnline ? "online" : "offline");
|
||||
const [explorerStatus, setExplorerStatus] = useState<ExplorerStatusType>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue