finish next-explorer build

This commit is contained in:
fmtabbara
2024-07-01 11:02:46 +01:00
parent 6fcdbc15ce
commit cd2978a8b0
2 changed files with 75 additions and 39 deletions
+56 -37
View File
@@ -1,19 +1,21 @@
/* eslint-disable camelcase */
import { MutableRefObject } from 'react';
import { Theme } from '@mui/material/styles';
import { registerLocale, getName } from 'i18n-iso-countries';
import Big from 'big.js';
import { CountryData } from '@/app/typeDefs/explorer-api';
import { EconomicsRowsType } from '@/app/components/MixNodes/Economics/types';
import { Network } from '../typeDefs/network';
import { MutableRefObject } from "react";
import { Theme } from "@mui/material/styles";
import { registerLocale, getName } from "i18n-iso-countries";
import Big from "big.js";
import { CountryData } from "@/app/typeDefs/explorer-api";
import { EconomicsRowsType } from "@/app/components/MixNodes/Economics/types";
import { Network } from "../typeDefs/network";
registerLocale(require('i18n-iso-countries/langs/en.json'));
registerLocale(require("i18n-iso-countries/langs/en.json"));
export function formatNumber(num: number): string {
return new Intl.NumberFormat().format(num);
}
export function scrollToRef(ref: MutableRefObject<HTMLDivElement | undefined>): void {
export function scrollToRef(
ref: MutableRefObject<HTMLDivElement | undefined>
): void {
if (ref?.current) ref.current.scrollIntoView();
}
@@ -25,13 +27,15 @@ export type CountryDataRowType = {
percentage: string;
};
export function countryDataToGridRow(countriesData: CountryData[]): CountryDataRowType[] {
export function countryDataToGridRow(
countriesData: CountryData[]
): CountryDataRowType[] {
const totalNodes = countriesData.reduce((acc, obj) => acc + obj.nodes, 0);
const formatted = countriesData.map((each: CountryData, index: number) => {
const updatedCountryRecord: CountryDataRowType = {
...each,
id: index,
countryName: getName(each.ISO3, 'en', { select: 'alias' }),
countryName: getName(each.ISO3, "en", { select: "alias" }) || "",
percentage: ((each.nodes * 100) / totalNodes).toFixed(1),
};
return updatedCountryRecord;
@@ -41,16 +45,21 @@ export function countryDataToGridRow(countriesData: CountryData[]): CountryDataR
return sorted;
}
export const splice = (start: number, deleteCount: number, address?: string): string => {
export const splice = (
start: number,
deleteCount: number,
address?: string
): string => {
if (address) {
const array = address.split('');
array.splice(start, deleteCount, '...');
return array.join('');
const array = address.split("");
array.splice(start, deleteCount, "...");
return array.join("");
}
return '';
return "";
};
export const trimAddress = (address = '', trimBy = 6) => `${address.slice(0, trimBy)}...${address.slice(-trimBy)}`;
export const trimAddress = (address = "", trimBy = 6) =>
`${address.slice(0, trimBy)}...${address.slice(-trimBy)}`;
/**
* Converts a stringified percentage float (0.0-1.0) to a stringified integer (0-100).
@@ -58,27 +67,33 @@ export const trimAddress = (address = '', trimBy = 6) => `${address.slice(0, tri
* @param value - the percentage to convert
* @returns A stringified integer
*/
export const toPercentIntegerString = (value: string) => Math.round(Number(value) * 100).toString();
export const toPercentInteger = (value: string) => Math.round(Number(value) * 100);
export const toPercentIntegerString = (value: string) =>
Math.round(Number(value) * 100).toString();
export const toPercentInteger = (value: string) =>
Math.round(Number(value) * 100);
export const textColour = (value: EconomicsRowsType, field: string, theme: Theme) => {
export const textColour = (
value: EconomicsRowsType,
field: string,
theme: Theme
) => {
const progressBarValue = value?.progressBarValue || 0;
const fieldValue = value.value;
if (progressBarValue > 100) {
return theme.palette.warning.main;
}
if (field === 'selectionChance') {
if (field === "selectionChance") {
// TODO: when v2 will be deployed, remove cases: VeryHigh, Moderate and VeryLow
switch (fieldValue) {
case 'High':
case 'VeryHigh':
case "High":
case "VeryHigh":
return theme.palette.nym.networkExplorer.selectionChance.overModerate;
case 'Good':
case 'Moderate':
case "Good":
case "Moderate":
return theme.palette.nym.networkExplorer.selectionChance.moderate;
case 'Low':
case 'VeryLow':
case "Low":
case "VeryLow":
return theme.palette.nym.networkExplorer.selectionChance.underModerate;
default:
return theme.palette.nym.wallet.fee;
@@ -101,8 +116,12 @@ export const isLessThan = (a: number, b: number) => a < b;
*
*/
export const isBalanceEnough = (fee: string, tx: string = '0', balance: string = '0') => {
console.log('balance', balance, fee, tx);
export const isBalanceEnough = (
fee: string,
tx: string = "0",
balance: string = "0"
) => {
console.log("balance", balance, fee, tx);
try {
return Big(balance).gte(Big(fee).plus(Big(tx)));
} catch (e) {
@@ -112,13 +131,13 @@ export const isBalanceEnough = (fee: string, tx: string = '0', balance: string =
};
export const urls = (networkName?: Network) =>
networkName === 'MAINNET'
networkName === "MAINNET"
? {
mixnetExplorer: 'https://mixnet.explorers.guru/',
blockExplorer: 'https://blocks.nymtech.net',
networkExplorer: 'https://explorer.nymtech.net',
}
mixnetExplorer: "https://mixnet.explorers.guru/",
blockExplorer: "https://blocks.nymtech.net",
networkExplorer: "https://explorer.nymtech.net",
}
: {
blockExplorer: `https://${networkName}-blocks.nymtech.net`,
networkExplorer: `https://${networkName}-explorer.nymtech.net`,
};
blockExplorer: `https://${networkName}-blocks.nymtech.net`,
networkExplorer: `https://${networkName}-explorer.nymtech.net`,
};
+19 -2
View File
@@ -10,33 +10,50 @@
},
"dependencies": {
"@chain-registry/types": "^0.45.9",
"@cosmjs/cosmwasm-stargate": "^0.29.5",
"@cosmos-kit/core": "^2.13.1",
"@cosmos-kit/keplr-extension": "^2.12.2",
"@cosmos-kit/react": "^2.17.2",
"@mui/base": "5.0.0-beta.40",
"@mui/icons-material": "^5.2.0",
"@mui/material": "^5.2.2",
"@mui/styles": "^5.2.2",
"@mui/system": "^5.15.20",
"@mui/x-data-grid": "7.1.1",
"@mui/x-date-pickers": "7.1.1",
"@nymproject/contract-clients": "1.2.4-rc.1",
"@nymproject/mui-theme": "workspace:^",
"@nymproject/nym-validator-client": "0.18.0",
"@nymproject/react": "workspace:^1.0.0",
"@nymproject/types": "workspace:^",
"@storybook/react": "^6.5.15",
"@types/d3-scale": "^4.0.8",
"@types/react-simple-maps": "^3.0.4",
"big.js": "^6.2.1",
"chain-registry": "^1.63.12",
"d3-scale": "^4.0.2",
"date-fns": "^2.28.0",
"i18n-iso-countries": "^7.11.2",
"lodash": "^4.17.21",
"material-react-table": "^2.12.1",
"next": "14.1.4",
"react": "^18",
"react-dom": "^18",
"react-error-boundary": "^4.0.13",
"react-google-charts": "^4.0.1",
"react-identicons": "^1.2.5",
"react-simple-maps": "^3.0.0",
"react-tooltip": "^5.27.0"
"react-tooltip": "^5.27.0",
"semver": "^6.3.1",
"use-clipboard-copy": "^0.2.0"
},
"devDependencies": {
"@types/big.js": "^6.1.6",
"@types/lodash": "^4.17.6",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/react-simple-maps": "^3.0.4",
"@types/semver": "^7.3.8",
"eslint": "^8",
"eslint-config-next": "14.1.4",
"typescript": "^5"