d7e82b075f
* adding delegators number info on mixnode details * add PM, Delegators and Avg. Uptime fields to the node list hardcoded * make delegations number dynamic * fixing bg color bug * wip node info statistics * adding basic tooltip new section and some ui * tooltip customisation * progress bar styles * remove not used import * fix info icons color * remove discord icon * Economic dynamics stats endpoint on the explorer API with dummy fixture data * fetching economic-dynamics-stats * Populating the endpoint with real data aggregated from validator api * Introduced new cache functionalities * using explorer-api data * adding marging profit * adding average update * Update network-explorer.yml * adding more info on mix nodes page * display only part of wallet and node id * typo * remove log * adding new values on node response and fix a typo * remove delegators number column * Endpoints for average mixnode uptime * remove TODO * Clippy * some ui fixes for percentage linear progress * GitHub Actions: build storybook for the Network Explorer and add to notification * Fix file extension to `.ts` * Fix up formatting and types * Add storybook * Add story for mix node details economics * Fix unused warning * adding percentage symbol on uptime in mix nodes * Change eslint config * some refactor * progress bar story * wip refactoring * more refactor * adding empty state to the story * change default values for empty state * refactor naming and progress bar contrast * adding hardcoded selection chance and update the storybook * adding selection chance stories * adding the progress bar back * tooltip button padding fix * Endpoints for average mixnode uptime * Fix unused warning * Rustfmt * moking selection chance response and new colors * remove log * fix camelCases issue * remove hardcoded code * remove avg_uptime at mixnodes table * Add jsonchema to uptimeresponse struct - add the route for avg_uptimes * adding space between words * update selection chance colours * adding the 2 missing tooltips * fix up uptimeresponse * fix duplicate entry * fmt * validator-client: use statement * explorer: PR requests Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> Co-authored-by: Fouad <fmtabbara@hotmail.co.uk> Co-authored-by: Jon Häggblad <jon.haggblad@gmail.com> Co-authored-by: Mark Sinclair <mmsinclair@gmail.com> Co-authored-by: tommy <tommyvez@protonmail.com>
134 lines
4.0 KiB
TypeScript
134 lines
4.0 KiB
TypeScript
import {
|
|
BLOCK_API,
|
|
COUNTRY_DATA_API,
|
|
GATEWAYS_API,
|
|
MIXNODE_API,
|
|
MIXNODE_PING,
|
|
MIXNODES_API,
|
|
OVERVIEW_API,
|
|
UPTIME_STORY_API,
|
|
VALIDATORS_API,
|
|
} from './constants';
|
|
|
|
import {
|
|
CountryDataResponse,
|
|
DelegationsResponse,
|
|
GatewayResponse,
|
|
MixNodeDescriptionResponse,
|
|
MixNodeResponse,
|
|
MixNodeResponseItem,
|
|
MixnodeStatus,
|
|
MixNodeEconomicDynamicsStatsResponse,
|
|
StatsResponse,
|
|
StatusResponse,
|
|
SummaryOverviewResponse,
|
|
UptimeStoryResponse,
|
|
ValidatorsResponse,
|
|
} from '../typeDefs/explorer-api';
|
|
|
|
function getFromCache(key: string) {
|
|
const ts = Number(localStorage.getItem('ts'));
|
|
const hasExpired = Date.now() - ts > 5000;
|
|
const curr = localStorage.getItem(key);
|
|
if (curr && !hasExpired) {
|
|
return JSON.parse(curr);
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function storeInCache(key: string, data: any) {
|
|
localStorage.setItem(key, data);
|
|
localStorage.setItem('ts', Date.now().toString());
|
|
}
|
|
|
|
export class Api {
|
|
static fetchOverviewSummary = async (): Promise<SummaryOverviewResponse> => {
|
|
const cache = getFromCache('overview-summary');
|
|
if (cache) {
|
|
return cache;
|
|
}
|
|
const res = await fetch(`${OVERVIEW_API}/summary`);
|
|
const json = await res.json();
|
|
storeInCache('overview-summary', JSON.stringify(json));
|
|
return json;
|
|
};
|
|
|
|
static fetchMixnodes = async (): Promise<MixNodeResponse> => {
|
|
const cachedMixnodes = getFromCache('mixnodes');
|
|
if (cachedMixnodes) {
|
|
return cachedMixnodes;
|
|
}
|
|
const res = await fetch(MIXNODES_API);
|
|
const json = await res.json();
|
|
storeInCache('mixnodes', JSON.stringify(json));
|
|
return json;
|
|
};
|
|
|
|
static fetchMixnodesActiveSetByStatus = async (status: MixnodeStatus): Promise<MixNodeResponse> => {
|
|
const cachedMixnodes = getFromCache(`mixnodes-${status}`);
|
|
if (cachedMixnodes) {
|
|
return cachedMixnodes;
|
|
}
|
|
const res = await fetch(`${MIXNODES_API}/active-set/${status}`);
|
|
const json = await res.json();
|
|
storeInCache(`mixnodes-${status}`, JSON.stringify(json));
|
|
return json;
|
|
};
|
|
|
|
static fetchMixnodeByID = async (id: string): Promise<MixNodeResponseItem | undefined> => {
|
|
const response = await fetch(`${MIXNODE_API}/${id}`);
|
|
|
|
// when the mixnode is not found, returned undefined
|
|
if (response.status === 404) {
|
|
return undefined;
|
|
}
|
|
|
|
return response.json();
|
|
};
|
|
|
|
static fetchGateways = async (): Promise<GatewayResponse> => {
|
|
const res = await fetch(GATEWAYS_API);
|
|
return res.json();
|
|
};
|
|
|
|
static fetchValidators = async (): Promise<ValidatorsResponse> => {
|
|
const res = await fetch(VALIDATORS_API);
|
|
const json = await res.json();
|
|
return json.result;
|
|
};
|
|
|
|
static fetchBlock = async (): Promise<number> => {
|
|
const res = await fetch(BLOCK_API);
|
|
const json = await res.json();
|
|
const { height } = json.result.block.header;
|
|
return height;
|
|
};
|
|
|
|
static fetchCountryData = async (): Promise<CountryDataResponse> => {
|
|
const result: CountryDataResponse = {};
|
|
const res = await fetch(COUNTRY_DATA_API);
|
|
const json = await res.json();
|
|
Object.keys(json).forEach((ISO3) => {
|
|
result[ISO3] = { ISO3, nodes: json[ISO3] };
|
|
});
|
|
return result;
|
|
};
|
|
|
|
static fetchDelegationsById = async (id: string): Promise<DelegationsResponse> =>
|
|
(await fetch(`${MIXNODE_API}/${id}/delegations`)).json();
|
|
|
|
static fetchStatsById = async (id: string): Promise<StatsResponse> =>
|
|
(await fetch(`${MIXNODE_API}/${id}/stats`)).json();
|
|
|
|
static fetchMixnodeDescriptionById = async (id: string): Promise<MixNodeDescriptionResponse> =>
|
|
(await fetch(`${MIXNODE_API}/${id}/description`)).json();
|
|
|
|
static fetchMixnodeEconomicDynamicsStatsById = async (id: string): Promise<MixNodeEconomicDynamicsStatsResponse> =>
|
|
(await fetch(`${MIXNODE_API}/${id}/economic-dynamics-stats`)).json();
|
|
|
|
static fetchStatusById = async (id: string): Promise<StatusResponse> => (await fetch(`${MIXNODE_PING}/${id}`)).json();
|
|
|
|
static fetchUptimeStoryById = async (id: string): Promise<UptimeStoryResponse> =>
|
|
(await fetch(`${UPTIME_STORY_API}/${id}/history`)).json();
|
|
}
|