Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 64823b06c7 | |||
| fb689a35e6 | |||
| 1847a84372 | |||
| 65d1589968 | |||
| b3d87156db | |||
| 28b4fe7e7e | |||
| 9479d2a383 | |||
| 886b4410aa | |||
| b51358fb12 | |||
| 53e3acaa37 | |||
| 978817baf7 | |||
| 9319a5ec04 | |||
| 3186db2915 | |||
| ff7671f28a | |||
| cbe8eec2a4 | |||
| 42f9edd408 | |||
| 128cf7c070 | |||
| 79e5004849 | |||
| 0d6722f9f5 | |||
| d458df9c34 | |||
| 7a8ac59a36 | |||
| ad3eb7a84c | |||
| 135f248eba | |||
| 7012bf9886 | |||
| 88aa32ddeb | |||
| 7c1c9976f0 | |||
| 4ee7f7eaf5 | |||
| 778772d96a | |||
| 5b791b41aa | |||
| 4b7e51fc3b | |||
| 0a42dd3e0d | |||
| 7cf49f642d | |||
| 089ab65dd7 | |||
| c1fabae770 | |||
| 3ed7cfa381 | |||
| 4fe83da99d | |||
| 4f81fc7400 | |||
| 6d601ca654 | |||
| cea3ad9908 | |||
| e4ecd099cc | |||
| 0723542c39 | |||
| 523e559ff8 | |||
| 02b27573de | |||
| 8f229737a3 | |||
| 1afd13d6e0 | |||
| df10b5595a | |||
| 443031ba66 | |||
| 8d340a49d3 | |||
| e0925d3c7f | |||
| 89d391da29 | |||
| cc2d7d34d2 | |||
| 969070f938 | |||
| 3dfcae9369 | |||
| 32a4bf1172 | |||
| 433cac8c58 | |||
| 4fc64a072c |
@@ -35,6 +35,7 @@
|
|||||||
"@uidotdev/usehooks": "^2.4.1",
|
"@uidotdev/usehooks": "^2.4.1",
|
||||||
"chain-registry": "^1.69.64",
|
"chain-registry": "^1.69.64",
|
||||||
"cldr-compact-number": "^0.4.0",
|
"cldr-compact-number": "^0.4.0",
|
||||||
|
"d3-scale": "^4.0.2",
|
||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
"i18next": "^24.2.2",
|
"i18next": "^24.2.2",
|
||||||
"i18next-resources-to-backend": "^1.2.1",
|
"i18next-resources-to-backend": "^1.2.1",
|
||||||
@@ -49,6 +50,8 @@
|
|||||||
"react-i18next": "^15.4.0",
|
"react-i18next": "^15.4.0",
|
||||||
"react-markdown": "^9.0.3",
|
"react-markdown": "^9.0.3",
|
||||||
"react-random-avatars": "^1.3.1",
|
"react-random-avatars": "^1.3.1",
|
||||||
|
"react-simple-maps": "^3.0.0",
|
||||||
|
"react-tooltip": "^5.28.1",
|
||||||
"react-world-flags": "^1.6.0",
|
"react-world-flags": "^1.6.0",
|
||||||
"zod": "^3.24.1"
|
"zod": "^3.24.1"
|
||||||
},
|
},
|
||||||
@@ -57,6 +60,7 @@
|
|||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^18",
|
"@types/react": "^18",
|
||||||
"@types/react-dom": "^18",
|
"@types/react-dom": "^18",
|
||||||
|
"@types/react-simple-maps": "^3.0.6",
|
||||||
"eslint": "^8",
|
"eslint": "^8",
|
||||||
"eslint-config-next": "15.0.3",
|
"eslint-config-next": "15.0.3",
|
||||||
"lefthook": "^1.8.5",
|
"lefthook": "^1.8.5",
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 218 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 223 KiB |
@@ -1,12 +1,14 @@
|
|||||||
|
import { countryCodeMap } from "@/assets/countryCodes";
|
||||||
import { addSeconds } from "date-fns";
|
import { addSeconds } from "date-fns";
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import type {
|
import type {
|
||||||
|
CountryDataResponse,
|
||||||
CurrentEpochData,
|
CurrentEpochData,
|
||||||
ExplorerData,
|
ExplorerData,
|
||||||
GatewayStatus,
|
GatewayStatus,
|
||||||
IAccountBalancesInfo,
|
IAccountBalancesInfo,
|
||||||
IObservatoryNode,
|
|
||||||
IPacketsAndStakingData,
|
IPacketsAndStakingData,
|
||||||
|
NS_NODE,
|
||||||
NodeRewardDetails,
|
NodeRewardDetails,
|
||||||
NymTokenomics,
|
NymTokenomics,
|
||||||
ObservatoryBalance,
|
ObservatoryBalance,
|
||||||
@@ -15,7 +17,7 @@ import {
|
|||||||
CURRENT_EPOCH,
|
CURRENT_EPOCH,
|
||||||
CURRENT_EPOCH_REWARDS,
|
CURRENT_EPOCH_REWARDS,
|
||||||
DATA_OBSERVATORY_BALANCES_URL,
|
DATA_OBSERVATORY_BALANCES_URL,
|
||||||
DATA_OBSERVATORY_NODES_URL,
|
NS_API_NODES,
|
||||||
NYM_ACCOUNT_ADDRESS,
|
NYM_ACCOUNT_ADDRESS,
|
||||||
NYM_PRICES_API,
|
NYM_PRICES_API,
|
||||||
OBSERVATORY_GATEWAYS_URL,
|
OBSERVATORY_GATEWAYS_URL,
|
||||||
@@ -56,15 +58,12 @@ export const fetchGatewayStatus = async (
|
|||||||
export const fetchNodeDelegations = async (
|
export const fetchNodeDelegations = async (
|
||||||
id: number,
|
id: number,
|
||||||
): Promise<NodeRewardDetails[]> => {
|
): Promise<NodeRewardDetails[]> => {
|
||||||
const response = await fetch(
|
const response = await fetch(`${NS_API_NODES}/${id}/delegations`, {
|
||||||
`${DATA_OBSERVATORY_NODES_URL}/${id}/delegations`,
|
headers: {
|
||||||
{
|
Accept: "application/json",
|
||||||
headers: {
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
Accept: "application/json",
|
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Failed to fetch delegations");
|
throw new Error("Failed to fetch delegations");
|
||||||
@@ -192,38 +191,6 @@ export const fetchAccountBalance = async (
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchObservatoryNodes = async (): Promise<IObservatoryNode[]> => {
|
|
||||||
const allNodes: IObservatoryNode[] = [];
|
|
||||||
let page = 1;
|
|
||||||
const PAGE_SIZE = 200;
|
|
||||||
let hasMoreData = true;
|
|
||||||
|
|
||||||
while (hasMoreData) {
|
|
||||||
const response = await fetch(
|
|
||||||
`${DATA_OBSERVATORY_NODES_URL}?page=${page}&limit=${PAGE_SIZE}`,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Accept: "application/json",
|
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to fetch observatory nodes (page ${page})`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodes: IObservatoryNode[] = await response.json();
|
|
||||||
allNodes.push(...nodes);
|
|
||||||
|
|
||||||
if (nodes.length < PAGE_SIZE) {
|
|
||||||
hasMoreData = false; // Stop fetching when the last page has fewer than 200 items
|
|
||||||
} else {
|
|
||||||
page++; // Move to the next page
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return allNodes;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 🔹 Fetch NYM Price
|
// 🔹 Fetch NYM Price
|
||||||
export const fetchNymPrice = async (): Promise<NymTokenomics> => {
|
export const fetchNymPrice = async (): Promise<NymTokenomics> => {
|
||||||
@@ -239,3 +206,104 @@ export const fetchNymPrice = async (): Promise<NymTokenomics> => {
|
|||||||
const data: NymTokenomics = await res.json();
|
const data: NymTokenomics = await res.json();
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchNSApiNodes = async (): Promise<NS_NODE[]> => {
|
||||||
|
if (!NS_API_NODES) {
|
||||||
|
throw new Error("NS_API_NODES URL is not defined");
|
||||||
|
}
|
||||||
|
|
||||||
|
const allNodes: any[] = [];
|
||||||
|
let page = 0;
|
||||||
|
const PAGE_SIZE = 200;
|
||||||
|
let totalItems = 0;
|
||||||
|
let hasMoreData = true;
|
||||||
|
|
||||||
|
while (hasMoreData) {
|
||||||
|
const response = await fetch(
|
||||||
|
`${NS_API_NODES}?page=${page}&size=${PAGE_SIZE}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json",
|
||||||
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to fetch NS API nodes (page ${page}): ${response.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
const nodes: any[] = data.items || [];
|
||||||
|
allNodes.push(...nodes);
|
||||||
|
|
||||||
|
// Get total count from response
|
||||||
|
totalItems = data.total || 0;
|
||||||
|
|
||||||
|
// Check if we've fetched all items
|
||||||
|
if (allNodes.length >= totalItems) {
|
||||||
|
hasMoreData = false;
|
||||||
|
} else {
|
||||||
|
page++; // Move to the next page
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return allNodes;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchWorldMapCountries = async (): Promise<{
|
||||||
|
countries: CountryDataResponse;
|
||||||
|
totalCountries: number;
|
||||||
|
uniqueLocations: number;
|
||||||
|
totalServers: number;
|
||||||
|
}> => {
|
||||||
|
// Fetch all nodes from the NS API
|
||||||
|
const nodes = await fetchNSApiNodes();
|
||||||
|
|
||||||
|
// Create a map to count nodes by country
|
||||||
|
const countryCounts: Record<string, number> = {};
|
||||||
|
// Set to track unique cities
|
||||||
|
const uniqueCities = new Set<string>();
|
||||||
|
|
||||||
|
// Process each node
|
||||||
|
for (const node of nodes) {
|
||||||
|
// Get the 2-letter country code from the node's geoip data
|
||||||
|
const twoLetterCode = node.geoip?.country;
|
||||||
|
|
||||||
|
if (twoLetterCode) {
|
||||||
|
// Convert to 3-letter country code
|
||||||
|
const threeLetterCode = countryCodeMap[twoLetterCode] || twoLetterCode;
|
||||||
|
|
||||||
|
// Increment the count for this country
|
||||||
|
countryCounts[threeLetterCode] =
|
||||||
|
(countryCounts[threeLetterCode] || 0) + 1;
|
||||||
|
|
||||||
|
// Add city to unique cities set if it exists
|
||||||
|
if (node.geoip?.city) {
|
||||||
|
uniqueCities.add(node.geoip.city);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If no geoip data, count it as unknown
|
||||||
|
countryCounts[""] = (countryCounts[""] || 0) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the counts to the required format
|
||||||
|
const result: CountryDataResponse = {};
|
||||||
|
|
||||||
|
for (const [threeLetterCode, count] of Object.entries(countryCounts)) {
|
||||||
|
result[threeLetterCode] = {
|
||||||
|
ISO3: threeLetterCode,
|
||||||
|
nodes: count,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
countries: result,
|
||||||
|
totalCountries: Object.keys(countryCounts).length,
|
||||||
|
uniqueLocations: uniqueCities.size,
|
||||||
|
totalServers: nodes.length,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -72,56 +72,59 @@ export interface ExplorerData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type NodeDescription = {
|
export type NodeDescription = {
|
||||||
last_polled: string;
|
authenticator: {
|
||||||
|
address: string;
|
||||||
|
};
|
||||||
|
auxiliary_details: {
|
||||||
|
accepted_operator_terms_and_conditions: boolean;
|
||||||
|
announce_ports: {
|
||||||
|
mix_port: number | null;
|
||||||
|
verloc_port: number | null;
|
||||||
|
};
|
||||||
|
location: string;
|
||||||
|
};
|
||||||
|
build_information: {
|
||||||
|
binary_name: string;
|
||||||
|
build_timestamp: string;
|
||||||
|
build_version: string;
|
||||||
|
cargo_profile: string;
|
||||||
|
cargo_triple: string;
|
||||||
|
commit_branch: string;
|
||||||
|
commit_sha: string;
|
||||||
|
commit_timestamp: string;
|
||||||
|
rustc_channel: string;
|
||||||
|
rustc_version: string;
|
||||||
|
};
|
||||||
|
declared_role: {
|
||||||
|
entry: boolean;
|
||||||
|
exit_ipr: boolean;
|
||||||
|
exit_nr: boolean;
|
||||||
|
mixnode: boolean;
|
||||||
|
};
|
||||||
host_information: {
|
host_information: {
|
||||||
ip_address: string[];
|
|
||||||
hostname: string;
|
hostname: string;
|
||||||
|
ip_address: [string, string];
|
||||||
keys: {
|
keys: {
|
||||||
ed25519: string;
|
ed25519: string;
|
||||||
x25519: string;
|
x25519: string;
|
||||||
x25519_noise: string | null;
|
x25519_noise: string | null;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
declared_role: {
|
ip_packet_router: {
|
||||||
mixnode: boolean;
|
address: string;
|
||||||
entry: boolean;
|
|
||||||
exit_nr: boolean;
|
|
||||||
exit_ipr: boolean;
|
|
||||||
};
|
};
|
||||||
auxiliary_details: {
|
last_polled: string;
|
||||||
location: string;
|
mixnet_websockets: {
|
||||||
announce_ports: {
|
ws_port: number;
|
||||||
verloc_port: number | null;
|
wss_port: number;
|
||||||
mix_port: number | null;
|
|
||||||
};
|
|
||||||
accepted_operator_terms_and_conditions: boolean;
|
|
||||||
};
|
|
||||||
build_information: {
|
|
||||||
binary_name: string;
|
|
||||||
build_timestamp: string;
|
|
||||||
build_version: string;
|
|
||||||
commit_sha: string;
|
|
||||||
commit_timestamp: string;
|
|
||||||
commit_branch: string;
|
|
||||||
rustc_version: string;
|
|
||||||
rustc_channel: string;
|
|
||||||
cargo_profile: string;
|
|
||||||
cargo_triple: string;
|
|
||||||
};
|
};
|
||||||
network_requester: {
|
network_requester: {
|
||||||
address: string;
|
address: string;
|
||||||
uses_exit_policy: boolean;
|
uses_exit_policy: boolean;
|
||||||
};
|
};
|
||||||
ip_packet_router: {
|
wireguard: {
|
||||||
address: string;
|
port: number;
|
||||||
};
|
public_key: string;
|
||||||
authenticator: {
|
|
||||||
address: string;
|
|
||||||
};
|
|
||||||
wireguard: string | null;
|
|
||||||
mixnet_websockets: {
|
|
||||||
ws_port: number;
|
|
||||||
wss_port: number | null;
|
|
||||||
};
|
};
|
||||||
} | null;
|
} | null;
|
||||||
|
|
||||||
@@ -165,15 +168,6 @@ export type Location = {
|
|||||||
longitude?: number;
|
longitude?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NodeData = {
|
|
||||||
node_id: number;
|
|
||||||
contract_node_type: string;
|
|
||||||
description: NodeDescription;
|
|
||||||
bond_information: BondInformation;
|
|
||||||
rewarding_details: RewardingDetails;
|
|
||||||
location: Location;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ACCOUNT BALANCES
|
// ACCOUNT BALANCES
|
||||||
|
|
||||||
export interface IRewardDetails {
|
export interface IRewardDetails {
|
||||||
@@ -207,111 +201,15 @@ export interface IAccountBalancesInfo {
|
|||||||
vesting_account?: null | string;
|
vesting_account?: null | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IObservatoryNode {
|
|
||||||
accepted_tnc: boolean;
|
|
||||||
bonded: boolean;
|
|
||||||
bonding_address: string;
|
|
||||||
description: {
|
|
||||||
authenticator: {
|
|
||||||
address: string;
|
|
||||||
};
|
|
||||||
auxiliary_details: {
|
|
||||||
accepted_operator_terms_and_conditions: boolean;
|
|
||||||
announce_ports: {
|
|
||||||
mix_port: number | null;
|
|
||||||
verloc_port: number | null;
|
|
||||||
};
|
|
||||||
location: string | null;
|
|
||||||
};
|
|
||||||
build_information: {
|
|
||||||
binary_name: string;
|
|
||||||
build_timestamp: string;
|
|
||||||
build_version: string;
|
|
||||||
cargo_profile: string;
|
|
||||||
cargo_triple: string;
|
|
||||||
commit_branch: string;
|
|
||||||
commit_sha: string;
|
|
||||||
commit_timestamp: string;
|
|
||||||
rustc_channel: string;
|
|
||||||
rustc_version: string;
|
|
||||||
};
|
|
||||||
declared_role: {
|
|
||||||
entry: boolean;
|
|
||||||
exit_ipr: boolean;
|
|
||||||
exit_nr: boolean;
|
|
||||||
mixnode: boolean;
|
|
||||||
};
|
|
||||||
host_information: {
|
|
||||||
hostname: string | null;
|
|
||||||
ip_address: string[];
|
|
||||||
};
|
|
||||||
keys: {
|
|
||||||
ed25519: string;
|
|
||||||
x25519: string;
|
|
||||||
x25519_noise: string | null;
|
|
||||||
};
|
|
||||||
ip_packet_router: {
|
|
||||||
address: string;
|
|
||||||
};
|
|
||||||
last_polled: string;
|
|
||||||
mixnet_websockets: {
|
|
||||||
ws_port: number;
|
|
||||||
wss_port: number | null;
|
|
||||||
};
|
|
||||||
network_requester: {
|
|
||||||
address: string;
|
|
||||||
uses_exit_policy: boolean;
|
|
||||||
};
|
|
||||||
wireguard: string | null;
|
|
||||||
geoip: {
|
|
||||||
city: string;
|
|
||||||
country: string;
|
|
||||||
ip_address: string;
|
|
||||||
loc: string;
|
|
||||||
node_id: number;
|
|
||||||
org: string;
|
|
||||||
postal: string;
|
|
||||||
region: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
identity_key: string;
|
|
||||||
ip_address: string;
|
|
||||||
node_id: number;
|
|
||||||
node_type: string;
|
|
||||||
original_pledge: number;
|
|
||||||
rewarding_details: {
|
|
||||||
cost_params: {
|
|
||||||
interval_operating_cost: {
|
|
||||||
amount: string;
|
|
||||||
denom: string;
|
|
||||||
};
|
|
||||||
profit_margin_percent: string;
|
|
||||||
};
|
|
||||||
delegates: string;
|
|
||||||
last_rewarded_epoch: number;
|
|
||||||
operator: string;
|
|
||||||
total_unit_reward: string;
|
|
||||||
unique_delegations: number;
|
|
||||||
unit_delegation: string;
|
|
||||||
};
|
|
||||||
self_description: {
|
|
||||||
details: string;
|
|
||||||
moniker: string;
|
|
||||||
security_contact: string;
|
|
||||||
website: string;
|
|
||||||
};
|
|
||||||
total_stake: number;
|
|
||||||
uptime: number;
|
|
||||||
}
|
|
||||||
export interface NodeRewardDetails {
|
export interface NodeRewardDetails {
|
||||||
amount: {
|
amount: {
|
||||||
amount: string;
|
amount: string;
|
||||||
denom: string;
|
denom: string;
|
||||||
};
|
};
|
||||||
|
block_height: number;
|
||||||
cumulative_reward_ratio: string;
|
cumulative_reward_ratio: string;
|
||||||
height: number;
|
|
||||||
node_id: number;
|
|
||||||
owner: string;
|
owner: string;
|
||||||
|
proxy: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LastProbeResult = {
|
export type LastProbeResult = {
|
||||||
@@ -480,3 +378,58 @@ export type NymTokenomics = {
|
|||||||
symbol: string;
|
symbol: string;
|
||||||
total_supply: number;
|
total_supply: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CountryData = {
|
||||||
|
ISO3: string;
|
||||||
|
nodes: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface CountryDataResponse {
|
||||||
|
[threeLetterCountryCode: string]: CountryData;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NS_NODE = {
|
||||||
|
accepted_tnc: boolean;
|
||||||
|
bonded: boolean;
|
||||||
|
bonding_address: string;
|
||||||
|
description: {
|
||||||
|
details: string;
|
||||||
|
moniker: string;
|
||||||
|
security_contact: string;
|
||||||
|
website: string;
|
||||||
|
};
|
||||||
|
geoip?: {
|
||||||
|
city: string;
|
||||||
|
country: string;
|
||||||
|
ip_address: string;
|
||||||
|
latitude: string;
|
||||||
|
longitude: string;
|
||||||
|
org: string;
|
||||||
|
postal: string;
|
||||||
|
region: string;
|
||||||
|
timezone: string;
|
||||||
|
};
|
||||||
|
identity_key: string;
|
||||||
|
ip_address: string;
|
||||||
|
node_id: number;
|
||||||
|
node_type: string;
|
||||||
|
original_pledge: number;
|
||||||
|
rewarding_details?: {
|
||||||
|
cost_params: {
|
||||||
|
interval_operating_cost: {
|
||||||
|
amount: string;
|
||||||
|
denom: string;
|
||||||
|
};
|
||||||
|
profit_margin_percent: string;
|
||||||
|
};
|
||||||
|
delegates: string;
|
||||||
|
last_rewarded_epoch: number;
|
||||||
|
operator: string;
|
||||||
|
total_unit_reward: string;
|
||||||
|
unique_delegations: number;
|
||||||
|
unit_delegation: string;
|
||||||
|
} | null;
|
||||||
|
self_description?: NodeDescription;
|
||||||
|
total_stake: string;
|
||||||
|
uptime: number;
|
||||||
|
};
|
||||||
|
|||||||
@@ -8,11 +8,6 @@ export const NYM_ACCOUNT_ADDRESS =
|
|||||||
export const NYM_PRICES_API = "https://api.nym.spectredao.net/api/v1/nym-price";
|
export const NYM_PRICES_API = "https://api.nym.spectredao.net/api/v1/nym-price";
|
||||||
export const VALIDATOR_BASE_URL =
|
export const VALIDATOR_BASE_URL =
|
||||||
process.env.NEXT_PUBLIC_VALIDATOR_URL || "https://rpc.nymtech.net";
|
process.env.NEXT_PUBLIC_VALIDATOR_URL || "https://rpc.nymtech.net";
|
||||||
export const DATA_OBSERVATORY_NODES_URL =
|
|
||||||
"https://api.nym.spectredao.net/api/v1/nodes";
|
|
||||||
|
|
||||||
export const DATA_OBSERVATORY_DELEGATIONS_URL =
|
|
||||||
"https://api.nym.spectredao.net/api/v1/delegations";
|
|
||||||
export const DATA_OBSERVATORY_BALANCES_URL =
|
export const DATA_OBSERVATORY_BALANCES_URL =
|
||||||
"https://api.nym.spectredao.net/api/v1/balances";
|
"https://api.nym.spectredao.net/api/v1/balances";
|
||||||
export const OBSERVATORY_GATEWAYS_URL =
|
export const OBSERVATORY_GATEWAYS_URL =
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
export const TABLET_WIDTH = "(min-width:700px)";
|
export const TABLET_WIDTH = "(min-width:700px)";
|
||||||
|
|
||||||
|
export const RECOMMENDED_NODES = [
|
||||||
|
1362, 291, 1719, 1768, 1772, 1512, 896, 1415, 2114, 2010,
|
||||||
|
];
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
|
import { WorldMap } from "@/components/worldMap/WorldMap";
|
||||||
import { Stack } from "@mui/material";
|
import { Stack } from "@mui/material";
|
||||||
import Grid from "@mui/material/Grid2";
|
import Grid from "@mui/material/Grid2";
|
||||||
import BlogArticlesCards from "../components/blogs/BlogArticleCards";
|
import BlogArticlesCards from "../components/blogs/BlogArticleCards";
|
||||||
import { ContentLayout } from "../components/contentLayout/ContentLayout";
|
import { ContentLayout } from "../components/contentLayout/ContentLayout";
|
||||||
import SectionHeading from "../components/headings/SectionHeading";
|
import SectionHeading from "../components/headings/SectionHeading";
|
||||||
import { CurrentEpochCard } from "../components/landingPageComponents/CurrentEpochCard";
|
import { CurrentEpochCardWrapper } from "../components/landingPageComponents/CurrentEpochCardWrapper";
|
||||||
import { NetworkStakeCard } from "../components/landingPageComponents/NetworkStakeCard";
|
import { NetworkStakeCardWrapper } from "../components/landingPageComponents/NetworkStakeCardWrapper";
|
||||||
import { NoiseCard } from "../components/landingPageComponents/NoiseCard";
|
import { NoiseCardWrapper } from "../components/landingPageComponents/NoiseCardWrapper";
|
||||||
import { StakersNumberCard } from "../components/landingPageComponents/StakersNumberCard";
|
import { StakersNumberCardWrapper } from "../components/landingPageComponents/StakersNumberCardWrapper";
|
||||||
import { TokenomicsCard } from "../components/landingPageComponents/TokenomicsCard";
|
import { TokenomicsCardWrapper } from "../components/landingPageComponents/TokenomicsCardWrapper";
|
||||||
import NodeTable from "../components/nodeTable/NodeTableWithAction";
|
import NodeTable from "../components/nodeTable/NodeTableWithAction";
|
||||||
import NodeAndAddressSearch from "../components/search/NodeAndAddressSearch";
|
import NodeAndAddressSearch from "../components/search/NodeAndAddressSearch";
|
||||||
|
|
||||||
@@ -16,38 +17,29 @@ export default async function Home() {
|
|||||||
<ContentLayout>
|
<ContentLayout>
|
||||||
<Stack gap={5}>
|
<Stack gap={5}>
|
||||||
<NodeAndAddressSearch />
|
<NodeAndAddressSearch />
|
||||||
|
<WorldMap />
|
||||||
</Stack>
|
</Stack>
|
||||||
<Grid container columnSpacing={5} rowSpacing={5}>
|
<Grid container columnSpacing={5} rowSpacing={5}>
|
||||||
<Grid size={12}>
|
<Grid size={12}>
|
||||||
<SectionHeading title="Noise Generating Network Overview" />
|
<SectionHeading title="Network Overview" />
|
||||||
</Grid>
|
|
||||||
<Grid size={{ xs: 12, sm: 6, lg: 3 }}>
|
|
||||||
<NoiseCard />
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<NoiseCardWrapper />
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
columnSpacing={5}
|
columnSpacing={5}
|
||||||
rowSpacing={5}
|
rowSpacing={5}
|
||||||
size={{ xs: 12, sm: 6, lg: 3 }}
|
size={{ xs: 12, sm: 6, lg: 3 }}
|
||||||
>
|
>
|
||||||
<Grid size={12}>
|
<StakersNumberCardWrapper />
|
||||||
<StakersNumberCard />
|
<CurrentEpochCardWrapper />
|
||||||
</Grid>
|
|
||||||
<Grid size={12}>
|
|
||||||
<CurrentEpochCard />
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid size={{ xs: 12, sm: 6, lg: 3 }}>
|
<NetworkStakeCardWrapper />
|
||||||
<NetworkStakeCard />
|
<TokenomicsCardWrapper />
|
||||||
</Grid>
|
|
||||||
<Grid size={{ xs: 12, sm: 6, lg: 3 }}>
|
|
||||||
<TokenomicsCard />
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid container>
|
<Grid container rowSpacing={5}>
|
||||||
<Grid size={12}>
|
<Grid size={12}>
|
||||||
<SectionHeading title="Nym Nodes" />
|
<SectionHeading title="Nym Servers" />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid size={12}>
|
<Grid size={12}>
|
||||||
<NodeTable />
|
<NodeTable />
|
||||||
|
|||||||
@@ -0,0 +1,195 @@
|
|||||||
|
// Map of 2-letter country codes to 3-letter country codes
|
||||||
|
export const countryCodeMap: Record<string, string> = {
|
||||||
|
AF: "AFG", // Afghanistan
|
||||||
|
AL: "ALB", // Albania
|
||||||
|
DZ: "DZA", // Algeria
|
||||||
|
AD: "AND", // Andorra
|
||||||
|
AO: "AGO", // Angola
|
||||||
|
AG: "ATG", // Antigua and Barbuda
|
||||||
|
AR: "ARG", // Argentina
|
||||||
|
AM: "ARM", // Armenia
|
||||||
|
AU: "AUS", // Australia
|
||||||
|
AT: "AUT", // Austria
|
||||||
|
AZ: "AZE", // Azerbaijan
|
||||||
|
BS: "BHS", // Bahamas
|
||||||
|
BH: "BHR", // Bahrain
|
||||||
|
BD: "BGD", // Bangladesh
|
||||||
|
BB: "BRB", // Barbados
|
||||||
|
BY: "BLR", // Belarus
|
||||||
|
BE: "BEL", // Belgium
|
||||||
|
BZ: "BLZ", // Belize
|
||||||
|
BJ: "BEN", // Benin
|
||||||
|
BT: "BTN", // Bhutan
|
||||||
|
BO: "BOL", // Bolivia
|
||||||
|
BA: "BIH", // Bosnia and Herzegovina
|
||||||
|
BW: "BWA", // Botswana
|
||||||
|
BR: "BRA", // Brazil
|
||||||
|
BN: "BRN", // Brunei
|
||||||
|
BG: "BGR", // Bulgaria
|
||||||
|
BF: "BFA", // Burkina Faso
|
||||||
|
BI: "BDI", // Burundi
|
||||||
|
KH: "KHM", // Cambodia
|
||||||
|
CM: "CMR", // Cameroon
|
||||||
|
CA: "CAN", // Canada
|
||||||
|
CV: "CPV", // Cape Verde
|
||||||
|
CF: "CAF", // Central African Republic
|
||||||
|
TD: "TCD", // Chad
|
||||||
|
CL: "CHL", // Chile
|
||||||
|
CN: "CHN", // China
|
||||||
|
CO: "COL", // Colombia
|
||||||
|
KM: "COM", // Comoros
|
||||||
|
CG: "COG", // Congo
|
||||||
|
CR: "CRI", // Costa Rica
|
||||||
|
HR: "HRV", // Croatia
|
||||||
|
CU: "CUB", // Cuba
|
||||||
|
CY: "CYP", // Cyprus
|
||||||
|
CZ: "CZE", // Czech Republic
|
||||||
|
DK: "DNK", // Denmark
|
||||||
|
DJ: "DJI", // Djibouti
|
||||||
|
DM: "DMA", // Dominica
|
||||||
|
DO: "DOM", // Dominican Republic
|
||||||
|
EC: "ECU", // Ecuador
|
||||||
|
EG: "EGY", // Egypt
|
||||||
|
SV: "SLV", // El Salvador
|
||||||
|
GQ: "GNQ", // Equatorial Guinea
|
||||||
|
ER: "ERI", // Eritrea
|
||||||
|
EE: "EST", // Estonia
|
||||||
|
ET: "ETH", // Ethiopia
|
||||||
|
FJ: "FJI", // Fiji
|
||||||
|
FI: "FIN", // Finland
|
||||||
|
FR: "FRA", // France
|
||||||
|
GA: "GAB", // Gabon
|
||||||
|
GM: "GMB", // Gambia
|
||||||
|
GE: "GEO", // Georgia
|
||||||
|
DE: "DEU", // Germany
|
||||||
|
GH: "GHA", // Ghana
|
||||||
|
GR: "GRC", // Greece
|
||||||
|
GD: "GRD", // Grenada
|
||||||
|
GT: "GTM", // Guatemala
|
||||||
|
GN: "GIN", // Guinea
|
||||||
|
GW: "GNB", // Guinea-Bissau
|
||||||
|
GY: "GUY", // Guyana
|
||||||
|
HT: "HTI", // Haiti
|
||||||
|
HN: "HND", // Honduras
|
||||||
|
HU: "HUN", // Hungary
|
||||||
|
IS: "ISL", // Iceland
|
||||||
|
IN: "IND", // India
|
||||||
|
ID: "IDN", // Indonesia
|
||||||
|
IR: "IRN", // Iran
|
||||||
|
IQ: "IRQ", // Iraq
|
||||||
|
IE: "IRL", // Ireland
|
||||||
|
IL: "ISR", // Israel
|
||||||
|
IT: "ITA", // Italy
|
||||||
|
JM: "JAM", // Jamaica
|
||||||
|
JP: "JPN", // Japan
|
||||||
|
JO: "JOR", // Jordan
|
||||||
|
KZ: "KAZ", // Kazakhstan
|
||||||
|
KE: "KEN", // Kenya
|
||||||
|
KI: "KIR", // Kiribati
|
||||||
|
KP: "PRK", // North Korea
|
||||||
|
KR: "KOR", // South Korea
|
||||||
|
KW: "KWT", // Kuwait
|
||||||
|
KG: "KGZ", // Kyrgyzstan
|
||||||
|
LA: "LAO", // Laos
|
||||||
|
LV: "LVA", // Latvia
|
||||||
|
LB: "LBN", // Lebanon
|
||||||
|
LS: "LSO", // Lesotho
|
||||||
|
LR: "LBR", // Liberia
|
||||||
|
LY: "LBY", // Libya
|
||||||
|
LI: "LIE", // Liechtenstein
|
||||||
|
LT: "LTU", // Lithuania
|
||||||
|
LU: "LUX", // Luxembourg
|
||||||
|
MG: "MDG", // Madagascar
|
||||||
|
MW: "MWI", // Malawi
|
||||||
|
MY: "MYS", // Malaysia
|
||||||
|
MV: "MDV", // Maldives
|
||||||
|
ML: "MLI", // Mali
|
||||||
|
MT: "MLT", // Malta
|
||||||
|
MH: "MHL", // Marshall Islands
|
||||||
|
MR: "MRT", // Mauritania
|
||||||
|
MU: "MUS", // Mauritius
|
||||||
|
MX: "MEX", // Mexico
|
||||||
|
FM: "FSM", // Micronesia
|
||||||
|
MD: "MDA", // Moldova
|
||||||
|
MC: "MCO", // Monaco
|
||||||
|
MN: "MNG", // Mongolia
|
||||||
|
ME: "MNE", // Montenegro
|
||||||
|
MA: "MAR", // Morocco
|
||||||
|
MZ: "MOZ", // Mozambique
|
||||||
|
MM: "MMR", // Myanmar
|
||||||
|
NA: "NAM", // Namibia
|
||||||
|
NR: "NRU", // Nauru
|
||||||
|
NP: "NPL", // Nepal
|
||||||
|
NL: "NLD", // Netherlands
|
||||||
|
NZ: "NZL", // New Zealand
|
||||||
|
NI: "NIC", // Nicaragua
|
||||||
|
NE: "NER", // Niger
|
||||||
|
NG: "NGA", // Nigeria
|
||||||
|
NO: "NOR", // Norway
|
||||||
|
OM: "OMN", // Oman
|
||||||
|
PK: "PAK", // Pakistan
|
||||||
|
PW: "PLW", // Palau
|
||||||
|
PA: "PAN", // Panama
|
||||||
|
PG: "PNG", // Papua New Guinea
|
||||||
|
PY: "PRY", // Paraguay
|
||||||
|
PE: "PER", // Peru
|
||||||
|
PH: "PHL", // Philippines
|
||||||
|
PL: "POL", // Poland
|
||||||
|
PT: "PRT", // Portugal
|
||||||
|
QA: "QAT", // Qatar
|
||||||
|
RO: "ROU", // Romania
|
||||||
|
RU: "RUS", // Russia
|
||||||
|
RW: "RWA", // Rwanda
|
||||||
|
KN: "KNA", // Saint Kitts and Nevis
|
||||||
|
LC: "LCA", // Saint Lucia
|
||||||
|
VC: "VCT", // Saint Vincent and the Grenadines
|
||||||
|
WS: "WSM", // Samoa
|
||||||
|
SM: "SMR", // San Marino
|
||||||
|
ST: "STP", // Sao Tome and Principe
|
||||||
|
SA: "SAU", // Saudi Arabia
|
||||||
|
SN: "SEN", // Senegal
|
||||||
|
RS: "SRB", // Serbia
|
||||||
|
SC: "SYC", // Seychelles
|
||||||
|
SL: "SLE", // Sierra Leone
|
||||||
|
SG: "SGP", // Singapore
|
||||||
|
SK: "SVK", // Slovakia
|
||||||
|
SI: "SVN", // Slovenia
|
||||||
|
SB: "SLB", // Solomon Islands
|
||||||
|
SO: "SOM", // Somalia
|
||||||
|
ZA: "ZAF", // South Africa
|
||||||
|
SS: "SSD", // South Sudan
|
||||||
|
ES: "ESP", // Spain
|
||||||
|
LK: "LKA", // Sri Lanka
|
||||||
|
SD: "SDN", // Sudan
|
||||||
|
SR: "SUR", // Suriname
|
||||||
|
SZ: "SWZ", // Swaziland
|
||||||
|
SE: "SWE", // Sweden
|
||||||
|
CH: "CHE", // Switzerland
|
||||||
|
SY: "SYR", // Syria
|
||||||
|
TW: "TWN", // Taiwan
|
||||||
|
TJ: "TJK", // Tajikistan
|
||||||
|
TZ: "TZA", // Tanzania
|
||||||
|
TH: "THA", // Thailand
|
||||||
|
TL: "TLS", // Timor-Leste
|
||||||
|
TG: "TGO", // Togo
|
||||||
|
TO: "TON", // Tonga
|
||||||
|
TT: "TTO", // Trinidad and Tobago
|
||||||
|
TN: "TUN", // Tunisia
|
||||||
|
TR: "TUR", // Turkey
|
||||||
|
TM: "TKM", // Turkmenistan
|
||||||
|
TV: "TUV", // Tuvalu
|
||||||
|
UG: "UGA", // Uganda
|
||||||
|
UA: "UKR", // Ukraine
|
||||||
|
AE: "ARE", // United Arab Emirates
|
||||||
|
GB: "GBR", // United Kingdom
|
||||||
|
US: "USA", // United States
|
||||||
|
UY: "URY", // Uruguay
|
||||||
|
UZ: "UZB", // Uzbekistan
|
||||||
|
VU: "VUT", // Vanuatu
|
||||||
|
VA: "VAT", // Vatican City
|
||||||
|
VE: "VEN", // Venezuela
|
||||||
|
VN: "VNM", // Vietnam
|
||||||
|
YE: "YEM", // Yemen
|
||||||
|
ZM: "ZMB", // Zambia
|
||||||
|
ZW: "ZWE", // Zimbabwe
|
||||||
|
};
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { fetchAccountBalance, fetchNymPrice } from "@/app/api";
|
import { fetchAccountBalance, fetchNymPrice } from "@/app/api";
|
||||||
import { Skeleton, Stack, Typography } from "@mui/material";
|
import { Skeleton, Stack, Typography, useTheme } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import type { IRewardDetails } from "../../app/api/types";
|
import type { IRewardDetails } from "../../app/api/types";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
@@ -45,7 +45,7 @@ const getAllocation = (unyms: number, totalUnyms: number): number => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const calculateStakingRewards = (
|
const calculateStakingRewards = (
|
||||||
accumulatedRewards: IRewardDetails[],
|
accumulatedRewards: IRewardDetails[]
|
||||||
): number => {
|
): number => {
|
||||||
if (accumulatedRewards.length > 0) {
|
if (accumulatedRewards.length > 0) {
|
||||||
const totalRewards = accumulatedRewards.reduce((total, rewardDetail) => {
|
const totalRewards = accumulatedRewards.reduce((total, rewardDetail) => {
|
||||||
@@ -61,6 +61,8 @@ const calculateStakingRewards = (
|
|||||||
|
|
||||||
export const AccountBalancesCard = (props: IAccountBalancesCardProps) => {
|
export const AccountBalancesCard = (props: IAccountBalancesCardProps) => {
|
||||||
const { address } = props;
|
const { address } = props;
|
||||||
|
const theme = useTheme();
|
||||||
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: accountInfo,
|
data: accountInfo,
|
||||||
@@ -101,7 +103,10 @@ export const AccountBalancesCard = (props: IAccountBalancesCardProps) => {
|
|||||||
if (isError || priceError || !accountInfo || !nymPrice) {
|
if (isError || priceError || !accountInfo || !nymPrice) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Total value">
|
<ExplorerCard label="Total value">
|
||||||
<Typography variant="h5" sx={{ color: "pine.600", letterSpacing: 0.7 }}>
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
|
>
|
||||||
Failed to account data.
|
Failed to account data.
|
||||||
</Typography>
|
</Typography>
|
||||||
<Skeleton variant="text" height={238} />
|
<Skeleton variant="text" height={238} />
|
||||||
@@ -113,7 +118,7 @@ export const AccountBalancesCard = (props: IAccountBalancesCardProps) => {
|
|||||||
|
|
||||||
const totalBalanceUSD = getPriceInUSD(
|
const totalBalanceUSD = getPriceInUSD(
|
||||||
Number(accountInfo.total_value.amount),
|
Number(accountInfo.total_value.amount),
|
||||||
nymPriceData,
|
nymPriceData
|
||||||
);
|
);
|
||||||
const spendableNYM =
|
const spendableNYM =
|
||||||
accountInfo.balances.length > 0
|
accountInfo.balances.length > 0
|
||||||
@@ -127,46 +132,46 @@ export const AccountBalancesCard = (props: IAccountBalancesCardProps) => {
|
|||||||
accountInfo.balances.length > 0
|
accountInfo.balances.length > 0
|
||||||
? getAllocation(
|
? getAllocation(
|
||||||
Number(accountInfo.balances[0].amount),
|
Number(accountInfo.balances[0].amount),
|
||||||
Number(accountInfo.total_value.amount),
|
Number(accountInfo.total_value.amount)
|
||||||
)
|
)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const delegationsNYM = getNymsFormated(
|
const delegationsNYM = getNymsFormated(
|
||||||
Number(accountInfo.total_delegations.amount),
|
Number(accountInfo.total_delegations.amount)
|
||||||
);
|
);
|
||||||
const delegationsUSD = getPriceInUSD(
|
const delegationsUSD = getPriceInUSD(
|
||||||
Number(accountInfo.total_delegations.amount),
|
Number(accountInfo.total_delegations.amount),
|
||||||
nymPriceData,
|
nymPriceData
|
||||||
);
|
);
|
||||||
const delegationsAllocation = getAllocation(
|
const delegationsAllocation = getAllocation(
|
||||||
Number(accountInfo.total_delegations.amount),
|
Number(accountInfo.total_delegations.amount),
|
||||||
Number(accountInfo.total_value.amount),
|
Number(accountInfo.total_value.amount)
|
||||||
);
|
);
|
||||||
|
|
||||||
const operatorRewardsAllocation = getAllocation(
|
const operatorRewardsAllocation = getAllocation(
|
||||||
Number(accountInfo.operator_rewards?.amount || 0),
|
Number(accountInfo.operator_rewards?.amount || 0),
|
||||||
Number(accountInfo.total_value.amount),
|
Number(accountInfo.total_value.amount)
|
||||||
);
|
);
|
||||||
|
|
||||||
const operatorRewardsNYM = getNymsFormated(
|
const operatorRewardsNYM = getNymsFormated(
|
||||||
Number(accountInfo.operator_rewards?.amount || 0),
|
Number(accountInfo.operator_rewards?.amount || 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
const operatorRewardsUSD = getPriceInUSD(
|
const operatorRewardsUSD = getPriceInUSD(
|
||||||
Number(accountInfo.operator_rewards?.amount || 0),
|
Number(accountInfo.operator_rewards?.amount || 0),
|
||||||
nymPriceData,
|
nymPriceData
|
||||||
);
|
);
|
||||||
|
|
||||||
const claimableNYM = getNymsFormated(
|
const claimableNYM = getNymsFormated(
|
||||||
Number(accountInfo.claimable_rewards.amount),
|
Number(accountInfo.claimable_rewards.amount)
|
||||||
);
|
);
|
||||||
const claimableUSD = getPriceInUSD(
|
const claimableUSD = getPriceInUSD(
|
||||||
Number(accountInfo.claimable_rewards.amount),
|
Number(accountInfo.claimable_rewards.amount),
|
||||||
nymPriceData,
|
nymPriceData
|
||||||
);
|
);
|
||||||
const claimableAllocation = getAllocation(
|
const claimableAllocation = getAllocation(
|
||||||
Number(accountInfo.claimable_rewards.amount),
|
Number(accountInfo.claimable_rewards.amount),
|
||||||
Number(accountInfo.total_value.amount),
|
Number(accountInfo.total_value.amount)
|
||||||
);
|
);
|
||||||
|
|
||||||
const stakingRewards =
|
const stakingRewards =
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { fetchAccountBalance } from "@/app/api";
|
import { fetchAccountBalance } from "@/app/api";
|
||||||
import { Box, Skeleton, Stack, Typography } from "@mui/material";
|
import { Box, Skeleton, Stack, Typography, useTheme } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
import CopyToClipboard from "../copyToClipboard/CopyToClipboard";
|
import CopyToClipboard from "../copyToClipboard/CopyToClipboard";
|
||||||
@@ -13,6 +13,8 @@ interface IAccountInfoCardProps {
|
|||||||
|
|
||||||
export const AccountInfoCard = (props: IAccountInfoCardProps) => {
|
export const AccountInfoCard = (props: IAccountInfoCardProps) => {
|
||||||
const { address } = props;
|
const { address } = props;
|
||||||
|
const theme = useTheme();
|
||||||
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
|
|
||||||
const { data, isLoading, isError } = useQuery({
|
const { data, isLoading, isError } = useQuery({
|
||||||
queryKey: ["accountBalance", address],
|
queryKey: ["accountBalance", address],
|
||||||
@@ -38,7 +40,10 @@ export const AccountInfoCard = (props: IAccountInfoCardProps) => {
|
|||||||
if (isError || !data) {
|
if (isError || !data) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Total NYM">
|
<ExplorerCard label="Total NYM">
|
||||||
<Typography variant="h5" sx={{ color: "pine.600", letterSpacing: 0.7 }}>
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
|
>
|
||||||
Failed to account data.
|
Failed to account data.
|
||||||
</Typography>
|
</Typography>
|
||||||
<Skeleton variant="text" height={238} />
|
<Skeleton variant="text" height={238} />
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { fetchObservatoryNodes } from "@/app/api";
|
import { fetchNSApiNodes } from "@/app/api";
|
||||||
|
import type { NS_NODE } from "@/app/api/types";
|
||||||
import ExplorerButtonGroup from "@/components/toggleButton/ToggleButton";
|
import ExplorerButtonGroup from "@/components/toggleButton/ToggleButton";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
@@ -9,18 +10,20 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function AccountPageButtonGroup({ address }: Props) {
|
export default function AccountPageButtonGroup({ address }: Props) {
|
||||||
const { data: nymNodes, isError } = useQuery({
|
const { data: nsApiNodes = [], isError: isNSApiNodesError } = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: fetchObservatoryNodes,
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!nymNodes || isError) return null;
|
if (!nsApiNodes || isNSApiNodesError) return null;
|
||||||
|
|
||||||
const nymNode = nymNodes.find((node) => node.bonding_address === address);
|
const nymNode = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.bonding_address === address
|
||||||
|
);
|
||||||
|
|
||||||
if (!nymNode) return null;
|
if (!nymNode) return null;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ const BlogArticlesCards = async ({
|
|||||||
const blogArticle = JSON.parse(fileContent);
|
const blogArticle = JSON.parse(fileContent);
|
||||||
return {
|
return {
|
||||||
...blogArticle,
|
...blogArticle,
|
||||||
link: `/onboarding/${filename.replace(".json", "")}`,
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ type BlogArticle = {
|
|||||||
image: string;
|
image: string;
|
||||||
iconLight: string;
|
iconLight: string;
|
||||||
iconDark: string;
|
iconDark: string;
|
||||||
|
link: string;
|
||||||
attributes: {
|
attributes: {
|
||||||
blogAuthors: string[];
|
blogAuthors: string[];
|
||||||
date: Date;
|
date: Date;
|
||||||
@@ -23,8 +24,6 @@ type BlogArticle = {
|
|||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BlogArticleWithLink = BlogArticle & {
|
export type BlogArticleWithLink = BlogArticle;
|
||||||
link: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default BlogArticle;
|
export default BlogArticle;
|
||||||
|
|||||||
@@ -68,7 +68,12 @@ const ExplorerHeroCard = ({
|
|||||||
const iconSrc = isDarkMode ? iconDarkSrc : iconLightSrc;
|
const iconSrc = isDarkMode ? iconDarkSrc : iconLightSrc;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link href={link} sx={{ textDecoration: "none", height: "100%" }}>
|
<Link
|
||||||
|
href={link}
|
||||||
|
sx={{ textDecoration: "none", height: "100%" }}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
<Card sx={dynamicCardStyles} elevation={0}>
|
<Card sx={dynamicCardStyles} elevation={0}>
|
||||||
<CardHeader
|
<CardHeader
|
||||||
title={
|
title={
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useCopyToClipboard } from "@uidotdev/usehooks";
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import CopyFile from "../icons/CopyFile";
|
import CopyFile from "../icons/CopyFile";
|
||||||
import CopyFileDark from "../icons/CopyFileDark";
|
import CopyFileDark from "../icons/CopyFileDark";
|
||||||
|
import CheckIcon from "@mui/icons-material/Check";
|
||||||
|
|
||||||
const CLEAR_AFTER_MS = 10_000;
|
const CLEAR_AFTER_MS = 10_000;
|
||||||
|
|
||||||
@@ -34,12 +35,8 @@ const CopyToClipboard = ({
|
|||||||
|
|
||||||
if (hasCopied) {
|
if (hasCopied) {
|
||||||
return (
|
return (
|
||||||
<Typography
|
<Typography sx={{ color: isDarkMode ? "base.white" : "pine.950" }}>
|
||||||
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
<CheckIcon fontSize="small" />
|
||||||
variant="h6"
|
|
||||||
color="textSecondary"
|
|
||||||
>
|
|
||||||
Copied
|
|
||||||
</Typography>
|
</Typography>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export async function Footer() {
|
|||||||
const locale = "en";
|
const locale = "en";
|
||||||
const footerData = await getFooter(locale);
|
const footerData = await getFooter(locale);
|
||||||
const legalContent1 =
|
const legalContent1 =
|
||||||
"Nym Noise Generating Network Explorer, V 2.1.0 Public Beta release.";
|
"Nym Noise Generating Network Explorer, V 2.2.0 Public Beta release.";
|
||||||
const legalContent2 = footerData?.attributes?.legalContent2 || false;
|
const legalContent2 = footerData?.attributes?.legalContent2 || false;
|
||||||
const footerLinkBlocks = footerData?.attributes?.linkBlocks || [];
|
const footerLinkBlocks = footerData?.attributes?.linkBlocks || [];
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
"use client";
|
||||||
|
import Grid from "@mui/material/Grid2";
|
||||||
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
|
interface ConditionalCardWrapperProps {
|
||||||
|
children: ReactNode;
|
||||||
|
size?:
|
||||||
|
| number
|
||||||
|
| { xs?: number; sm?: number; md?: number; lg?: number; xl?: number };
|
||||||
|
visible?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ConditionalCardWrapper = ({
|
||||||
|
children,
|
||||||
|
size,
|
||||||
|
visible = true,
|
||||||
|
}: ConditionalCardWrapperProps) => {
|
||||||
|
if (!visible) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Grid size={size}>{children}</Grid>;
|
||||||
|
};
|
||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
type EpochResponseData,
|
type EpochResponseData,
|
||||||
useEpochContext,
|
useEpochContext,
|
||||||
} from "@/providers/EpochProvider";
|
} from "@/providers/EpochProvider";
|
||||||
import { Skeleton, Typography } from "@mui/material";
|
import { Skeleton, Typography, useTheme } from "@mui/material";
|
||||||
import { differenceInMinutes, format } from "date-fns";
|
import { differenceInMinutes, format } from "date-fns";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
@@ -34,10 +34,13 @@ export const CurrentEpochCard = () => {
|
|||||||
const [endTime, setEndTime] = useState("");
|
const [endTime, setEndTime] = useState("");
|
||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
|
|
||||||
|
const theme = useTheme();
|
||||||
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
|
|
||||||
const updateState = useCallback((data: NonNullable<EpochResponseData>) => {
|
const updateState = useCallback((data: NonNullable<EpochResponseData>) => {
|
||||||
const { startTime, endTime } = getStartEndTime(
|
const { startTime, endTime } = getStartEndTime(
|
||||||
data.current_epoch_start,
|
data.current_epoch_start,
|
||||||
data.current_epoch_end,
|
data.current_epoch_end
|
||||||
);
|
);
|
||||||
const progress = calulateProgress(data.current_epoch_end);
|
const progress = calulateProgress(data.current_epoch_end);
|
||||||
|
|
||||||
@@ -65,30 +68,28 @@ export const CurrentEpochCard = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError) {
|
if (isError || !data) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Current mixnet epoch">
|
<ExplorerCard label="Current mixnet epoch">
|
||||||
<Typography variant="body3" fontWeight="light">
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
|
>
|
||||||
Failed to load data
|
Failed to load data
|
||||||
</Typography>
|
</Typography>
|
||||||
</ExplorerCard>
|
</ExplorerCard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
return (
|
|
||||||
<ExplorerCard label="Current mixnet epoch">
|
|
||||||
<Typography variant="body3" fontWeight="light">
|
|
||||||
No data available
|
|
||||||
</Typography>
|
|
||||||
</ExplorerCard>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (epochStatus === "pending") {
|
if (epochStatus === "pending") {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Current mixnet epoch">
|
<ExplorerCard label="Current mixnet epoch">
|
||||||
<Typography variant="body3" fontWeight="light" height={80}>
|
<Typography
|
||||||
|
variant="body3"
|
||||||
|
fontWeight="light"
|
||||||
|
height={80}
|
||||||
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
|
>
|
||||||
Waiting for next epoch to start...
|
Waiting for next epoch to start...
|
||||||
</Typography>
|
</Typography>
|
||||||
</ExplorerCard>
|
</ExplorerCard>
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
"use client";
|
||||||
|
import { useEpochContext } from "@/providers/EpochProvider";
|
||||||
|
import { CurrentEpochCard } from "./CurrentEpochCard";
|
||||||
|
import { ConditionalCardWrapper } from "./ConditionalCardWrapper";
|
||||||
|
|
||||||
|
export const CurrentEpochCardWrapper = () => {
|
||||||
|
const { data, isError, isLoading, epochStatus } = useEpochContext();
|
||||||
|
|
||||||
|
// Determine if the card should be visible
|
||||||
|
// Show the card if we have data and it's not in a pending state, or if we're still loading
|
||||||
|
const isVisible =
|
||||||
|
!isError && (data || isLoading) && epochStatus !== "pending";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ConditionalCardWrapper size={12} visible={isVisible}>
|
||||||
|
<CurrentEpochCard />
|
||||||
|
</ConditionalCardWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -33,21 +33,14 @@ export const NetworkStakeCard = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isStakingError || !packetsAndStaking) {
|
// Don't display the card if there's an error or insufficient data
|
||||||
return (
|
if (
|
||||||
<ExplorerCard label="Current network stake">
|
isStakingError ||
|
||||||
<Typography
|
!packetsAndStaking ||
|
||||||
variant="h5"
|
!Array.isArray(packetsAndStaking) ||
|
||||||
sx={{
|
packetsAndStaking.length < 10
|
||||||
color: isDarkMode ? "base.white" : "pine.950",
|
) {
|
||||||
letterSpacing: 0.7,
|
return null;
|
||||||
}}
|
|
||||||
>
|
|
||||||
Failed to load data
|
|
||||||
</Typography>
|
|
||||||
<Skeleton variant="text" height={238} />
|
|
||||||
</ExplorerCard>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const packetsAndStakingData: ExplorerData["packetsAndStakingData"] =
|
const packetsAndStakingData: ExplorerData["packetsAndStakingData"] =
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
"use client";
|
||||||
|
import { fetchNoise } from "@/app/api";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { NetworkStakeCard } from "./NetworkStakeCard";
|
||||||
|
import { ConditionalCardWrapper } from "./ConditionalCardWrapper";
|
||||||
|
|
||||||
|
export const NetworkStakeCardWrapper = () => {
|
||||||
|
const { data, isLoading, isError } = useQuery({
|
||||||
|
queryKey: ["noise"],
|
||||||
|
queryFn: fetchNoise,
|
||||||
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnReconnect: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Determine if the card should be visible
|
||||||
|
const isVisible =
|
||||||
|
!isLoading && !isError && data && Array.isArray(data) && data.length >= 10;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ConditionalCardWrapper size={{ xs: 12, sm: 6, lg: 3 }} visible={isVisible}>
|
||||||
|
<NetworkStakeCard />
|
||||||
|
</ConditionalCardWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -41,31 +41,21 @@ export const NoiseCard = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError || !data) {
|
// Don't display the card if there's an error or insufficient data
|
||||||
return (
|
if (isError || !data || !Array.isArray(data) || data.length < 10) {
|
||||||
<ExplorerCard label="Mixnet traffic">
|
return null;
|
||||||
<Typography
|
|
||||||
variant="h5"
|
|
||||||
sx={{
|
|
||||||
color: isDarkMode ? "base.white" : "pine.950",
|
|
||||||
letterSpacing: 0.7,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Failed to load data
|
|
||||||
</Typography>
|
|
||||||
<Skeleton variant="text" height={238} />
|
|
||||||
</ExplorerCard>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const todaysData = data[data.length - 2];
|
const todaysData = data[data.length - 2];
|
||||||
const yesterdaysData = data[data.length - 3];
|
const yesterdaysData = data[data.length - 3];
|
||||||
|
|
||||||
const noiseLast24H =
|
const noiseLast24H =
|
||||||
todaysData.total_packets_sent + todaysData.total_packets_received;
|
(todaysData?.total_packets_sent || 0) +
|
||||||
|
(todaysData?.total_packets_received || 0);
|
||||||
|
|
||||||
const noisePrevious24H =
|
const noisePrevious24H =
|
||||||
yesterdaysData.total_packets_sent + yesterdaysData.total_packets_received;
|
(yesterdaysData?.total_packets_sent || 0) +
|
||||||
|
(yesterdaysData?.total_packets_received || 0);
|
||||||
|
|
||||||
const formatNoiseVolume = (packets: number): string => {
|
const formatNoiseVolume = (packets: number): string => {
|
||||||
if (packets < 0) {
|
if (packets < 0) {
|
||||||
@@ -107,8 +97,9 @@ export const NoiseCard = () => {
|
|||||||
.slice(0, -1)
|
.slice(0, -1)
|
||||||
.map((item: IPacketsAndStakingData) => {
|
.map((item: IPacketsAndStakingData) => {
|
||||||
return {
|
return {
|
||||||
date_utc: item.date_utc,
|
date_utc: item?.date_utc,
|
||||||
numericData: item.total_packets_sent + item.total_packets_received,
|
numericData:
|
||||||
|
(item?.total_packets_sent || 0) + (item?.total_packets_received || 0),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter((item) => item.numericData >= 2_500_000_000);
|
.filter((item) => item.numericData >= 2_500_000_000);
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
"use client";
|
||||||
|
import { fetchNoise } from "@/app/api";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { NoiseCard } from "./NoiseCard";
|
||||||
|
import { ConditionalCardWrapper } from "./ConditionalCardWrapper";
|
||||||
|
|
||||||
|
export const NoiseCardWrapper = () => {
|
||||||
|
const { data, isLoading, isError } = useQuery({
|
||||||
|
queryKey: ["noise"],
|
||||||
|
queryFn: fetchNoise,
|
||||||
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnReconnect: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Determine if the card should be visible
|
||||||
|
const isVisible =
|
||||||
|
!isLoading && !isError && data && Array.isArray(data) && data.length >= 10;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ConditionalCardWrapper size={{ xs: 12, sm: 6, lg: 3 }} visible={isVisible}>
|
||||||
|
<NoiseCard />
|
||||||
|
</ConditionalCardWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { fetchObservatoryNodes } from "@/app/api";
|
import { fetchNSApiNodes } from "@/app/api";
|
||||||
import type { IObservatoryNode } from "@/app/api/types";
|
import type { NS_NODE } from "@/app/api/types";
|
||||||
import { Skeleton, Typography, useTheme } from "@mui/material";
|
import { Skeleton, Typography, useTheme } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
|
|
||||||
export const StakersNumberCard = () => {
|
export const StakersNumberCard = () => {
|
||||||
const {
|
const {
|
||||||
data: nymNodes,
|
data: nsApiNodes = [],
|
||||||
isLoading,
|
isLoading: isNSApiNodesLoading,
|
||||||
isError,
|
isError: isNSApiNodesError,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: () => fetchObservatoryNodes(),
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
@@ -22,7 +22,7 @@ export const StakersNumberCard = () => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isDarkMode = theme.palette.mode === "dark";
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
|
|
||||||
if (isLoading) {
|
if (isNSApiNodesLoading) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Number of delegations">
|
<ExplorerCard label="Number of delegations">
|
||||||
<Skeleton variant="text" height={90} />
|
<Skeleton variant="text" height={90} />
|
||||||
@@ -30,11 +30,11 @@ export const StakersNumberCard = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError || !nymNodes) {
|
if (isNSApiNodesError || !nsApiNodes) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Number of delegations">
|
<ExplorerCard label="Number of delegations">
|
||||||
<Typography
|
<Typography
|
||||||
variant="h3"
|
variant="h5"
|
||||||
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
>
|
>
|
||||||
Failed to load node data.
|
Failed to load node data.
|
||||||
@@ -43,13 +43,13 @@ export const StakersNumberCard = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const getActiveStakersNumber = (nodes: IObservatoryNode[]): number => {
|
const getActiveStakersNumber = (nodes: NS_NODE[]): number => {
|
||||||
return nodes.reduce(
|
return nodes.reduce(
|
||||||
(sum, node) => sum + node.rewarding_details.unique_delegations,
|
(sum, node) => sum + (node.rewarding_details?.unique_delegations || 0),
|
||||||
0,
|
0
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
const allStakers = getActiveStakersNumber(nymNodes);
|
const allStakers = getActiveStakersNumber(nsApiNodes);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Number of delegations">
|
<ExplorerCard label="Number of delegations">
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
"use client";
|
||||||
|
import { fetchNSApiNodes } from "@/app/api";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { StakersNumberCard } from "./StakersNumberCard";
|
||||||
|
import { ConditionalCardWrapper } from "./ConditionalCardWrapper";
|
||||||
|
|
||||||
|
export const StakersNumberCardWrapper = () => {
|
||||||
|
const { data, isLoading, isError } = useQuery({
|
||||||
|
queryKey: ["nsApiNodes"],
|
||||||
|
queryFn: fetchNSApiNodes,
|
||||||
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnReconnect: false,
|
||||||
|
refetchOnMount: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Determine if the card should be visible
|
||||||
|
const isVisible =
|
||||||
|
!isLoading && !isError && data && Array.isArray(data) && data.length > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ConditionalCardWrapper size={12} visible={isVisible}>
|
||||||
|
<StakersNumberCard />
|
||||||
|
</ConditionalCardWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { fetchEpochRewards, fetchNoise, fetchNymPrice } from "@/app/api";
|
import { fetchEpochRewards, fetchNoise, fetchNymPrice } from "@/app/api";
|
||||||
import { formatBigNum } from "@/utils/formatBigNumbers";
|
import { formatBigNum } from "@/utils/formatBigNumbers";
|
||||||
import { Box, Skeleton, Stack, Typography } from "@mui/material";
|
import { Box, Skeleton, Stack, Typography, useTheme } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import type { ExplorerData, NymTokenomics } from "../../app/api/types";
|
import type { ExplorerData, NymTokenomics } from "../../app/api/types";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
@@ -9,6 +9,8 @@ import ExplorerListItem from "../list/ListItem";
|
|||||||
import { TitlePrice } from "../price/TitlePrice";
|
import { TitlePrice } from "../price/TitlePrice";
|
||||||
|
|
||||||
export const TokenomicsCard = () => {
|
export const TokenomicsCard = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
const {
|
const {
|
||||||
data: nymPrice,
|
data: nymPrice,
|
||||||
isLoading,
|
isLoading,
|
||||||
@@ -69,7 +71,10 @@ export const TokenomicsCard = () => {
|
|||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Tokenomics overview">
|
<ExplorerCard label="Tokenomics overview">
|
||||||
<Typography variant="h5" sx={{ color: "pine.600", letterSpacing: 0.7 }}>
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
|
>
|
||||||
Failed to load tokenomics overview.
|
Failed to load tokenomics overview.
|
||||||
</Typography>
|
</Typography>
|
||||||
<Skeleton variant="text" height={80} />
|
<Skeleton variant="text" height={80} />
|
||||||
@@ -98,7 +103,7 @@ export const TokenomicsCard = () => {
|
|||||||
function calculateTVL(
|
function calculateTVL(
|
||||||
epochRewards: ExplorerData["currentEpochRewardsData"],
|
epochRewards: ExplorerData["currentEpochRewardsData"],
|
||||||
nymPriceData: NymTokenomics,
|
nymPriceData: NymTokenomics,
|
||||||
packetsAndStaking: ExplorerData["packetsAndStakingData"],
|
packetsAndStaking: ExplorerData["packetsAndStakingData"]
|
||||||
): number {
|
): number {
|
||||||
const lastTotalStake =
|
const lastTotalStake =
|
||||||
packetsAndStaking[packetsAndStaking.length - 1]?.total_stake || 0;
|
packetsAndStaking[packetsAndStaking.length - 1]?.total_stake || 0;
|
||||||
@@ -109,7 +114,7 @@ export const TokenomicsCard = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const TVL = formatBigNum(
|
const TVL = formatBigNum(
|
||||||
calculateTVL(epochRewardsData, nymPrice, packetsAndStakingData),
|
calculateTVL(epochRewardsData, nymPrice, packetsAndStakingData)
|
||||||
);
|
);
|
||||||
|
|
||||||
const dataRows = [
|
const dataRows = [
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
"use client";
|
||||||
|
import { fetchEpochRewards, fetchNoise, fetchNymPrice } from "@/app/api";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { TokenomicsCard } from "./TokenomicsCard";
|
||||||
|
import { ConditionalCardWrapper } from "./ConditionalCardWrapper";
|
||||||
|
|
||||||
|
export const TokenomicsCardWrapper = () => {
|
||||||
|
const {
|
||||||
|
data: nymPrice,
|
||||||
|
isLoading: isPriceLoading,
|
||||||
|
isError: isPriceError,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["nymPrice"],
|
||||||
|
queryFn: fetchNymPrice,
|
||||||
|
staleTime: 10 * 60 * 1000,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnReconnect: false,
|
||||||
|
refetchOnMount: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: epochRewards,
|
||||||
|
isLoading: isEpochLoading,
|
||||||
|
isError: isEpochError,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["epochRewards"],
|
||||||
|
queryFn: fetchEpochRewards,
|
||||||
|
staleTime: 10 * 60 * 1000,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnReconnect: false,
|
||||||
|
refetchOnMount: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: packetsAndStaking,
|
||||||
|
isLoading: isStakingLoading,
|
||||||
|
isError: isStakingError,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["noise"],
|
||||||
|
queryFn: fetchNoise,
|
||||||
|
staleTime: 10 * 60 * 1000,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnReconnect: false,
|
||||||
|
refetchOnMount: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Determine if the card should be visible
|
||||||
|
const isLoading = isPriceLoading || isEpochLoading || isStakingLoading;
|
||||||
|
const hasError = isPriceError || isEpochError || isStakingError;
|
||||||
|
const hasData =
|
||||||
|
nymPrice &&
|
||||||
|
epochRewards &&
|
||||||
|
packetsAndStaking &&
|
||||||
|
Array.isArray(packetsAndStaking) &&
|
||||||
|
packetsAndStaking.length >= 2;
|
||||||
|
|
||||||
|
const isVisible = !hasError && (hasData || isLoading);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ConditionalCardWrapper size={{ xs: 12, sm: 6, lg: 3 }} visible={isVisible}>
|
||||||
|
<TokenomicsCard />
|
||||||
|
</ConditionalCardWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,339 @@
|
|||||||
|
"use client";
|
||||||
|
import React from "react";
|
||||||
|
import {
|
||||||
|
Box,
|
||||||
|
Button,
|
||||||
|
Collapse,
|
||||||
|
Slider,
|
||||||
|
Typography,
|
||||||
|
useTheme,
|
||||||
|
} from "@mui/material";
|
||||||
|
import Grid from "@mui/material/Grid2";
|
||||||
|
|
||||||
|
import FilterAltIcon from "@mui/icons-material/FilterAlt";
|
||||||
|
import AccessTimeIcon from "@mui/icons-material/AccessTime";
|
||||||
|
import PieChartIcon from "@mui/icons-material/PieChart";
|
||||||
|
import PercentIcon from "@mui/icons-material/Percent";
|
||||||
|
import NodeFilterButtonGroup from "../toggleButton/NodeFilterButtonGroup";
|
||||||
|
import { RECOMMENDED_NODES } from "@/app/constants";
|
||||||
|
|
||||||
|
type AdvancedFiltersProps = {
|
||||||
|
uptime: [number, number];
|
||||||
|
setUptime: (value: [number, number]) => void;
|
||||||
|
saturation: [number, number];
|
||||||
|
setSaturation: (value: [number, number]) => void;
|
||||||
|
profitMargin: [number, number];
|
||||||
|
setProfitMargin: (value: [number, number]) => void;
|
||||||
|
open?: boolean;
|
||||||
|
setOpen?: (open: boolean) => void;
|
||||||
|
maxSaturation?: number;
|
||||||
|
activeFilter: "all" | "mixnodes" | "gateways" | "recommended";
|
||||||
|
setActiveFilter: (
|
||||||
|
filter: "all" | "mixnodes" | "gateways" | "recommended"
|
||||||
|
) => void;
|
||||||
|
nodeCounts: {
|
||||||
|
all: number;
|
||||||
|
mixnodes: number;
|
||||||
|
gateways: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function AdvancedFilters({
|
||||||
|
uptime,
|
||||||
|
setUptime,
|
||||||
|
saturation,
|
||||||
|
setSaturation,
|
||||||
|
profitMargin,
|
||||||
|
setProfitMargin,
|
||||||
|
open,
|
||||||
|
setOpen,
|
||||||
|
maxSaturation = 100,
|
||||||
|
activeFilter,
|
||||||
|
setActiveFilter,
|
||||||
|
nodeCounts,
|
||||||
|
}: AdvancedFiltersProps) {
|
||||||
|
const theme = useTheme();
|
||||||
|
const green = "#14e76f"; // from theme colours
|
||||||
|
|
||||||
|
const marksPercent: { value: number }[] = [{ value: 0 }, { value: 100 }];
|
||||||
|
const marksSaturation: { value: number }[] = [
|
||||||
|
{ value: 0 },
|
||||||
|
{ value: maxSaturation },
|
||||||
|
];
|
||||||
|
|
||||||
|
const panel = (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
mt: 3,
|
||||||
|
p: 2,
|
||||||
|
borderRadius: 3,
|
||||||
|
background: theme.palette.background.paper,
|
||||||
|
border: `1px solid ${theme.palette.divider}`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle1"
|
||||||
|
sx={{
|
||||||
|
fontStyle: "italic",
|
||||||
|
color:
|
||||||
|
theme.palette.mode === "light"
|
||||||
|
? theme.palette.common.black
|
||||||
|
: theme.palette.common.white,
|
||||||
|
mb: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Advanced filtering mode is active
|
||||||
|
</Typography>
|
||||||
|
<Grid container spacing={3}>
|
||||||
|
<Grid size={{ xs: 12, sm: 6, md: 4 }}>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
p: 3,
|
||||||
|
borderRadius: 3,
|
||||||
|
background: theme.palette.background.default,
|
||||||
|
mb: { xs: 2, sm: 0 },
|
||||||
|
border: `1px solid ${theme.palette.divider}`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box display="flex" alignItems="center" mb={1}>
|
||||||
|
<AccessTimeIcon
|
||||||
|
sx={{
|
||||||
|
color:
|
||||||
|
theme.palette.mode === "dark"
|
||||||
|
? theme.palette.common.white
|
||||||
|
: theme.palette.common.black,
|
||||||
|
mr: 1,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography
|
||||||
|
variant="h6"
|
||||||
|
sx={{ color: theme.palette.text.primary, fontSize: 17 }}
|
||||||
|
>
|
||||||
|
Uptime
|
||||||
|
</Typography>
|
||||||
|
<Box flexGrow={1} />
|
||||||
|
<Typography
|
||||||
|
variant="h6"
|
||||||
|
sx={{ color: theme.palette.primary.main, fontSize: 17 }}
|
||||||
|
>
|
||||||
|
{uptime[0]}% - {uptime[1]}%
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Slider
|
||||||
|
value={uptime}
|
||||||
|
onChange={(_, v) => setUptime(v as [number, number])}
|
||||||
|
valueLabelDisplay="off"
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
marks={marksPercent}
|
||||||
|
sx={{
|
||||||
|
color: green,
|
||||||
|
height: 8,
|
||||||
|
"& .MuiSlider-thumb": {
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
backgroundColor: green,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Grid>
|
||||||
|
<Grid size={{ xs: 12, sm: 6, md: 4 }}>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
p: 3,
|
||||||
|
borderRadius: 3,
|
||||||
|
background: theme.palette.background.default,
|
||||||
|
mb: { xs: 2, sm: 0 },
|
||||||
|
border: `1px solid ${theme.palette.divider}`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box display="flex" alignItems="center" mb={1}>
|
||||||
|
<PieChartIcon
|
||||||
|
sx={{
|
||||||
|
color:
|
||||||
|
theme.palette.mode === "dark"
|
||||||
|
? theme.palette.common.white
|
||||||
|
: theme.palette.common.black,
|
||||||
|
mr: 1,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography
|
||||||
|
variant="h6"
|
||||||
|
sx={{ color: theme.palette.text.primary, fontSize: 17 }}
|
||||||
|
>
|
||||||
|
Saturation
|
||||||
|
</Typography>
|
||||||
|
<Box flexGrow={1} />
|
||||||
|
<Typography
|
||||||
|
variant="h6"
|
||||||
|
sx={{ color: theme.palette.primary.main, fontSize: 17 }}
|
||||||
|
>
|
||||||
|
{saturation[0]}% - {saturation[1]}%
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Slider
|
||||||
|
value={saturation}
|
||||||
|
onChange={(_, v) => setSaturation(v as [number, number])}
|
||||||
|
valueLabelDisplay="off"
|
||||||
|
min={0}
|
||||||
|
max={maxSaturation}
|
||||||
|
marks={marksSaturation}
|
||||||
|
sx={{
|
||||||
|
color: green,
|
||||||
|
height: 8,
|
||||||
|
"& .MuiSlider-thumb": {
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
backgroundColor: green,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Grid>
|
||||||
|
<Grid size={{ xs: 12, sm: 6, md: 4 }} sx={{ mx: { sm: "auto" } }}>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
p: 3,
|
||||||
|
borderRadius: 3,
|
||||||
|
background: theme.palette.background.default,
|
||||||
|
mb: { xs: 2, sm: 0 },
|
||||||
|
border: `1px solid ${theme.palette.divider}`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box display="flex" alignItems="center" mb={1}>
|
||||||
|
<PercentIcon
|
||||||
|
sx={{
|
||||||
|
color:
|
||||||
|
theme.palette.mode === "dark"
|
||||||
|
? theme.palette.common.white
|
||||||
|
: theme.palette.common.black,
|
||||||
|
mr: 1,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography
|
||||||
|
variant="h6"
|
||||||
|
sx={{ color: theme.palette.text.primary, fontSize: 17 }}
|
||||||
|
>
|
||||||
|
Profit Margin
|
||||||
|
</Typography>
|
||||||
|
<Box flexGrow={1} />
|
||||||
|
<Typography
|
||||||
|
variant="h6"
|
||||||
|
sx={{ color: theme.palette.primary.main, fontSize: 17 }}
|
||||||
|
>
|
||||||
|
{profitMargin[0]}% - {profitMargin[1]}%
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Slider
|
||||||
|
value={profitMargin}
|
||||||
|
onChange={(_, v) => setProfitMargin(v as [number, number])}
|
||||||
|
valueLabelDisplay="off"
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
marks={marksPercent}
|
||||||
|
sx={{
|
||||||
|
color: green,
|
||||||
|
height: 8,
|
||||||
|
"& .MuiSlider-thumb": {
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
backgroundColor: green,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ width: "100%" }}>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: { xs: "column", sm: "row" },
|
||||||
|
alignItems: { xs: "stretch", sm: "center" },
|
||||||
|
gap: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box sx={{ width: { xs: "100%", sm: "auto" } }}>
|
||||||
|
<NodeFilterButtonGroup
|
||||||
|
size="medium"
|
||||||
|
options={[
|
||||||
|
{
|
||||||
|
label: `Recommended servers (${RECOMMENDED_NODES.length})`,
|
||||||
|
isSelected: activeFilter === "recommended",
|
||||||
|
value: "recommended",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: `All servers (${nodeCounts.all})`,
|
||||||
|
isSelected: activeFilter === "all",
|
||||||
|
value: "all",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: `Mixnodes (${nodeCounts.mixnodes})`,
|
||||||
|
isSelected: activeFilter === "mixnodes",
|
||||||
|
value: "mixnodes",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: `Gateways (${nodeCounts.gateways})`,
|
||||||
|
isSelected: activeFilter === "gateways",
|
||||||
|
value: "gateways",
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
onPage={activeFilter}
|
||||||
|
onFilterChange={setActiveFilter}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
color="inherit"
|
||||||
|
startIcon={
|
||||||
|
<FilterAltIcon
|
||||||
|
sx={{
|
||||||
|
color:
|
||||||
|
theme.palette.mode === "light"
|
||||||
|
? `${theme.palette.common.black} !important`
|
||||||
|
: `${theme.palette.common.white} !important`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
onClick={() => setOpen && setOpen(!open)}
|
||||||
|
sx={{
|
||||||
|
borderRadius: 3,
|
||||||
|
px: 4,
|
||||||
|
py: 1.5,
|
||||||
|
color:
|
||||||
|
theme.palette.mode === "light"
|
||||||
|
? `${theme.palette.common.black} !important`
|
||||||
|
: `${theme.palette.common.white} !important`,
|
||||||
|
borderColor:
|
||||||
|
theme.palette.mode === "light"
|
||||||
|
? theme.palette.common.black
|
||||||
|
: theme.palette.common.white,
|
||||||
|
background: "none",
|
||||||
|
fontWeight: 500,
|
||||||
|
fontSize: 16,
|
||||||
|
"&:hover, &:focus": {
|
||||||
|
background:
|
||||||
|
theme.palette.mode === "light"
|
||||||
|
? "rgba(0,0,0,0.04)"
|
||||||
|
: "rgba(255,255,255,0.05)",
|
||||||
|
borderColor:
|
||||||
|
theme.palette.mode === "light"
|
||||||
|
? theme.palette.grey[400]
|
||||||
|
: theme.palette.common.white,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Advanced Filters
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Collapse in={open} timeout="auto" unmountOnExit>
|
||||||
|
{panel}
|
||||||
|
</Collapse>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
Typography,
|
Typography,
|
||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
useTheme,
|
useTheme,
|
||||||
|
Tooltip,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { useLocalStorage } from "@uidotdev/usehooks";
|
import { useLocalStorage } from "@uidotdev/usehooks";
|
||||||
@@ -29,6 +30,7 @@ import StakeModal from "../staking/StakeModal";
|
|||||||
import { fee } from "../staking/schemas";
|
import { fee } from "../staking/schemas";
|
||||||
import ConnectWallet from "../wallet/ConnectWallet";
|
import ConnectWallet from "../wallet/ConnectWallet";
|
||||||
import type { MappedNymNode, MappedNymNodes } from "./NodeTableWithAction";
|
import type { MappedNymNode, MappedNymNodes } from "./NodeTableWithAction";
|
||||||
|
import CopyToClipboard from "../copyToClipboard/CopyToClipboard";
|
||||||
|
|
||||||
const ColumnHeading = ({
|
const ColumnHeading = ({
|
||||||
children,
|
children,
|
||||||
@@ -100,7 +102,7 @@ const NodeTable = ({ nodes }: { nodes: MappedNymNodes }) => {
|
|||||||
{ nodeId },
|
{ nodeId },
|
||||||
fee,
|
fee,
|
||||||
"Delegation from Nym Explorer V2",
|
"Delegation from Nym Explorer V2",
|
||||||
uNymFunds,
|
uNymFunds
|
||||||
);
|
);
|
||||||
setSelectedNodeForStaking(undefined);
|
setSelectedNodeForStaking(undefined);
|
||||||
setInfoModalProps({
|
setInfoModalProps({
|
||||||
@@ -129,7 +131,7 @@ const NodeTable = ({ nodes }: { nodes: MappedNymNodes }) => {
|
|||||||
}
|
}
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
},
|
},
|
||||||
[nymClient, handleRefetch],
|
[nymClient, handleRefetch]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleOnSelectStake = useCallback(
|
const handleOnSelectStake = useCallback(
|
||||||
@@ -158,7 +160,7 @@ const NodeTable = ({ nodes }: { nodes: MappedNymNodes }) => {
|
|||||||
identityKey: node.identity_key,
|
identityKey: node.identity_key,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[isWalletConnected],
|
[isWalletConnected]
|
||||||
);
|
);
|
||||||
|
|
||||||
const columns: MRT_ColumnDef<MappedNymNode>[] = useMemo(
|
const columns: MRT_ColumnDef<MappedNymNode>[] = useMemo(
|
||||||
@@ -189,54 +191,6 @@ const NodeTable = ({ nodes }: { nodes: MappedNymNodes }) => {
|
|||||||
},
|
},
|
||||||
Cell: ({ row }) => <Favorite address={row.original.owner} />,
|
Cell: ({ row }) => <Favorite address={row.original.owner} />,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
|
||||||
id: "name",
|
|
||||||
header: "",
|
|
||||||
Header: <ColumnHeading>Name</ColumnHeading>,
|
|
||||||
accessorKey: "name",
|
|
||||||
Cell: ({ row }) => (
|
|
||||||
<Stack spacing={1}>
|
|
||||||
<Typography variant="body4">{row.original.name || "-"}</Typography>
|
|
||||||
</Stack>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "id",
|
|
||||||
header: "",
|
|
||||||
Header: <ColumnHeading>Node ID</ColumnHeading>,
|
|
||||||
accessorKey: "nodeId",
|
|
||||||
size: 90,
|
|
||||||
Cell: ({ row }) => (
|
|
||||||
<Stack spacing={1}>
|
|
||||||
<Typography variant="body4">{row.original.nodeId}</Typography>
|
|
||||||
</Stack>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "identity_key",
|
|
||||||
header: "",
|
|
||||||
Header: <ColumnHeading>Identity Key</ColumnHeading>,
|
|
||||||
accessorKey: "identity_key",
|
|
||||||
Cell: ({ row }) => (
|
|
||||||
<Stack spacing={1}>
|
|
||||||
<Typography variant="body5">{row.original.identity_key}</Typography>
|
|
||||||
</Stack>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "qos",
|
|
||||||
header: "Qlt of Service",
|
|
||||||
align: "center",
|
|
||||||
accessorKey: "qualityOfService",
|
|
||||||
size: 100,
|
|
||||||
Header: <ColumnHeading>Qlt of Service</ColumnHeading>,
|
|
||||||
Cell: ({ row }) => (
|
|
||||||
<Typography variant="body4">
|
|
||||||
{row.original.qualityOfService.toFixed()}%
|
|
||||||
</Typography>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: "location",
|
id: "location",
|
||||||
header: "Location",
|
header: "Location",
|
||||||
@@ -255,6 +209,98 @@ const NodeTable = ({ nodes }: { nodes: MappedNymNodes }) => {
|
|||||||
"-"
|
"-"
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "name",
|
||||||
|
header: "",
|
||||||
|
size: 210,
|
||||||
|
|
||||||
|
Header: <ColumnHeading>Node</ColumnHeading>,
|
||||||
|
accessorKey: "name",
|
||||||
|
Cell: ({ row }) => (
|
||||||
|
<Stack spacing={1}>
|
||||||
|
<Typography variant="body4">{row.original.name || "-"}</Typography>
|
||||||
|
<Tooltip
|
||||||
|
title={row.original.identity_key}
|
||||||
|
placement="bottom"
|
||||||
|
slotProps={{
|
||||||
|
tooltip: {
|
||||||
|
sx: {
|
||||||
|
maxWidth: "none",
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
bgcolor: isDarkMode ? "#374042" : "#E5E7EB",
|
||||||
|
color: isDarkMode ? "#FFFFFF" : "#000000",
|
||||||
|
"& .MuiTooltip-arrow": {
|
||||||
|
color: isDarkMode ? "#374042" : "#E5E7EB",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
justifyContent="space-between"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
sx={{ height: "24px" }}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="body5"
|
||||||
|
sx={{
|
||||||
|
height: "24px",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{row.original.identity_key.length > 17
|
||||||
|
? `${row.original.identity_key.slice(0, 10)}...${row.original.identity_key.slice(-8)}`
|
||||||
|
: row.original.identity_key}
|
||||||
|
</Typography>
|
||||||
|
<CopyToClipboard text={row.original.identity_key} />
|
||||||
|
</Stack>
|
||||||
|
</Tooltip>
|
||||||
|
</Stack>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "id",
|
||||||
|
header: "",
|
||||||
|
Header: <ColumnHeading>Node ID</ColumnHeading>,
|
||||||
|
accessorKey: "nodeId",
|
||||||
|
size: 90,
|
||||||
|
Cell: ({ row }) => (
|
||||||
|
<Stack spacing={1}>
|
||||||
|
<Typography variant="body4">{row.original.nodeId}</Typography>
|
||||||
|
</Stack>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: "qos",
|
||||||
|
header: "Qlt of Service",
|
||||||
|
align: "center",
|
||||||
|
accessorKey: "qualityOfService",
|
||||||
|
size: 100,
|
||||||
|
Header: <ColumnHeading>Uptime</ColumnHeading>,
|
||||||
|
Cell: ({ row }) => {
|
||||||
|
const value = row.original.qualityOfService;
|
||||||
|
let color = "#000000";
|
||||||
|
|
||||||
|
if (value >= 80) {
|
||||||
|
color = "#22C55E"; // green
|
||||||
|
} else if (value >= 50) {
|
||||||
|
color = "#F59E0B"; // amber/orange-yellow
|
||||||
|
} else {
|
||||||
|
color = "#EF4444"; // red
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Typography variant="body4" sx={{ color, fontWeight: 400 }}>
|
||||||
|
{value.toFixed()}%
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
id: "stakeSaturation",
|
id: "stakeSaturation",
|
||||||
header: "Stake saturation",
|
header: "Stake saturation",
|
||||||
@@ -262,9 +308,58 @@ const NodeTable = ({ nodes }: { nodes: MappedNymNodes }) => {
|
|||||||
size: 120,
|
size: 120,
|
||||||
|
|
||||||
Header: <ColumnHeading>Saturation</ColumnHeading>,
|
Header: <ColumnHeading>Saturation</ColumnHeading>,
|
||||||
|
Cell: ({ row }) => {
|
||||||
|
const value = row.original.stakeSaturation;
|
||||||
|
let color = "#000000";
|
||||||
|
|
||||||
|
if (value > 100) {
|
||||||
|
color = "#EF4444";
|
||||||
|
} else if (value >= 75) {
|
||||||
|
color = "#22C55E";
|
||||||
|
} else if (value >= 25) {
|
||||||
|
color = "#F59E0B";
|
||||||
|
} else {
|
||||||
|
color = "#EF4444";
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Typography variant="body4" sx={{ color, fontWeight: 400 }}>
|
||||||
|
{value}%
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "selfBond",
|
||||||
|
header: "Self-bond",
|
||||||
|
accessorKey: "selfBond",
|
||||||
|
Header: <ColumnHeading>Self-bond</ColumnHeading>,
|
||||||
|
Cell: ({ row }) => {
|
||||||
|
const value = row.original.selfBond;
|
||||||
|
let color = isDarkMode ? "#FFFFFF" : "#000000";
|
||||||
|
|
||||||
|
if (value === 0) {
|
||||||
|
color = "#EF4444";
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Typography
|
||||||
|
variant="body4"
|
||||||
|
sx={{ color, fontWeight: value === 0 ? 400 : 300 }}
|
||||||
|
>
|
||||||
|
{row.original.selfBond} NYM
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "operatingCosts",
|
||||||
|
header: "Operating costs",
|
||||||
|
accessorKey: "operatingCosts",
|
||||||
|
Header: <ColumnHeading>Operating costs</ColumnHeading>,
|
||||||
Cell: ({ row }) => (
|
Cell: ({ row }) => (
|
||||||
<Typography variant="body4">
|
<Typography variant="body4">
|
||||||
{row.original.stakeSaturation}%
|
{row.original.operatingCosts} NYM
|
||||||
</Typography>
|
</Typography>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -303,7 +398,7 @@ const NodeTable = ({ nodes }: { nodes: MappedNymNodes }) => {
|
|||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[isWalletConnected, handleOnSelectStake, favorites],
|
[isWalletConnected, handleOnSelectStake, favorites, isDarkMode]
|
||||||
);
|
);
|
||||||
const table = useMaterialReactTable({
|
const table = useMaterialReactTable({
|
||||||
columns,
|
columns,
|
||||||
@@ -410,8 +505,12 @@ const NodeTable = ({ nodes }: { nodes: MappedNymNodes }) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
muiTableBodyRowProps: ({ row }) => ({
|
muiTableBodyRowProps: ({ row }) => ({
|
||||||
onClick: () => {
|
onClick: (e) => {
|
||||||
router.push(`/nym-node/${row.original.nodeId}`);
|
if (e.ctrlKey || e.metaKey) {
|
||||||
|
window.open(`/explorer/nym-node/${row.original.nodeId}`, "_blank");
|
||||||
|
} else {
|
||||||
|
router.push(`/nym-node/${row.original.nodeId}`);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
hover: true,
|
hover: true,
|
||||||
sx: {
|
sx: {
|
||||||
|
|||||||
@@ -3,15 +3,18 @@
|
|||||||
import { Card, CardContent, Skeleton, Stack, Typography } from "@mui/material";
|
import { Card, CardContent, Skeleton, Stack, Typography } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import DOMPurify from "isomorphic-dompurify";
|
import DOMPurify from "isomorphic-dompurify";
|
||||||
import { fetchEpochRewards, fetchObservatoryNodes } from "../../app/api";
|
import { fetchEpochRewards, fetchNSApiNodes } from "../../app/api";
|
||||||
import type { ExplorerData, IObservatoryNode } from "../../app/api/types";
|
import type { ExplorerData, NS_NODE } from "../../app/api/types";
|
||||||
import { countryName } from "../../utils/countryName";
|
import { countryName } from "../../utils/countryName";
|
||||||
import NodeTable from "./NodeTable";
|
import NodeTable from "./NodeTable";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import AdvancedFilters from "./AdvancedFilters";
|
||||||
|
import { RECOMMENDED_NODES } from "@/app/constants";
|
||||||
|
|
||||||
// Utility function to calculate node saturation point
|
// Utility function to calculate node saturation point
|
||||||
function getNodeSaturationPoint(
|
function getNodeSaturationPoint(
|
||||||
totalStake: number,
|
totalStake: number,
|
||||||
stakeSaturationPoint: string,
|
stakeSaturationPoint: string
|
||||||
): number {
|
): number {
|
||||||
const saturation = Number.parseFloat(stakeSaturationPoint);
|
const saturation = Number.parseFloat(stakeSaturationPoint);
|
||||||
|
|
||||||
@@ -25,39 +28,129 @@ function getNodeSaturationPoint(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Map nodes with rewards data
|
// Map nodes with rewards data
|
||||||
const mappedNymNodes = (
|
|
||||||
nodes: IObservatoryNode[],
|
const mappedNSApiNodes = (
|
||||||
epochRewardsData: ExplorerData["currentEpochRewardsData"],
|
nodes: NS_NODE[],
|
||||||
|
epochRewardsData: ExplorerData["currentEpochRewardsData"]
|
||||||
) =>
|
) =>
|
||||||
nodes.map((node) => {
|
nodes
|
||||||
const nodeSaturationPoint = getNodeSaturationPoint(
|
.map((node) => {
|
||||||
node.total_stake,
|
const nodeSaturationPoint = getNodeSaturationPoint(
|
||||||
epochRewardsData.interval.stake_saturation_point,
|
+node.total_stake,
|
||||||
);
|
epochRewardsData.interval.stake_saturation_point
|
||||||
|
);
|
||||||
|
|
||||||
const cleanMoniker = DOMPurify.sanitize(
|
const cleanMoniker = DOMPurify.sanitize(node.description.moniker).replace(
|
||||||
node.self_description.moniker,
|
/&/g,
|
||||||
).replace(/&/g, "&");
|
"&"
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
const selfBondFormatted = node.original_pledge
|
||||||
name: cleanMoniker,
|
? Number(node.original_pledge) / 1_000_000
|
||||||
nodeId: node.node_id,
|
: 0;
|
||||||
identity_key: node.identity_key,
|
|
||||||
countryCode: node.description.auxiliary_details.location || null,
|
|
||||||
countryName:
|
|
||||||
countryName(node.description.auxiliary_details.location) || null,
|
|
||||||
profitMarginPercentage:
|
|
||||||
+node.rewarding_details.cost_params.profit_margin_percent * 100,
|
|
||||||
owner: node.bonding_address,
|
|
||||||
stakeSaturation: nodeSaturationPoint,
|
|
||||||
qualityOfService: +node.uptime * 100,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
export type MappedNymNodes = ReturnType<typeof mappedNymNodes>;
|
const operatingCostsFormatted = node.rewarding_details
|
||||||
|
? Number(
|
||||||
|
node.rewarding_details.cost_params.interval_operating_cost.amount
|
||||||
|
) / 1_000_000
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: cleanMoniker,
|
||||||
|
nodeId: node.node_id,
|
||||||
|
identity_key: node.identity_key,
|
||||||
|
countryCode: node.geoip?.country || null,
|
||||||
|
countryName: countryName(node.geoip?.country || null) || null,
|
||||||
|
selfBond: selfBondFormatted,
|
||||||
|
operatingCosts: operatingCostsFormatted,
|
||||||
|
profitMarginPercentage: node.rewarding_details
|
||||||
|
? +node.rewarding_details.cost_params.profit_margin_percent * 100
|
||||||
|
: 0,
|
||||||
|
owner: node.bonding_address,
|
||||||
|
stakeSaturation: nodeSaturationPoint,
|
||||||
|
qualityOfService: +node.uptime * 100,
|
||||||
|
mixnode: node.self_description?.declared_role.mixnode === true,
|
||||||
|
gateway:
|
||||||
|
node.self_description?.declared_role.entry === true ||
|
||||||
|
node.self_description?.declared_role.exit_ipr === true ||
|
||||||
|
node.self_description?.declared_role.exit_nr === true,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.sort((a, b) => {
|
||||||
|
// Handle null country names by putting them at the end
|
||||||
|
if (!a.countryName && !b.countryName) return 0;
|
||||||
|
if (!a.countryName) return 1;
|
||||||
|
if (!b.countryName) return -1;
|
||||||
|
|
||||||
|
// Sort alphabetically by country name
|
||||||
|
return a.countryName.localeCompare(b.countryName);
|
||||||
|
});
|
||||||
|
|
||||||
|
export type MappedNymNodes = ReturnType<typeof mappedNSApiNodes>;
|
||||||
export type MappedNymNode = MappedNymNodes[0];
|
export type MappedNymNode = MappedNymNodes[0];
|
||||||
|
|
||||||
const NodeTableWithAction = () => {
|
const NodeTableWithAction = () => {
|
||||||
|
// All hooks at the top!
|
||||||
|
const [activeFilter, setActiveFilter] = useState<
|
||||||
|
"all" | "mixnodes" | "gateways" | "recommended"
|
||||||
|
>(() => {
|
||||||
|
const stored = sessionStorage.getItem("nodeTableActiveFilter");
|
||||||
|
return (
|
||||||
|
(stored as "all" | "mixnodes" | "gateways" | "recommended") ||
|
||||||
|
"recommended"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
const [uptime, setUptime] = useState<[number, number]>(() => {
|
||||||
|
const stored = sessionStorage.getItem("nodeTableUptime");
|
||||||
|
return stored ? JSON.parse(stored) : [0, 100];
|
||||||
|
});
|
||||||
|
const [saturation, setSaturation] = useState<[number, number]>([0, 100]);
|
||||||
|
const [profitMargin, setProfitMargin] = useState<[number, number]>(() => {
|
||||||
|
const stored = sessionStorage.getItem("nodeTableProfitMargin");
|
||||||
|
return stored ? JSON.parse(stored) : [0, 100];
|
||||||
|
});
|
||||||
|
const [advancedOpen, setAdvancedOpen] = useState(() => {
|
||||||
|
const stored = sessionStorage.getItem("nodeTableAdvancedOpen");
|
||||||
|
return stored ? JSON.parse(stored) : false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wrapper functions to handle filter changes and sessionStorage
|
||||||
|
const handleActiveFilterChange = (
|
||||||
|
newFilter: "all" | "mixnodes" | "gateways" | "recommended"
|
||||||
|
) => {
|
||||||
|
setActiveFilter(newFilter);
|
||||||
|
sessionStorage.setItem("nodeTableActiveFilter", newFilter);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUptimeChange = (newUptime: [number, number]) => {
|
||||||
|
setUptime(newUptime);
|
||||||
|
sessionStorage.setItem("nodeTableUptime", JSON.stringify(newUptime));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSaturationChange = (newSaturation: [number, number]) => {
|
||||||
|
setSaturation(newSaturation);
|
||||||
|
sessionStorage.setItem(
|
||||||
|
"nodeTableSaturation",
|
||||||
|
JSON.stringify(newSaturation)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleProfitMarginChange = (newProfitMargin: [number, number]) => {
|
||||||
|
setProfitMargin(newProfitMargin);
|
||||||
|
sessionStorage.setItem(
|
||||||
|
"nodeTableProfitMargin",
|
||||||
|
JSON.stringify(newProfitMargin)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAdvancedOpenChange = (newAdvancedOpen: boolean) => {
|
||||||
|
setAdvancedOpen(newAdvancedOpen);
|
||||||
|
sessionStorage.setItem(
|
||||||
|
"nodeTableAdvancedOpen",
|
||||||
|
JSON.stringify(newAdvancedOpen)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Use React Query to fetch epoch rewards
|
// Use React Query to fetch epoch rewards
|
||||||
const {
|
const {
|
||||||
data: epochRewardsData,
|
data: epochRewardsData,
|
||||||
@@ -74,20 +167,48 @@ const NodeTableWithAction = () => {
|
|||||||
|
|
||||||
// Use React Query to fetch Nym nodes
|
// Use React Query to fetch Nym nodes
|
||||||
const {
|
const {
|
||||||
data: nymNodes = [],
|
data: nsApiNodes = [],
|
||||||
isLoading: isNodesLoading,
|
isLoading: isNSApiNodesLoading,
|
||||||
isError: isNodesError,
|
isError: isNSApiNodesError,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: fetchObservatoryNodes,
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Map nodes with rewards data
|
||||||
|
const nsApiNodesData = epochRewardsData
|
||||||
|
? mappedNSApiNodes(nsApiNodes || [], epochRewardsData)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
// Calculate max saturation from all nodes
|
||||||
|
const maxSaturation = Math.max(
|
||||||
|
100,
|
||||||
|
...nsApiNodesData.map((n) => n.stakeSaturation || 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Initialize saturation from sessionStorage or set to maxSaturation when data is loaded
|
||||||
|
useEffect(() => {
|
||||||
|
const stored = sessionStorage.getItem("nodeTableSaturation");
|
||||||
|
if (stored) {
|
||||||
|
setSaturation(JSON.parse(stored));
|
||||||
|
} else if (nsApiNodesData.length > 0) {
|
||||||
|
setSaturation([0, maxSaturation]);
|
||||||
|
}
|
||||||
|
}, [maxSaturation, nsApiNodesData.length]);
|
||||||
|
|
||||||
|
// Calculate node counts for each type
|
||||||
|
const nodeCounts = {
|
||||||
|
all: nsApiNodesData.length,
|
||||||
|
mixnodes: nsApiNodesData.filter((node) => node.mixnode).length,
|
||||||
|
gateways: nsApiNodesData.filter((node) => node.gateway).length,
|
||||||
|
};
|
||||||
|
|
||||||
// Handle loading state
|
// Handle loading state
|
||||||
if (isEpochLoading || isNodesLoading) {
|
if (isEpochLoading || isNSApiNodesLoading) {
|
||||||
return (
|
return (
|
||||||
<Card sx={{ height: "100%", mt: 5 }}>
|
<Card sx={{ height: "100%", mt: 5 }}>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
@@ -101,7 +222,7 @@ const NodeTableWithAction = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle error state
|
// Handle error state
|
||||||
if (isEpochError || isNodesError) {
|
if (isEpochError || isNSApiNodesError) {
|
||||||
return (
|
return (
|
||||||
<Stack direction="row" spacing={1}>
|
<Stack direction="row" spacing={1}>
|
||||||
<Typography variant="h5" sx={{ color: "pine.600", letterSpacing: 0.7 }}>
|
<Typography variant="h5" sx={{ color: "pine.600", letterSpacing: 0.7 }}>
|
||||||
@@ -112,14 +233,67 @@ const NodeTableWithAction = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Map nodes with rewards data
|
// Map nodes with rewards data
|
||||||
|
|
||||||
if (!epochRewardsData) {
|
if (!epochRewardsData) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = mappedNymNodes(nymNodes || [], epochRewardsData);
|
// Step 1: Filter nodes by type
|
||||||
|
const typeFilteredNodes = nsApiNodesData.filter((node) => {
|
||||||
|
switch (activeFilter) {
|
||||||
|
case "mixnodes":
|
||||||
|
return node.mixnode;
|
||||||
|
case "gateways":
|
||||||
|
return node.gateway;
|
||||||
|
case "recommended":
|
||||||
|
return RECOMMENDED_NODES.includes(node.nodeId);
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return <NodeTable nodes={data} />;
|
// Step 2: If advanced filters are open, apply them only if sliders are not at default
|
||||||
|
const isDefault = {
|
||||||
|
uptime: uptime[0] === 0 && uptime[1] === 100,
|
||||||
|
saturation: saturation[0] === 0 && saturation[1] === maxSaturation,
|
||||||
|
profitMargin: profitMargin[0] === 0 && profitMargin[1] === 100,
|
||||||
|
};
|
||||||
|
const filteredNodes = advancedOpen
|
||||||
|
? typeFilteredNodes.filter((node) => {
|
||||||
|
const uptimeMatch =
|
||||||
|
isDefault.uptime ||
|
||||||
|
(node.qualityOfService >= uptime[0] &&
|
||||||
|
node.qualityOfService <= uptime[1]);
|
||||||
|
const saturationMatch =
|
||||||
|
isDefault.saturation ||
|
||||||
|
(node.stakeSaturation >= saturation[0] &&
|
||||||
|
node.stakeSaturation <= saturation[1]);
|
||||||
|
const profitMarginMatch =
|
||||||
|
isDefault.profitMargin ||
|
||||||
|
(node.profitMarginPercentage >= profitMargin[0] &&
|
||||||
|
node.profitMarginPercentage <= profitMargin[1]);
|
||||||
|
return uptimeMatch && saturationMatch && profitMarginMatch;
|
||||||
|
})
|
||||||
|
: typeFilteredNodes;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack spacing={3}>
|
||||||
|
<AdvancedFilters
|
||||||
|
open={advancedOpen}
|
||||||
|
setOpen={handleAdvancedOpenChange}
|
||||||
|
uptime={uptime}
|
||||||
|
setUptime={handleUptimeChange}
|
||||||
|
saturation={saturation}
|
||||||
|
setSaturation={handleSaturationChange}
|
||||||
|
profitMargin={profitMargin}
|
||||||
|
setProfitMargin={handleProfitMarginChange}
|
||||||
|
maxSaturation={maxSaturation}
|
||||||
|
activeFilter={activeFilter}
|
||||||
|
setActiveFilter={handleActiveFilterChange}
|
||||||
|
nodeCounts={nodeCounts}
|
||||||
|
/>
|
||||||
|
<NodeTable nodes={filteredNodes} />
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default NodeTableWithAction;
|
export default NodeTableWithAction;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { IObservatoryNode } from "@/app/api/types";
|
import type { NS_NODE } from "@/app/api/types";
|
||||||
import { Skeleton, Stack, Typography } from "@mui/material";
|
import { Skeleton, Stack, Typography, useTheme } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { fetchObservatoryNodes } from "../../app/api";
|
import { fetchNSApiNodes } from "../../app/api";
|
||||||
import { formatBigNum } from "../../utils/formatBigNumbers";
|
import { formatBigNum } from "../../utils/formatBigNumbers";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
import CopyToClipboard from "../copyToClipboard/CopyToClipboard";
|
import CopyToClipboard from "../copyToClipboard/CopyToClipboard";
|
||||||
@@ -14,22 +14,25 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const BasicInfoCard = ({ paramId }: Props) => {
|
export const BasicInfoCard = ({ paramId }: Props) => {
|
||||||
let nodeInfo: IObservatoryNode | undefined;
|
let nodeInfo: NS_NODE | undefined;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: nymNodes,
|
data: nsApiNodes = [],
|
||||||
isLoading,
|
isLoading: isNSApiNodesLoading,
|
||||||
isError,
|
isError: isNSApiNodesError,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: fetchObservatoryNodes,
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoading) {
|
const theme = useTheme();
|
||||||
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
|
|
||||||
|
if (isNSApiNodesLoading) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Basic info">
|
<ExplorerCard label="Basic info">
|
||||||
<Skeleton variant="text" height={90} />
|
<Skeleton variant="text" height={90} />
|
||||||
@@ -42,10 +45,13 @@ export const BasicInfoCard = ({ paramId }: Props) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError || !nymNodes) {
|
if (!nsApiNodes || isNSApiNodesError) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Basic info">
|
<ExplorerCard label="Basic info">
|
||||||
<Typography variant="h3" sx={{ color: "pine.950" }}>
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
|
>
|
||||||
Failed to load node data.
|
Failed to load node data.
|
||||||
</Typography>
|
</Typography>
|
||||||
</ExplorerCard>
|
</ExplorerCard>
|
||||||
@@ -55,16 +61,21 @@ export const BasicInfoCard = ({ paramId }: Props) => {
|
|||||||
// get node info based on wether it's dentity_key or node_id
|
// get node info based on wether it's dentity_key or node_id
|
||||||
|
|
||||||
if (paramId.length > 10) {
|
if (paramId.length > 10) {
|
||||||
nodeInfo = nymNodes.find((node) => node.identity_key === paramId);
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.identity_key === paramId
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
nodeInfo = nymNodes.find((node) => node.node_id === Number(paramId));
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.node_id === Number(paramId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nodeInfo) return null;
|
if (!nodeInfo) return null;
|
||||||
|
|
||||||
const selfBond = formatBigNum(
|
|
||||||
Number(nodeInfo.rewarding_details.operator) / 1_000_000,
|
const selfBond = nodeInfo.original_pledge
|
||||||
);
|
? formatBigNum(Number(nodeInfo.original_pledge) / 1_000_000)
|
||||||
|
: 0;
|
||||||
const selfBondFormatted = `${selfBond} NYM`;
|
const selfBondFormatted = `${selfBond} NYM`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -85,9 +96,13 @@ export const BasicInfoCard = ({ paramId }: Props) => {
|
|||||||
variant="body4"
|
variant="body4"
|
||||||
sx={{ wordWrap: "break-word", maxWidth: "90%" }}
|
sx={{ wordWrap: "break-word", maxWidth: "90%" }}
|
||||||
>
|
>
|
||||||
{nodeInfo.bonding_address}
|
{nodeInfo.bonding_address
|
||||||
|
? nodeInfo.bonding_address
|
||||||
|
: "Node not bonded"}
|
||||||
</Typography>
|
</Typography>
|
||||||
<CopyToClipboard text={nodeInfo.bonding_address} />
|
{nodeInfo.bonding_address && (
|
||||||
|
<CopyToClipboard text={nodeInfo.bonding_address} />
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -113,12 +128,14 @@ export const BasicInfoCard = ({ paramId }: Props) => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ExplorerListItem
|
{nodeInfo.rewarding_details && (
|
||||||
row
|
<ExplorerListItem
|
||||||
divider
|
row
|
||||||
label="Nr. of stakers"
|
divider
|
||||||
value={nodeInfo.rewarding_details.unique_delegations.toString()}
|
label="Nr. of stakers"
|
||||||
/>
|
value={nodeInfo.rewarding_details.unique_delegations.toString()}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<ExplorerListItem row label="Self bonded" value={selfBondFormatted} />
|
<ExplorerListItem row label="Self bonded" value={selfBondFormatted} />
|
||||||
</Stack>
|
</Stack>
|
||||||
</ExplorerCard>
|
</ExplorerCard>
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ const DelegationsTable = ({ id }: Props) => {
|
|||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const columns: MRT_ColumnDef<NodeRewardDetails>[] = useMemo(
|
const columns: MRT_ColumnDef<NodeRewardDetails>[] = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
@@ -55,7 +56,7 @@ const DelegationsTable = ({ id }: Props) => {
|
|||||||
accessorKey: "height",
|
accessorKey: "height",
|
||||||
Cell: ({ row }) => (
|
Cell: ({ row }) => (
|
||||||
<Stack spacing={1}>
|
<Stack spacing={1}>
|
||||||
<Typography variant="body4">{row.original.height}</Typography>
|
<Typography variant="body4">{row.original.block_height}</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -86,7 +87,7 @@ const DelegationsTable = ({ id }: Props) => {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
const table = useMaterialReactTable({
|
const table = useMaterialReactTable({
|
||||||
columns,
|
columns,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { IObservatoryNode } from "@/app/api/types";
|
import type { NS_NODE } from "@/app/api/types";
|
||||||
import { Skeleton, Typography } from "@mui/material";
|
import { Skeleton, Typography, useTheme } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { fetchEpochRewards, fetchObservatoryNodes } from "../../app/api";
|
import { fetchEpochRewards, fetchNSApiNodes } from "../../app/api";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
import ExplorerListItem from "../list/ListItem";
|
import ExplorerListItem from "../list/ListItem";
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const NodeDataCard = ({ paramId }: Props) => {
|
export const NodeDataCard = ({ paramId }: Props) => {
|
||||||
let nodeInfo: IObservatoryNode | undefined;
|
let nodeInfo: NS_NODE | undefined;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: epochRewardsData,
|
data: epochRewardsData,
|
||||||
@@ -30,19 +30,22 @@ export const NodeDataCard = ({ paramId }: Props) => {
|
|||||||
|
|
||||||
// Fetch node information
|
// Fetch node information
|
||||||
const {
|
const {
|
||||||
data: nymNodes,
|
data: nsApiNodes = [],
|
||||||
isLoading,
|
isLoading: isNSApiNodesLoading,
|
||||||
isError,
|
isError: isNSApiNodesError,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: fetchObservatoryNodes,
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isEpochLoading || isLoading) {
|
const theme = useTheme();
|
||||||
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
|
|
||||||
|
if (isEpochLoading || isNSApiNodesLoading) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Nym node data" sx={{ height: "100%" }}>
|
<ExplorerCard label="Nym node data" sx={{ height: "100%" }}>
|
||||||
<Skeleton variant="text" height={50} />
|
<Skeleton variant="text" height={50} />
|
||||||
@@ -53,10 +56,13 @@ export const NodeDataCard = ({ paramId }: Props) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEpochError || isError || !nymNodes || !epochRewardsData) {
|
if (isEpochError || isNSApiNodesError || !nsApiNodes || !epochRewardsData) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Nym node data" sx={{ height: "100%" }}>
|
<ExplorerCard label="Nym node data" sx={{ height: "100%" }}>
|
||||||
<Typography variant="h3" sx={{ color: "pine.950" }}>
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
|
>
|
||||||
Failed to load node data.
|
Failed to load node data.
|
||||||
</Typography>
|
</Typography>
|
||||||
</ExplorerCard>
|
</ExplorerCard>
|
||||||
@@ -66,17 +72,23 @@ export const NodeDataCard = ({ paramId }: Props) => {
|
|||||||
// get node info based on wether it's dentity_key or node_id
|
// get node info based on wether it's dentity_key or node_id
|
||||||
|
|
||||||
if (paramId.length > 10) {
|
if (paramId.length > 10) {
|
||||||
nodeInfo = nymNodes.find((node) => node.identity_key === paramId);
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.identity_key === paramId
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
nodeInfo = nymNodes.find((node) => node.node_id === Number(paramId));
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.node_id === Number(paramId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nodeInfo) return null;
|
if (!nodeInfo) return null;
|
||||||
|
|
||||||
const softwareUpdateTime = format(
|
const softwareUpdateTime = nodeInfo.self_description
|
||||||
new Date(nodeInfo.description.build_information.build_timestamp),
|
? format(
|
||||||
"dd/MM/yyyy",
|
new Date(nodeInfo.self_description.build_information.build_timestamp),
|
||||||
);
|
"dd/MM/yyyy"
|
||||||
|
)
|
||||||
|
: "N/A";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Nym node data" sx={{ height: "100%" }}>
|
<ExplorerCard label="Nym node data" sx={{ height: "100%" }}>
|
||||||
@@ -90,13 +102,21 @@ export const NodeDataCard = ({ paramId }: Props) => {
|
|||||||
row
|
row
|
||||||
divider
|
divider
|
||||||
label="Host"
|
label="Host"
|
||||||
value={nodeInfo.description.host_information.ip_address.toString()}
|
value={
|
||||||
|
nodeInfo.self_description
|
||||||
|
? nodeInfo.self_description.host_information.ip_address.toString()
|
||||||
|
: "N/A"
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<ExplorerListItem
|
<ExplorerListItem
|
||||||
row
|
row
|
||||||
divider
|
divider
|
||||||
label="Version"
|
label="Version"
|
||||||
value={nodeInfo.description.build_information.build_version}
|
value={
|
||||||
|
nodeInfo.self_description
|
||||||
|
? nodeInfo.self_description.build_information.build_version
|
||||||
|
: "N/A"
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<ExplorerListItem
|
<ExplorerListItem
|
||||||
row
|
row
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { fetchObservatoryNodes } from "@/app/api";
|
import { fetchNSApiNodes } from "@/app/api";
|
||||||
import type { IObservatoryNode } from "@/app/api/types";
|
import type { NS_NODE } from "@/app/api/types";
|
||||||
import { Skeleton, Typography } from "@mui/material";
|
import { Skeleton, Typography, useTheme } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
import DelegationsTable from "./DelegationsTable";
|
import DelegationsTable from "./DelegationsTable";
|
||||||
@@ -12,15 +12,17 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const NodeDelegationsCard = ({ paramId }: Props) => {
|
const NodeDelegationsCard = ({ paramId }: Props) => {
|
||||||
let nodeInfo: IObservatoryNode | undefined;
|
const theme = useTheme();
|
||||||
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
|
let nodeInfo: NS_NODE | undefined;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: nymNodes,
|
data: nsApiNodes = [],
|
||||||
isError,
|
isLoading: isNSApiNodesLoading,
|
||||||
isLoading,
|
isError: isNSApiNodesError,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: fetchObservatoryNodes,
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
@@ -28,16 +30,20 @@ const NodeDelegationsCard = ({ paramId }: Props) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (paramId.length > 10) {
|
if (paramId.length > 10) {
|
||||||
nodeInfo = nymNodes?.find((node) => node.identity_key === paramId);
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.identity_key === paramId
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
nodeInfo = nymNodes?.find((node) => node.node_id === Number(paramId));
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.node_id === Number(paramId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nodeInfo) return null;
|
if (!nodeInfo) return null;
|
||||||
|
|
||||||
const id = nodeInfo.node_id;
|
const id = nodeInfo.node_id;
|
||||||
|
|
||||||
if (isLoading) {
|
if (isNSApiNodesLoading) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Delegations" sx={{ height: "100%" }}>
|
<ExplorerCard label="Delegations" sx={{ height: "100%" }}>
|
||||||
<Skeleton variant="text" height={50} />
|
<Skeleton variant="text" height={50} />
|
||||||
@@ -48,10 +54,13 @@ const NodeDelegationsCard = ({ paramId }: Props) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError) {
|
if (isNSApiNodesError) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Delegations" sx={{ height: "100%" }}>
|
<ExplorerCard label="Delegations" sx={{ height: "100%" }}>
|
||||||
<Typography variant="h3" sx={{ color: "pine.950" }}>
|
<Typography
|
||||||
|
variant="h3"
|
||||||
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
|
>
|
||||||
Failed to load delegations. Please try again later.
|
Failed to load delegations. Please try again later.
|
||||||
</Typography>
|
</Typography>
|
||||||
</ExplorerCard>
|
</ExplorerCard>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { fetchObservatoryNodes } from "@/app/api";
|
import { fetchNSApiNodes } from "@/app/api";
|
||||||
import type { IObservatoryNode } from "@/app/api/types";
|
import type { NS_NODE } from "@/app/api/types";
|
||||||
import ExplorerButtonGroup from "@/components/toggleButton/ToggleButton";
|
import ExplorerButtonGroup from "@/components/toggleButton/ToggleButton";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
@@ -10,27 +10,32 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function NodePageButtonGroup({ paramId }: Props) {
|
export default function NodePageButtonGroup({ paramId }: Props) {
|
||||||
let nodeInfo: IObservatoryNode | undefined;
|
let nodeInfo: NS_NODE | undefined;
|
||||||
|
|
||||||
const { data: nymNodes, isError } = useQuery({
|
const { data: nsApiNodes = [], isError: isNSApiNodesError } = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: fetchObservatoryNodes,
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!nymNodes || isError) return null;
|
if (!nsApiNodes || isNSApiNodesError) return null;
|
||||||
|
|
||||||
// get node info based on wether it's dentity_key or node_id
|
// get node info based on wether it's dentity_key or node_id
|
||||||
|
|
||||||
if (paramId.length > 10) {
|
if (paramId.length > 10) {
|
||||||
nodeInfo = nymNodes.find((node) => node.identity_key === paramId);
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.identity_key === paramId
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
nodeInfo = nymNodes.find((node) => node.node_id === Number(paramId));
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.node_id === Number(paramId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!nodeInfo) return null;
|
if (!nodeInfo) return null;
|
||||||
|
|
||||||
if (nodeInfo.bonding_address)
|
if (nodeInfo.bonding_address)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { formatBigNum } from "@/utils/formatBigNumbers";
|
import { formatBigNum } from "@/utils/formatBigNumbers";
|
||||||
import { Skeleton, Typography } from "@mui/material";
|
import { Skeleton, Typography, useTheme } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { fetchEpochRewards, fetchObservatoryNodes } from "../../app/api";
|
import { fetchEpochRewards, fetchNSApiNodes } from "../../app/api";
|
||||||
import type { IObservatoryNode, RewardingDetails } from "../../app/api/types";
|
import type { NS_NODE } from "../../app/api/types";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
import ExplorerListItem from "../list/ListItem";
|
import ExplorerListItem from "../list/ListItem";
|
||||||
|
|
||||||
@@ -13,7 +13,9 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const NodeParametersCard = ({ paramId }: Props) => {
|
export const NodeParametersCard = ({ paramId }: Props) => {
|
||||||
let nodeInfo: IObservatoryNode | undefined;
|
const theme = useTheme();
|
||||||
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
|
let nodeInfo: NS_NODE | undefined;
|
||||||
|
|
||||||
// Fetch epoch rewards
|
// Fetch epoch rewards
|
||||||
const {
|
const {
|
||||||
@@ -31,19 +33,19 @@ export const NodeParametersCard = ({ paramId }: Props) => {
|
|||||||
|
|
||||||
// Fetch node information
|
// Fetch node information
|
||||||
const {
|
const {
|
||||||
data: nymNodes,
|
data: nsApiNodes = [],
|
||||||
isLoading,
|
isLoading: isNSApiNodesLoading,
|
||||||
isError,
|
isError: isNSApiNodesError,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: fetchObservatoryNodes,
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isEpochLoading || isLoading) {
|
if (isEpochLoading || isNSApiNodesLoading) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Node parameters" sx={{ height: "100%" }}>
|
<ExplorerCard label="Node parameters" sx={{ height: "100%" }}>
|
||||||
<Skeleton variant="text" height={50} />
|
<Skeleton variant="text" height={50} />
|
||||||
@@ -54,10 +56,13 @@ export const NodeParametersCard = ({ paramId }: Props) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEpochError || isError || !nymNodes || !epochRewardsData) {
|
if (isEpochError || isNSApiNodesError || !nsApiNodes || !epochRewardsData) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Node parameters" sx={{ height: "100%" }}>
|
<ExplorerCard label="Node parameters" sx={{ height: "100%" }}>
|
||||||
<Typography variant="h3" sx={{ color: "pine.950" }}>
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
|
>
|
||||||
Failed to load node data.
|
Failed to load node data.
|
||||||
</Typography>
|
</Typography>
|
||||||
</ExplorerCard>
|
</ExplorerCard>
|
||||||
@@ -66,9 +71,13 @@ export const NodeParametersCard = ({ paramId }: Props) => {
|
|||||||
// get node info based on wether it's dentity_key or node_id
|
// get node info based on wether it's dentity_key or node_id
|
||||||
|
|
||||||
if (paramId.length > 10) {
|
if (paramId.length > 10) {
|
||||||
nodeInfo = nymNodes.find((node) => node.identity_key === paramId);
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.identity_key === paramId
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
nodeInfo = nymNodes.find((node) => node.node_id === Number(paramId));
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.node_id === Number(paramId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nodeInfo) return null;
|
if (!nodeInfo) return null;
|
||||||
@@ -77,22 +86,25 @@ export const NodeParametersCard = ({ paramId }: Props) => {
|
|||||||
const totalStakeFormatted = `${totalStake} NYM`;
|
const totalStakeFormatted = `${totalStake} NYM`;
|
||||||
|
|
||||||
// Extract reward details
|
// Extract reward details
|
||||||
const rewardDetails: RewardingDetails = nodeInfo.rewarding_details;
|
|
||||||
|
|
||||||
const profitMarginPercent =
|
const profitMarginPercent = nodeInfo.rewarding_details
|
||||||
Number(rewardDetails.cost_params.profit_margin_percent) * 100;
|
? Number(nodeInfo.rewarding_details.cost_params.profit_margin_percent) * 100
|
||||||
|
: 0;
|
||||||
const profitMarginPercentFormated = `${profitMarginPercent}%`;
|
const profitMarginPercentFormated = `${profitMarginPercent}%`;
|
||||||
|
|
||||||
const operatingCosts =
|
const operatingCosts = nodeInfo.rewarding_details
|
||||||
Number(rewardDetails.cost_params.interval_operating_cost.amount) /
|
? Number(
|
||||||
1_000_000;
|
nodeInfo.rewarding_details.cost_params.interval_operating_cost.amount
|
||||||
|
) / 1_000_000
|
||||||
|
: 0;
|
||||||
const operatingCostsFormated = `${operatingCosts.toString()} NYM`;
|
const operatingCostsFormated = `${operatingCosts.toString()} NYM`;
|
||||||
|
|
||||||
const getNodeSaturationPoint = (
|
const getNodeSaturationPoint = (
|
||||||
totalStake: number,
|
nodeTotalStake: string,
|
||||||
stakeSaturationPoint: string,
|
stakeSaturationPoint: string
|
||||||
): string => {
|
): string => {
|
||||||
const saturation = Number.parseFloat(stakeSaturationPoint);
|
const saturation = Number.parseFloat(stakeSaturationPoint);
|
||||||
|
const totalStake = Number.parseFloat(nodeTotalStake);
|
||||||
|
|
||||||
if (Number.isNaN(saturation) || saturation <= 0) {
|
if (Number.isNaN(saturation) || saturation <= 0) {
|
||||||
throw new Error("Invalid stake saturation point provided");
|
throw new Error("Invalid stake saturation point provided");
|
||||||
@@ -105,7 +117,7 @@ export const NodeParametersCard = ({ paramId }: Props) => {
|
|||||||
|
|
||||||
const nodeSaturationPoint = getNodeSaturationPoint(
|
const nodeSaturationPoint = getNodeSaturationPoint(
|
||||||
nodeInfo.total_stake,
|
nodeInfo.total_stake,
|
||||||
epochRewardsData.interval.stake_saturation_point,
|
epochRewardsData.interval.stake_saturation_point
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { IObservatoryNode } from "@/app/api/types";
|
import type { NS_NODE } from "@/app/api/types";
|
||||||
import { useChain } from "@cosmos-kit/react";
|
import { useChain } from "@cosmos-kit/react";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
@@ -14,7 +14,7 @@ import { useQuery } from "@tanstack/react-query";
|
|||||||
import DOMPurify from "isomorphic-dompurify";
|
import DOMPurify from "isomorphic-dompurify";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import { RandomAvatar } from "react-random-avatars";
|
import { RandomAvatar } from "react-random-avatars";
|
||||||
import { fetchObservatoryNodes } from "../../app/api";
|
import { fetchNSApiNodes } from "../../app/api";
|
||||||
import { COSMOS_KIT_USE_CHAIN } from "../../config";
|
import { COSMOS_KIT_USE_CHAIN } from "../../config";
|
||||||
import { useNymClient } from "../../hooks/useNymClient";
|
import { useNymClient } from "../../hooks/useNymClient";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
@@ -31,7 +31,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const NodeProfileCard = ({ paramId }: Props) => {
|
export const NodeProfileCard = ({ paramId }: Props) => {
|
||||||
let nodeInfo: IObservatoryNode | undefined;
|
let nodeInfo: NS_NODE | undefined;
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const { isWalletConnected } = useChain(COSMOS_KIT_USE_CHAIN);
|
const { isWalletConnected } = useChain(COSMOS_KIT_USE_CHAIN);
|
||||||
@@ -47,12 +47,12 @@ export const NodeProfileCard = ({ paramId }: Props) => {
|
|||||||
|
|
||||||
// Fetch node info
|
// Fetch node info
|
||||||
const {
|
const {
|
||||||
data: nymNodes,
|
data: nsApiNodes = [],
|
||||||
isLoading: isLoadingNymNodes,
|
isLoading: isNSApiNodesLoading,
|
||||||
isError,
|
isError: isNSApiNodesError,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: fetchObservatoryNodes,
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
@@ -62,9 +62,13 @@ export const NodeProfileCard = ({ paramId }: Props) => {
|
|||||||
// get node info based on wether it's dentity_key or node_id
|
// get node info based on wether it's dentity_key or node_id
|
||||||
|
|
||||||
if (paramId.length > 10) {
|
if (paramId.length > 10) {
|
||||||
nodeInfo = nymNodes?.find((node) => node.identity_key === paramId);
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.identity_key === paramId
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
nodeInfo = nymNodes?.find((node) => node.node_id === Number(paramId));
|
nodeInfo = nsApiNodes.find(
|
||||||
|
(node: NS_NODE) => node.node_id === Number(paramId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnSelectStake = useCallback(() => {
|
const handleOnSelectStake = useCallback(() => {
|
||||||
@@ -96,7 +100,7 @@ export const NodeProfileCard = ({ paramId }: Props) => {
|
|||||||
}
|
}
|
||||||
}, [isWalletConnected, nodeInfo]);
|
}, [isWalletConnected, nodeInfo]);
|
||||||
|
|
||||||
if (isLoadingNymNodes) {
|
if (isNSApiNodesLoading) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Nym Node" sx={{ height: "100%" }}>
|
<ExplorerCard label="Nym Node" sx={{ height: "100%" }}>
|
||||||
<Skeleton variant="rectangular" height={80} width={80} />
|
<Skeleton variant="rectangular" height={80} width={80} />
|
||||||
@@ -105,11 +109,11 @@ export const NodeProfileCard = ({ paramId }: Props) => {
|
|||||||
</ExplorerCard>
|
</ExplorerCard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (isError || !nymNodes) {
|
if (isNSApiNodesError || !nsApiNodes) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Nym Node" sx={{ height: "100%" }}>
|
<ExplorerCard label="Nym Node" sx={{ height: "100%" }}>
|
||||||
<Typography
|
<Typography
|
||||||
variant="h3"
|
variant="h5"
|
||||||
sx={{
|
sx={{
|
||||||
color: theme.palette.mode === "dark" ? "base.white" : "pine.950",
|
color: theme.palette.mode === "dark" ? "base.white" : "pine.950",
|
||||||
}}
|
}}
|
||||||
@@ -137,7 +141,7 @@ export const NodeProfileCard = ({ paramId }: Props) => {
|
|||||||
{ nodeId },
|
{ nodeId },
|
||||||
fee,
|
fee,
|
||||||
"Delegation from Nym Explorer V2",
|
"Delegation from Nym Explorer V2",
|
||||||
uNymFunds,
|
uNymFunds
|
||||||
);
|
);
|
||||||
setSelectedNodeForStaking(undefined);
|
setSelectedNodeForStaking(undefined);
|
||||||
setInfoModalProps({
|
setInfoModalProps({
|
||||||
@@ -164,12 +168,13 @@ export const NodeProfileCard = ({ paramId }: Props) => {
|
|||||||
|
|
||||||
if (!nodeInfo) return null;
|
if (!nodeInfo) return null;
|
||||||
|
|
||||||
const cleanMoniker = DOMPurify.sanitize(
|
const cleanMoniker = DOMPurify.sanitize(nodeInfo.description.moniker).replace(
|
||||||
nodeInfo?.self_description.moniker,
|
/&/g,
|
||||||
).replace(/&/g, "&");
|
"&"
|
||||||
|
);
|
||||||
|
|
||||||
const cleanDescription = DOMPurify.sanitize(
|
const cleanDescription = DOMPurify.sanitize(
|
||||||
nodeInfo?.self_description.details,
|
nodeInfo.description.details
|
||||||
).replace(/&/g, "&");
|
).replace(/&/g, "&");
|
||||||
|
|
||||||
// get full country name
|
// get full country name
|
||||||
@@ -197,7 +202,7 @@ export const NodeProfileCard = ({ paramId }: Props) => {
|
|||||||
>
|
>
|
||||||
{cleanMoniker || "Moniker"}
|
{cleanMoniker || "Moniker"}
|
||||||
</Typography>
|
</Typography>
|
||||||
{nodeInfo.description.auxiliary_details.location && (
|
{nodeInfo.geoip?.country && (
|
||||||
<Box display={"flex"} gap={1}>
|
<Box display={"flex"} gap={1}>
|
||||||
<Typography
|
<Typography
|
||||||
variant="h6"
|
variant="h6"
|
||||||
@@ -210,10 +215,8 @@ export const NodeProfileCard = ({ paramId }: Props) => {
|
|||||||
|
|
||||||
<Box>
|
<Box>
|
||||||
<CountryFlag
|
<CountryFlag
|
||||||
countryCode={nodeInfo.description.auxiliary_details.location}
|
countryCode={nodeInfo.geoip?.country || ""}
|
||||||
countryName={countryName(
|
countryName={countryName(nodeInfo.geoip?.country || "")}
|
||||||
nodeInfo.description.auxiliary_details.location,
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Chip, Skeleton, Stack, Typography } from "@mui/material";
|
import { Chip, Skeleton, Stack, Typography, useTheme } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import {
|
import {
|
||||||
fetchEpochRewards,
|
fetchEpochRewards,
|
||||||
fetchGatewayStatus,
|
fetchGatewayStatus,
|
||||||
fetchObservatoryNodes,
|
fetchNSApiNodes,
|
||||||
} from "../../app/api";
|
} from "../../app/api";
|
||||||
import type {
|
import type {
|
||||||
IObservatoryNode,
|
|
||||||
LastProbeResult,
|
LastProbeResult,
|
||||||
NodeDescription,
|
NodeDescription,
|
||||||
|
NS_NODE,
|
||||||
} from "../../app/api/types";
|
} from "../../app/api/types";
|
||||||
import ExplorerCard from "../cards/ExplorerCard";
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
import ExplorerListItem from "../list/ListItem";
|
import ExplorerListItem from "../list/ListItem";
|
||||||
@@ -32,7 +32,7 @@ const roleMapping: Record<DeclaredRoleKey, RoleString> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getNodeRoles = (
|
const getNodeRoles = (
|
||||||
declaredRoles: NodeDescriptionNotNull["declared_role"],
|
declaredRoles: NodeDescriptionNotNull["declared_role"]
|
||||||
): RoleString[] => {
|
): RoleString[] => {
|
||||||
return Object.entries(declaredRoles)
|
return Object.entries(declaredRoles)
|
||||||
.filter(([, isActive]) => isActive)
|
.filter(([, isActive]) => isActive)
|
||||||
@@ -81,7 +81,7 @@ function calculateConfigScoreStars(probeResult: LastProbeResult): number {
|
|||||||
|
|
||||||
if (as_entry) {
|
if (as_entry) {
|
||||||
const entryScore = [as_entry.can_connect, as_entry.can_route].filter(
|
const entryScore = [as_entry.can_connect, as_entry.can_route].filter(
|
||||||
Boolean,
|
Boolean
|
||||||
).length;
|
).length;
|
||||||
|
|
||||||
return entryScore === 2 ? 4 : entryScore === 1 ? 2 : 1;
|
return entryScore === 2 ? 4 : entryScore === 1 ? 2 : 1;
|
||||||
@@ -148,21 +148,23 @@ function calculateWireguardPerformance(probeResult: LastProbeResult): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const NodeRoleCard = ({ paramId }: Props) => {
|
export const NodeRoleCard = ({ paramId }: Props) => {
|
||||||
let nodeInfo: IObservatoryNode | undefined;
|
let nodeInfo: NS_NODE | undefined;
|
||||||
|
const theme = useTheme();
|
||||||
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
// Fetch node info
|
// Fetch node info
|
||||||
const {
|
const {
|
||||||
data: nymNodes,
|
data: nsApiNodes = [],
|
||||||
isLoading,
|
isLoading: isNSApiNodesLoading,
|
||||||
isError,
|
isError: isNSApiNodesError,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: fetchObservatoryNodes,
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: epochRewardsData,
|
data: epochRewardsData,
|
||||||
isLoading: isEpochLoading,
|
isLoading: isEpochLoading,
|
||||||
@@ -177,19 +179,19 @@ export const NodeRoleCard = ({ paramId }: Props) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (paramId.length > 10) {
|
if (paramId.length > 10) {
|
||||||
nodeInfo = nymNodes?.find((node) => node.identity_key === paramId);
|
nodeInfo = nsApiNodes.find((node) => node.identity_key === paramId);
|
||||||
} else {
|
} else {
|
||||||
nodeInfo = nymNodes?.find((node) => node.node_id === Number(paramId));
|
nodeInfo = nsApiNodes.find((node) => node.node_id === Number(paramId));
|
||||||
} // Extract node roles once `nodeInfo` is available
|
} // Extract node roles once `nodeInfo` is available
|
||||||
const nodeRoles = nodeInfo
|
|
||||||
? getNodeRoles(nodeInfo.description.declared_role)
|
const nodeRoles = nodeInfo?.self_description
|
||||||
|
? getNodeRoles(nodeInfo.self_description.declared_role)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
// Define whether to fetch gateway status
|
// Define whether to fetch gateway status
|
||||||
const shouldFetchGatewayStatus = nodeRoles.some((role) =>
|
const shouldFetchGatewayStatus = nodeRoles.some((role) =>
|
||||||
["Entry Node", "Exit IPR Node", "Exit NR Node"].includes(role),
|
["Entry Node", "Exit IPR Node", "Exit NR Node"].includes(role)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fetch gateway status only if `shouldFetchGatewayStatus` is true
|
// Fetch gateway status only if `shouldFetchGatewayStatus` is true
|
||||||
const { data: gatewayStatus } = useQuery({
|
const { data: gatewayStatus } = useQuery({
|
||||||
queryKey: ["gatewayStatus", nodeInfo?.identity_key],
|
queryKey: ["gatewayStatus", nodeInfo?.identity_key],
|
||||||
@@ -200,7 +202,7 @@ export const NodeRoleCard = ({ paramId }: Props) => {
|
|||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoading || isEpochLoading) {
|
if (isNSApiNodesLoading || isEpochLoading) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Node role & performance">
|
<ExplorerCard label="Node role & performance">
|
||||||
<Skeleton variant="text" height={70} />
|
<Skeleton variant="text" height={70} />
|
||||||
@@ -210,15 +212,20 @@ export const NodeRoleCard = ({ paramId }: Props) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError || !nymNodes || !epochRewardsData || isEpochError) {
|
if (isNSApiNodesError || !nsApiNodes || !epochRewardsData || isEpochError) {
|
||||||
return (
|
return (
|
||||||
<ExplorerCard label="Node role & performance">
|
<ExplorerCard label="Node role & performance">
|
||||||
<Typography variant="h3" sx={{ color: "pine.950" }}>
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
sx={{ color: isDarkMode ? "base.white" : "pine.950" }}
|
||||||
|
>
|
||||||
Failed to load node data.
|
Failed to load node data.
|
||||||
</Typography>
|
</Typography>
|
||||||
</ExplorerCard>
|
</ExplorerCard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (!nodeInfo) return null;
|
||||||
|
|
||||||
|
|
||||||
const NodeRoles = nodeRoles.map((role) => (
|
const NodeRoles = nodeRoles.map((role) => (
|
||||||
<Stack key={role} direction="row" gap={1}>
|
<Stack key={role} direction="row" gap={1}>
|
||||||
@@ -226,8 +233,6 @@ export const NodeRoleCard = ({ paramId }: Props) => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
));
|
));
|
||||||
|
|
||||||
if (!nodeInfo) return null;
|
|
||||||
|
|
||||||
const qualityOfServiceStars = nodeInfo?.uptime
|
const qualityOfServiceStars = nodeInfo?.uptime
|
||||||
? calculateQualityOfServiceStars(nodeInfo.uptime)
|
? calculateQualityOfServiceStars(nodeInfo.uptime)
|
||||||
: gatewayStatus
|
: gatewayStatus
|
||||||
@@ -247,9 +252,10 @@ export const NodeRoleCard = ({ paramId }: Props) => {
|
|||||||
|
|
||||||
// Function to calculate active set probability
|
// Function to calculate active set probability
|
||||||
const getActiveSetProbability = (
|
const getActiveSetProbability = (
|
||||||
totalStake: number,
|
nodeTotalStake: string,
|
||||||
stakeSaturationPoint: string,
|
stakeSaturationPoint: string
|
||||||
): string => {
|
): string => {
|
||||||
|
const totalStake = Number.parseFloat(nodeTotalStake);
|
||||||
const saturation = Number.parseFloat(stakeSaturationPoint);
|
const saturation = Number.parseFloat(stakeSaturationPoint);
|
||||||
|
|
||||||
if (Number.isNaN(saturation) || saturation <= 0) {
|
if (Number.isNaN(saturation) || saturation <= 0) {
|
||||||
@@ -268,7 +274,7 @@ export const NodeRoleCard = ({ paramId }: Props) => {
|
|||||||
};
|
};
|
||||||
const activeSetProb = getActiveSetProbability(
|
const activeSetProb = getActiveSetProbability(
|
||||||
nodeInfo.total_stake,
|
nodeInfo.total_stake,
|
||||||
epochRewardsData.interval.stake_saturation_point,
|
epochRewardsData.interval.stake_saturation_point
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import type { IObservatoryNode } from "@/app/api/types";
|
import type { NS_NODE } from "@/app/api/types";
|
||||||
|
import { NYM_ACCOUNT_ADDRESS } from "@/app/api/urls";
|
||||||
import { Search } from "@mui/icons-material";
|
import { Search } from "@mui/icons-material";
|
||||||
import {
|
import {
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
@@ -12,22 +13,22 @@ import {
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { fetchObservatoryNodes } from "../../app/api";
|
import { fetchNSApiNodes } from "../../app/api";
|
||||||
import { NYM_ACCOUNT_ADDRESS } from "@/app/api/urls";
|
|
||||||
|
|
||||||
const NodeAndAddressSearch = () => {
|
const NodeAndAddressSearch = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
const [errorText, setErrorText] = useState("");
|
const [errorText, setErrorText] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [searchOptions, setSearchOptions] = useState<IObservatoryNode[]>([]);
|
const [searchOptions, setSearchOptions] = useState<NS_NODE[]>([]);
|
||||||
|
|
||||||
// Use React Query to fetch nodes
|
// Use React Query to fetch nodes
|
||||||
const { data: nymNodes = [], isLoading: isLoadingNodes } = useQuery({
|
|
||||||
queryKey: ["nymNodes"],
|
const { data: nsApiNodes = [], isLoading: isNSApiNodesLoading } = useQuery({
|
||||||
queryFn: fetchObservatoryNodes,
|
queryKey: ["nsApiNodes"],
|
||||||
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
@@ -66,9 +67,9 @@ const NodeAndAddressSearch = () => {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check if it's a node identity key
|
// Check if it's a node identity key
|
||||||
if (nymNodes) {
|
if (nsApiNodes) {
|
||||||
const matchingNode = nymNodes.find(
|
const matchingNode = nsApiNodes.find(
|
||||||
(node) => node.identity_key === inputValue
|
(node: NS_NODE) => node.identity_key === inputValue
|
||||||
);
|
);
|
||||||
|
|
||||||
if (matchingNode) {
|
if (matchingNode) {
|
||||||
@@ -104,10 +105,8 @@ const NodeAndAddressSearch = () => {
|
|||||||
|
|
||||||
// Filter nodes by moniker if input is not empty
|
// Filter nodes by moniker if input is not empty
|
||||||
if (value.trim() !== "") {
|
if (value.trim() !== "") {
|
||||||
const filteredNodes = nymNodes.filter((node) =>
|
const filteredNodes = nsApiNodes.filter((node: NS_NODE) =>
|
||||||
node.self_description?.moniker
|
node.description.moniker?.toLowerCase().includes(value.toLowerCase())
|
||||||
?.toLowerCase()
|
|
||||||
.includes(value.toLowerCase())
|
|
||||||
);
|
);
|
||||||
setSearchOptions(filteredNodes);
|
setSearchOptions(filteredNodes);
|
||||||
} else {
|
} else {
|
||||||
@@ -118,7 +117,7 @@ const NodeAndAddressSearch = () => {
|
|||||||
// Handle node selection from dropdown
|
// Handle node selection from dropdown
|
||||||
const handleNodeSelect = (
|
const handleNodeSelect = (
|
||||||
event: React.SyntheticEvent,
|
event: React.SyntheticEvent,
|
||||||
value: string | IObservatoryNode | null
|
value: string | NS_NODE | null
|
||||||
) => {
|
) => {
|
||||||
if (value && typeof value !== "string") {
|
if (value && typeof value !== "string") {
|
||||||
setIsLoading(true); // Show loading spinner
|
setIsLoading(true); // Show loading spinner
|
||||||
@@ -132,9 +131,9 @@ const NodeAndAddressSearch = () => {
|
|||||||
<Autocomplete
|
<Autocomplete
|
||||||
freeSolo
|
freeSolo
|
||||||
options={searchOptions}
|
options={searchOptions}
|
||||||
getOptionLabel={(option: string | IObservatoryNode) => {
|
getOptionLabel={(option: string | NS_NODE) => {
|
||||||
if (typeof option === "string") return option;
|
if (typeof option === "string") return option;
|
||||||
return option.self_description?.moniker || "";
|
return option.description.moniker || "";
|
||||||
}}
|
}}
|
||||||
isOptionEqualToValue={(option, value) => {
|
isOptionEqualToValue={(option, value) => {
|
||||||
if (typeof option === "string" || typeof value === "string")
|
if (typeof option === "string" || typeof value === "string")
|
||||||
@@ -146,10 +145,10 @@ const NodeAndAddressSearch = () => {
|
|||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
{...props}
|
{...props}
|
||||||
key={`${option.node_id}-${option.self_description?.moniker || ""}`}
|
key={`${option.node_id}-${option.description.moniker || ""}`}
|
||||||
style={{ fontSize: "0.875rem" }}
|
style={{ fontSize: "0.875rem" }}
|
||||||
>
|
>
|
||||||
{option.self_description?.moniker || "Unnamed Node"}
|
{option.description.moniker || "Unnamed Node"}
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
@@ -182,7 +181,7 @@ const NodeAndAddressSearch = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
onChange={handleNodeSelect}
|
onChange={handleNodeSelect}
|
||||||
loading={isLoadingNodes}
|
loading={isNSApiNodesLoading}
|
||||||
loadingText="Loading nodes..."
|
loadingText="Loading nodes..."
|
||||||
noOptionsText="No nodes found"
|
noOptionsText="No nodes found"
|
||||||
slotProps={{
|
slotProps={{
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import StakeModal from "./StakeModal";
|
|||||||
import type { MappedNymNode, MappedNymNodes } from "./StakeTableWithAction";
|
import type { MappedNymNode, MappedNymNodes } from "./StakeTableWithAction";
|
||||||
import { fee } from "./schemas";
|
import { fee } from "./schemas";
|
||||||
|
|
||||||
|
|
||||||
type DelegationWithNodeDetails = {
|
type DelegationWithNodeDetails = {
|
||||||
node: MappedNymNode | undefined;
|
node: MappedNymNode | undefined;
|
||||||
delegation: Delegation;
|
delegation: Delegation;
|
||||||
|
|||||||
@@ -3,15 +3,15 @@
|
|||||||
import { Card, CardContent, Skeleton, Stack, Typography } from "@mui/material";
|
import { Card, CardContent, Skeleton, Stack, Typography } from "@mui/material";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import DOMPurify from "isomorphic-dompurify";
|
import DOMPurify from "isomorphic-dompurify";
|
||||||
import { fetchEpochRewards, fetchObservatoryNodes } from "../../app/api";
|
import { fetchEpochRewards, fetchNSApiNodes } from "../../app/api";
|
||||||
import type { ExplorerData, IObservatoryNode } from "../../app/api/types";
|
import type { ExplorerData, NS_NODE } from "../../app/api/types";
|
||||||
import { countryName } from "../../utils/countryName";
|
import { countryName } from "../../utils/countryName";
|
||||||
import StakeTable from "./StakeTable";
|
import StakeTable from "./StakeTable";
|
||||||
|
|
||||||
// Utility function to calculate node saturation point
|
// Utility function to calculate node saturation point
|
||||||
function getNodeSaturationPoint(
|
function getNodeSaturationPoint(
|
||||||
totalStake: number,
|
totalStake: number,
|
||||||
stakeSaturationPoint: string,
|
stakeSaturationPoint: string
|
||||||
): number {
|
): number {
|
||||||
const saturation = Number.parseFloat(stakeSaturationPoint);
|
const saturation = Number.parseFloat(stakeSaturationPoint);
|
||||||
|
|
||||||
@@ -24,35 +24,46 @@ function getNodeSaturationPoint(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Map nodes with rewards data
|
// Map nodes with rewards data
|
||||||
const mappedNymNodes = (
|
const mappedNSApiNodes = (
|
||||||
nodes: IObservatoryNode[],
|
nodes: NS_NODE[],
|
||||||
epochRewardsData: ExplorerData["currentEpochRewardsData"],
|
epochRewardsData: ExplorerData["currentEpochRewardsData"]
|
||||||
) =>
|
) =>
|
||||||
nodes.map((node) => {
|
nodes
|
||||||
const nodeSaturationPoint = getNodeSaturationPoint(
|
.map((node) => {
|
||||||
node.total_stake,
|
const nodeSaturationPoint = getNodeSaturationPoint(
|
||||||
epochRewardsData.interval.stake_saturation_point,
|
+node.total_stake,
|
||||||
);
|
epochRewardsData.interval.stake_saturation_point
|
||||||
|
);
|
||||||
|
|
||||||
const cleanMoniker = DOMPurify.sanitize(
|
const cleanMoniker = DOMPurify.sanitize(node.description.moniker).replace(
|
||||||
node.self_description.moniker,
|
/&/g,
|
||||||
).replace(/&/g, "&");
|
"&"
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: cleanMoniker,
|
name: cleanMoniker,
|
||||||
nodeId: node.node_id,
|
nodeId: node.node_id,
|
||||||
identity_key: node.identity_key,
|
identity_key: node.identity_key,
|
||||||
countryCode: node.description.auxiliary_details.location || null,
|
countryCode: node.geoip?.country || null,
|
||||||
countryName:
|
countryName: countryName(node.geoip?.country || null) || null,
|
||||||
countryName(node.description.auxiliary_details.location) || null,
|
profitMarginPercentage: node.rewarding_details
|
||||||
profitMarginPercentage:
|
? +node.rewarding_details.cost_params.profit_margin_percent * 100
|
||||||
+node.rewarding_details.cost_params.profit_margin_percent * 100,
|
: 0,
|
||||||
owner: node.bonding_address,
|
owner: node.bonding_address,
|
||||||
stakeSaturation: +nodeSaturationPoint || 0,
|
stakeSaturation: nodeSaturationPoint,
|
||||||
};
|
};
|
||||||
});
|
})
|
||||||
|
.sort((a, b) => {
|
||||||
|
// Handle null country names by putting them at the end
|
||||||
|
if (!a.countryName && !b.countryName) return 0;
|
||||||
|
if (!a.countryName) return 1;
|
||||||
|
if (!b.countryName) return -1;
|
||||||
|
|
||||||
export type MappedNymNodes = ReturnType<typeof mappedNymNodes>;
|
// Sort alphabetically by country name
|
||||||
|
return a.countryName.localeCompare(b.countryName);
|
||||||
|
});
|
||||||
|
|
||||||
|
export type MappedNymNodes = ReturnType<typeof mappedNSApiNodes>;
|
||||||
export type MappedNymNode = MappedNymNodes[0];
|
export type MappedNymNode = MappedNymNodes[0];
|
||||||
|
|
||||||
const StakeTableWithAction = () => {
|
const StakeTableWithAction = () => {
|
||||||
@@ -72,12 +83,12 @@ const StakeTableWithAction = () => {
|
|||||||
|
|
||||||
// Use React Query to fetch Nym nodes
|
// Use React Query to fetch Nym nodes
|
||||||
const {
|
const {
|
||||||
data: nymNodes = [],
|
data: nsApiNodes = [],
|
||||||
isLoading: isNodesLoading,
|
isLoading: isNSApiNodesLoading,
|
||||||
isError: isNodesError,
|
isError: isNSApiNodesError,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["nymNodes"],
|
queryKey: ["nsApiNodes"],
|
||||||
queryFn: fetchObservatoryNodes,
|
queryFn: fetchNSApiNodes,
|
||||||
staleTime: 10 * 60 * 1000, // 10 minutes
|
staleTime: 10 * 60 * 1000, // 10 minutes
|
||||||
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
refetchOnWindowFocus: false, // Prevents unnecessary refetching
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
@@ -85,7 +96,7 @@ const StakeTableWithAction = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Handle loading state
|
// Handle loading state
|
||||||
if (isEpochLoading || isNodesLoading) {
|
if (isEpochLoading || isNSApiNodesLoading) {
|
||||||
return (
|
return (
|
||||||
<Card sx={{ height: "100%", mt: 5 }}>
|
<Card sx={{ height: "100%", mt: 5 }}>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
@@ -99,7 +110,7 @@ const StakeTableWithAction = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle error state
|
// Handle error state
|
||||||
if (isEpochError || isNodesError) {
|
if (isEpochError || isNSApiNodesError) {
|
||||||
return (
|
return (
|
||||||
<Stack direction="row" spacing={1}>
|
<Stack direction="row" spacing={1}>
|
||||||
<Typography variant="h5" sx={{ color: "pine.600", letterSpacing: 0.7 }}>
|
<Typography variant="h5" sx={{ color: "pine.600", letterSpacing: 0.7 }}>
|
||||||
@@ -115,9 +126,9 @@ const StakeTableWithAction = () => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = mappedNymNodes(nymNodes || [], epochRewardsData);
|
const nsApiNodesData = mappedNSApiNodes(nsApiNodes || [], epochRewardsData);
|
||||||
|
|
||||||
return <StakeTable nodes={data} />;
|
return <StakeTable nodes={nsApiNodesData} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default StakeTableWithAction;
|
export default StakeTableWithAction;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import type { Delegation } from "@nymproject/contract-clients/Mixnet.types";
|
|||||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import { fetchTotalStakerRewards } from "../../app/api";
|
import { fetchTotalStakerRewards } from "../../app/api";
|
||||||
import type { NodeRewardDetails } from "../../app/api/types";
|
|
||||||
import { COSMOS_KIT_USE_CHAIN, NYM_MIXNET_CONTRACT } from "../../config";
|
import { COSMOS_KIT_USE_CHAIN, NYM_MIXNET_CONTRACT } from "../../config";
|
||||||
import { useNymClient } from "../../hooks/useNymClient";
|
import { useNymClient } from "../../hooks/useNymClient";
|
||||||
import Loading from "../loading";
|
import Loading from "../loading";
|
||||||
@@ -19,7 +18,7 @@ import RedeemRewardsModal from "../redeemRewards/RedeemRewardsModal";
|
|||||||
const fetchDelegations = async (
|
const fetchDelegations = async (
|
||||||
address: string,
|
address: string,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
nymClient: any,
|
nymClient: any
|
||||||
): Promise<Delegation[]> => {
|
): Promise<Delegation[]> => {
|
||||||
const data = await nymClient.getDelegatorDelegations({ delegator: address });
|
const data = await nymClient.getDelegatorDelegations({ delegator: address });
|
||||||
return data.delegations;
|
return data.delegations;
|
||||||
@@ -84,10 +83,10 @@ const SubHeaderRowActions = () => {
|
|||||||
const client = await SigningCosmWasmClient.connectWithSigner(
|
const client = await SigningCosmWasmClient.connectWithSigner(
|
||||||
"https://rpc.nymtech.net/",
|
"https://rpc.nymtech.net/",
|
||||||
signer,
|
signer,
|
||||||
{ gasPrice },
|
{ gasPrice }
|
||||||
);
|
);
|
||||||
|
|
||||||
const messages = delegations.map((delegation: NodeRewardDetails) => ({
|
const messages = delegations.map((delegation: Delegation) => ({
|
||||||
contractAddress: NYM_MIXNET_CONTRACT,
|
contractAddress: NYM_MIXNET_CONTRACT,
|
||||||
funds: [],
|
funds: [],
|
||||||
msg: {
|
msg: {
|
||||||
@@ -101,7 +100,7 @@ const SubHeaderRowActions = () => {
|
|||||||
address,
|
address,
|
||||||
messages,
|
messages,
|
||||||
"auto",
|
"auto",
|
||||||
"Redeeming all rewards",
|
"Redeeming all rewards"
|
||||||
);
|
);
|
||||||
// Success state
|
// Success state
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
"use client";
|
||||||
|
import { Button, ButtonGroup, Stack } from "@mui/material";
|
||||||
|
|
||||||
|
type Option = {
|
||||||
|
label: string;
|
||||||
|
isSelected: boolean;
|
||||||
|
value: "all" | "mixnodes" | "gateways" | "recommended";
|
||||||
|
};
|
||||||
|
|
||||||
|
type Options = [Option, Option, Option, Option];
|
||||||
|
|
||||||
|
const NodeFilterButtonGroup = ({
|
||||||
|
size = "small",
|
||||||
|
options,
|
||||||
|
onPage,
|
||||||
|
onFilterChange,
|
||||||
|
}: {
|
||||||
|
size?: "small" | "medium" | "large";
|
||||||
|
options: Options;
|
||||||
|
onPage: string;
|
||||||
|
onFilterChange: (
|
||||||
|
filter: "all" | "mixnodes" | "gateways" | "recommended"
|
||||||
|
) => void;
|
||||||
|
}) => {
|
||||||
|
const handleClick = (
|
||||||
|
value: "all" | "mixnodes" | "gateways" | "recommended"
|
||||||
|
) => {
|
||||||
|
if (onPage === value) return;
|
||||||
|
onFilterChange(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMobileButtonStyles = (isSelected: boolean) => ({
|
||||||
|
color: isSelected ? "primary.contrastText" : "text.primary",
|
||||||
|
"&:hover": {
|
||||||
|
bgcolor: isSelected ? "primary.main" : "",
|
||||||
|
},
|
||||||
|
bgcolor: isSelected ? "primary.main" : "transparent",
|
||||||
|
width: "100%",
|
||||||
|
py: 1.5,
|
||||||
|
px: 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
const getDesktopButtonStyles = (isSelected: boolean) => ({
|
||||||
|
color: isSelected ? "primary.contrastText" : "text.primary",
|
||||||
|
"&:hover": {
|
||||||
|
bgcolor: isSelected ? "primary.main" : "",
|
||||||
|
},
|
||||||
|
bgcolor: isSelected ? "primary.main" : "transparent",
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{/* Mobile view - Stack */}
|
||||||
|
<Stack
|
||||||
|
spacing={1.5}
|
||||||
|
sx={{
|
||||||
|
display: { xs: "flex", sm: "none" },
|
||||||
|
width: "100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{options.map((option) => (
|
||||||
|
<Button
|
||||||
|
key={option.label}
|
||||||
|
onClick={() => handleClick(option.value)}
|
||||||
|
sx={getMobileButtonStyles(option.isSelected)}
|
||||||
|
variant="outlined"
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
{/* Desktop view - ButtonGroup */}
|
||||||
|
<ButtonGroup size={size} sx={{ display: { xs: "none", sm: "flex" } }}>
|
||||||
|
{options.map((option) => (
|
||||||
|
<Button
|
||||||
|
key={option.label}
|
||||||
|
onClick={() => handleClick(option.value)}
|
||||||
|
sx={getDesktopButtonStyles(option.isSelected)}
|
||||||
|
variant="outlined"
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
</ButtonGroup>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NodeFilterButtonGroup;
|
||||||
@@ -0,0 +1,406 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { scaleLinear } from "d3-scale";
|
||||||
|
import * as React from "react";
|
||||||
|
import Image from "next/image";
|
||||||
|
import {
|
||||||
|
ComposableMap,
|
||||||
|
Geographies,
|
||||||
|
Geography,
|
||||||
|
ZoomableGroup,
|
||||||
|
} from "react-simple-maps";
|
||||||
|
import { Tooltip } from "react-tooltip";
|
||||||
|
import { fetchWorldMapCountries } from "@/app/api";
|
||||||
|
import AddIcon from "@mui/icons-material/Add";
|
||||||
|
import RemoveIcon from "@mui/icons-material/Remove";
|
||||||
|
import RestartAltIcon from "@mui/icons-material/RestartAlt";
|
||||||
|
import { IconButton, Skeleton, Typography, Box } from "@mui/material";
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import type { CountryDataResponse } from "../../app/api/types";
|
||||||
|
import MAP_TOPOJSON from "../../assets/world-110m.json";
|
||||||
|
import ExplorerCard from "../cards/ExplorerCard";
|
||||||
|
|
||||||
|
const mapPlaceholderDark = "/explorer/map-placeholder-dark.png";
|
||||||
|
const mapPlaceholderLight = "/explorer/map-placeholder-light.png";
|
||||||
|
|
||||||
|
export const WorldMap = (): JSX.Element => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const isDarkMode = theme.palette.mode === "dark";
|
||||||
|
const [position, setPosition] = React.useState<{
|
||||||
|
coordinates: [number, number];
|
||||||
|
zoom: number;
|
||||||
|
}>({ coordinates: [0, 0], zoom: 1 });
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: {
|
||||||
|
countries = [],
|
||||||
|
totalCountries = 0,
|
||||||
|
uniqueLocations = 0,
|
||||||
|
totalServers = 0,
|
||||||
|
} = {
|
||||||
|
countries: [],
|
||||||
|
totalCountries: 0,
|
||||||
|
uniqueLocations: 0,
|
||||||
|
totalServers: 0,
|
||||||
|
},
|
||||||
|
isLoading: isLoadingCountries,
|
||||||
|
isError: isCountriesError,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["nymNodesCountries"],
|
||||||
|
queryFn: fetchWorldMapCountries,
|
||||||
|
staleTime: 60 * 60 * 1000, // 1 hour
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnReconnect: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [tooltipContent, setTooltipContent] = React.useState<string>("");
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const handleMouseLeave = () => setTooltipContent("");
|
||||||
|
return () => {
|
||||||
|
handleMouseLeave();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const colorScale = React.useMemo(() => {
|
||||||
|
if (countries) {
|
||||||
|
const heighestNumberOfNodes = Math.max(
|
||||||
|
...Object.values(countries).map((country) => country.nodes)
|
||||||
|
);
|
||||||
|
return scaleLinear<string, string>()
|
||||||
|
.domain([
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
heighestNumberOfNodes / 4,
|
||||||
|
heighestNumberOfNodes / 2,
|
||||||
|
heighestNumberOfNodes,
|
||||||
|
])
|
||||||
|
.range(
|
||||||
|
isDarkMode
|
||||||
|
? [
|
||||||
|
theme.palette.pine[950],
|
||||||
|
"#0F5A2E", // Dark green
|
||||||
|
"#147A3D", // Medium green
|
||||||
|
"#1A994C", // Light green
|
||||||
|
theme.palette.accent.main,
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
theme.palette.pine[300],
|
||||||
|
"#0F5A2E", // Dark green
|
||||||
|
"#147A3D", // Medium green
|
||||||
|
"#1A994C", // Light green
|
||||||
|
theme.palette.accent.main,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
.unknown(isDarkMode ? theme.palette.pine[950] : theme.palette.pine[25]);
|
||||||
|
}
|
||||||
|
return () =>
|
||||||
|
isDarkMode ? theme.palette.pine[950] : theme.palette.pine[25];
|
||||||
|
}, [countries, theme.palette.pine, theme.palette.accent, isDarkMode]);
|
||||||
|
|
||||||
|
if (isLoadingCountries) {
|
||||||
|
return (
|
||||||
|
<ExplorerCard label="Nym server locations" sx={{ width: "100%" }}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "relative",
|
||||||
|
width: "100%",
|
||||||
|
aspectRatio: "16/7",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
src={isDarkMode ? mapPlaceholderDark : mapPlaceholderLight}
|
||||||
|
alt="World Map Placeholder"
|
||||||
|
fill
|
||||||
|
style={{ objectFit: "contain" }}
|
||||||
|
priority
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ExplorerCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCountriesError) {
|
||||||
|
return (
|
||||||
|
<ExplorerCard label="Nym server locations" sx={{ width: "100%" }}>
|
||||||
|
<Typography
|
||||||
|
variant="h5"
|
||||||
|
sx={{
|
||||||
|
color: isDarkMode ? "base.white" : "pine.950",
|
||||||
|
letterSpacing: 0.7,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Failed to load data
|
||||||
|
</Typography>
|
||||||
|
<Skeleton variant="text" height={500} />
|
||||||
|
</ExplorerCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ExplorerCard
|
||||||
|
label="Nym server locations"
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
position: "relative",
|
||||||
|
p: { xs: 2, sm: 3 },
|
||||||
|
"& > .MuiCardContent-root": {
|
||||||
|
height: {
|
||||||
|
xs: "200px",
|
||||||
|
sm: "auto",
|
||||||
|
},
|
||||||
|
aspectRatio: {
|
||||||
|
xs: "unset",
|
||||||
|
sm: "16/7",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
position: "relative",
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
overflow: "hidden",
|
||||||
|
margin: "0 auto",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ComposableMap
|
||||||
|
data-tip=""
|
||||||
|
style={{
|
||||||
|
backgroundColor: isDarkMode ? "#000000" : theme.palette.pine[25],
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
}}
|
||||||
|
viewBox="0 0 800 400"
|
||||||
|
projection="geoMercator"
|
||||||
|
projectionConfig={{
|
||||||
|
scale: 130,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ZoomableGroup
|
||||||
|
center={position.coordinates}
|
||||||
|
zoom={position.zoom}
|
||||||
|
minZoom={1}
|
||||||
|
maxZoom={8}
|
||||||
|
translateExtent={[
|
||||||
|
[-800, -400],
|
||||||
|
[800, 400],
|
||||||
|
]}
|
||||||
|
onMoveEnd={({
|
||||||
|
coordinates,
|
||||||
|
zoom,
|
||||||
|
}: {
|
||||||
|
coordinates: [number, number];
|
||||||
|
zoom: number;
|
||||||
|
}) => {
|
||||||
|
setPosition({ coordinates, zoom });
|
||||||
|
}}
|
||||||
|
onClick={(e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Geographies geography={MAP_TOPOJSON}>
|
||||||
|
{({ geographies }: { geographies: GeoJSON.Feature[] }) =>
|
||||||
|
geographies.map((geo) => {
|
||||||
|
const d = Array.isArray(countries)
|
||||||
|
? { nodes: 0 }
|
||||||
|
: (countries as CountryDataResponse)[
|
||||||
|
geo.properties?.ISO_A3 as string
|
||||||
|
] || { nodes: 0 };
|
||||||
|
return (
|
||||||
|
<Geography
|
||||||
|
key={`${geo.properties?.ISO_A3 || ""}-${geo.id}-${
|
||||||
|
geo.properties?.NAME_LONG || ""
|
||||||
|
}`}
|
||||||
|
geography={geo}
|
||||||
|
fill={colorScale(d?.nodes || 0)}
|
||||||
|
stroke={
|
||||||
|
theme.palette.mode === "dark"
|
||||||
|
? theme.palette.pine[800]
|
||||||
|
: theme.palette.pine[200]
|
||||||
|
}
|
||||||
|
strokeWidth={0.2}
|
||||||
|
data-tooltip-id="map-tooltip"
|
||||||
|
onMouseEnter={() => {
|
||||||
|
const { NAME_LONG } = geo.properties as {
|
||||||
|
NAME_LONG: string;
|
||||||
|
};
|
||||||
|
setTooltipContent(`${NAME_LONG} | ${d?.nodes || 0}`);
|
||||||
|
}}
|
||||||
|
onMouseLeave={() => {
|
||||||
|
setTooltipContent("");
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
hover: countries
|
||||||
|
? {
|
||||||
|
fill: theme.palette.accent.main,
|
||||||
|
outline: "white",
|
||||||
|
cursor: "pointer",
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
default: {
|
||||||
|
outline: "none",
|
||||||
|
},
|
||||||
|
pressed: {
|
||||||
|
outline: "none",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</Geographies>
|
||||||
|
</ZoomableGroup>
|
||||||
|
</ComposableMap>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
top: 10,
|
||||||
|
left: 10,
|
||||||
|
zIndex: 1000,
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
gap: "4px",
|
||||||
|
backgroundColor: isDarkMode
|
||||||
|
? "rgba(0,0,0,0.5)"
|
||||||
|
: "rgba(255,255,255,0.5)",
|
||||||
|
padding: "4px",
|
||||||
|
borderRadius: "4px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
onClick={() =>
|
||||||
|
setPosition((prev) => ({
|
||||||
|
...prev,
|
||||||
|
zoom: Math.min(prev.zoom + 0.5, 8),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
sx={{
|
||||||
|
backgroundColor: isDarkMode
|
||||||
|
? "rgba(255,255,255,0.1)"
|
||||||
|
: "rgba(0,0,0,0.1)",
|
||||||
|
"&:hover": {
|
||||||
|
backgroundColor: isDarkMode
|
||||||
|
? "rgba(255,255,255,0.2)"
|
||||||
|
: "rgba(0,0,0,0.2)",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<AddIcon fontSize="small" />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
onClick={() =>
|
||||||
|
setPosition((prev) => ({
|
||||||
|
...prev,
|
||||||
|
zoom: Math.max(prev.zoom - 0.5, 1),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
sx={{
|
||||||
|
backgroundColor: isDarkMode
|
||||||
|
? "rgba(255,255,255,0.1)"
|
||||||
|
: "rgba(0,0,0,0.1)",
|
||||||
|
"&:hover": {
|
||||||
|
backgroundColor: isDarkMode
|
||||||
|
? "rgba(255,255,255,0.2)"
|
||||||
|
: "rgba(0,0,0,0.2)",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<RemoveIcon fontSize="small" />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
onClick={() => setPosition({ coordinates: [0, 0], zoom: 1 })}
|
||||||
|
sx={{
|
||||||
|
backgroundColor: isDarkMode
|
||||||
|
? "rgba(255,255,255,0.1)"
|
||||||
|
: "rgba(0,0,0,0.1)",
|
||||||
|
"&:hover": {
|
||||||
|
backgroundColor: isDarkMode
|
||||||
|
? "rgba(255,255,255,0.2)"
|
||||||
|
: "rgba(0,0,0,0.2)",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<RestartAltIcon fontSize="small" />
|
||||||
|
</IconButton>
|
||||||
|
</div>
|
||||||
|
</Box>
|
||||||
|
<Tooltip
|
||||||
|
id="map-tooltip"
|
||||||
|
content={tooltipContent}
|
||||||
|
float={true}
|
||||||
|
style={{
|
||||||
|
fontSize: "12px",
|
||||||
|
padding: "4px 8px",
|
||||||
|
backgroundColor:
|
||||||
|
theme.palette.mode === "dark"
|
||||||
|
? theme.palette.pine[800]
|
||||||
|
: theme.palette.pine[200],
|
||||||
|
color:
|
||||||
|
theme.palette.mode === "dark"
|
||||||
|
? theme.palette.base.white
|
||||||
|
: theme.palette.pine[950],
|
||||||
|
borderRadius: "4px",
|
||||||
|
zIndex: 9999,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ExplorerCard>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "grid",
|
||||||
|
gridTemplateColumns: {
|
||||||
|
xs: "1fr",
|
||||||
|
sm: "repeat(3, 1fr)",
|
||||||
|
},
|
||||||
|
gap: 2,
|
||||||
|
mt: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ExplorerCard label="Nym servers around the world">
|
||||||
|
<Typography
|
||||||
|
variant="h4"
|
||||||
|
sx={{
|
||||||
|
color: isDarkMode ? "base.white" : "pine.950",
|
||||||
|
letterSpacing: 0.7,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{totalServers}
|
||||||
|
</Typography>
|
||||||
|
</ExplorerCard>
|
||||||
|
<ExplorerCard label="Countries with Nym servers">
|
||||||
|
<Typography
|
||||||
|
variant="h4"
|
||||||
|
sx={{
|
||||||
|
color: isDarkMode ? "base.white" : "pine.950",
|
||||||
|
letterSpacing: 0.7,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{totalCountries}
|
||||||
|
</Typography>
|
||||||
|
</ExplorerCard>
|
||||||
|
<ExplorerCard label="Nym Server Locations">
|
||||||
|
<Typography
|
||||||
|
variant="h4"
|
||||||
|
sx={{
|
||||||
|
color: isDarkMode ? "base.white" : "pine.950",
|
||||||
|
letterSpacing: 0.7,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{uniqueLocations}
|
||||||
|
</Typography>
|
||||||
|
</ExplorerCard>
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
"iconLight": "explorerCard",
|
"iconLight": "explorerCard",
|
||||||
"iconDark": "explorerCardDark",
|
"iconDark": "explorerCardDark",
|
||||||
"image": "/explorer/images/Network.webp",
|
"image": "/explorer/images/Network.webp",
|
||||||
|
"link": "https://nym.com/blog/welcome-to-explorer",
|
||||||
"overview": {
|
"overview": {
|
||||||
"content": [
|
"content": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"iconLight": "stakeCard",
|
"iconLight": "stakeCard",
|
||||||
"iconDark": "stakeCardDark",
|
"iconDark": "stakeCardDark",
|
||||||
"image": "/explorer/images/stake-article.webp",
|
"image": "/explorer/images/stake-article.webp",
|
||||||
|
"link": "https://nym.com/blog/stake-Nym-tokens",
|
||||||
"overview": {
|
"overview": {
|
||||||
"content": [
|
"content": [
|
||||||
{
|
{
|
||||||
|
|||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
declare module "*.json" {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const content: any;
|
||||||
|
export default content;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
declare module "react-simple-maps";
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
declare module 'react-tooltip';
|
||||||
Reference in New Issue
Block a user