add service-type and routing-scores to sps + allow sorting on routing scores

This commit is contained in:
fmtabbara
2023-06-06 22:44:05 +01:00
parent b8ca1762c2
commit e32ee2ccf3
7 changed files with 70 additions and 124 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ import {
Environment,
GatewayBondAnnotated,
GatewayBond,
DirectoryService,
DirectoryServiceProvider,
} from '../typeDefs/explorer-api';
function getFromCache(key: string) {
@@ -153,7 +153,7 @@ export class Api {
static fetchUptimeStoryById = async (id: string): Promise<UptimeStoryResponse> =>
(await fetch(`${UPTIME_STORY_API}/${id}/history`)).json();
static fetchServiceProviders = async (): Promise<DirectoryService[]> => {
static fetchServiceProviders = async (): Promise<DirectoryServiceProvider[]> => {
const res = await fetch(SERVICE_PROVIDERS);
const json = await res.json();
return json;
+37 -37
View File
@@ -52,43 +52,43 @@ type DataGridProps = {
};
export const UniversalDataGrid: FCWithChildren<DataGridProps> = ({ rows, columns, loading, pagination, pageSize }) => {
if (loading) return <LinearProgress />;
if (!loading)
return (
<DataGrid
pagination={pagination}
rows={rows}
components={{
Pagination: CustomPagination,
}}
columns={columns}
pageSize={Number(pageSize)}
disableSelectionOnClick
autoHeight
hideFooter={!pagination}
style={{
width: '100%',
border: 'none',
}}
sx={{
'*::-webkit-scrollbar': {
width: '1em',
},
'*::-webkit-scrollbar-track': {
background: (t) => t.palette.nym.networkExplorer.scroll.backgroud,
outline: (t) => `1px solid ${t.palette.nym.networkExplorer.scroll.border}`,
boxShadow: 'auto',
borderRadius: 'auto',
},
'*::-webkit-scrollbar-thumb': {
backgroundColor: (t) => t.palette.nym.networkExplorer.scroll.color,
borderRadius: '20px',
width: '.4em',
border: (t) => `3px solid ${t.palette.nym.networkExplorer.scroll.backgroud}`,
shadow: 'auto',
},
}}
/>
);
return (
<DataGrid
pagination={pagination}
rows={rows}
components={{
Pagination: CustomPagination,
}}
columns={columns}
pageSize={Number(pageSize)}
disableSelectionOnClick
autoHeight
hideFooter={!pagination}
style={{
width: '100%',
border: 'none',
}}
sx={{
'*::-webkit-scrollbar': {
width: '1em',
},
'*::-webkit-scrollbar-track': {
background: (t) => t.palette.nym.networkExplorer.scroll.backgroud,
outline: (t) => `1px solid ${t.palette.nym.networkExplorer.scroll.border}`,
boxShadow: 'auto',
borderRadius: 'auto',
},
'*::-webkit-scrollbar-thumb': {
backgroundColor: (t) => t.palette.nym.networkExplorer.scroll.color,
borderRadius: '20px',
width: '.4em',
border: (t) => `3px solid ${t.palette.nym.networkExplorer.scroll.backgroud}`,
shadow: 'auto',
},
}}
/>
);
return null;
};
+11 -8
View File
@@ -4,17 +4,18 @@ import {
ApiState,
BlockResponse,
CountryDataResponse,
DirectoryService,
GatewayResponse,
MixNodeResponse,
MixnodeStatus,
SummaryOverviewResponse,
ValidatorsResponse,
Environment,
DirectoryServiceProvider,
} from '../typeDefs/explorer-api';
import { EnumFilterKey } from '../typeDefs/filters';
import { Api, getEnvironment } from '../api';
import { NavOptionType, originalNavOptions } from './nav';
import { toPercentIntegerString } from '../utils';
interface StateData {
summaryOverview?: ApiState<SummaryOverviewResponse>;
@@ -27,7 +28,7 @@ interface StateData {
navState: NavOptionType[];
validators?: ApiState<ValidatorsResponse>;
environment?: Environment;
serviceProviders?: ApiState<DirectoryService>;
serviceProviders?: ApiState<DirectoryServiceProvider[]>;
}
interface StateApi {
@@ -70,7 +71,7 @@ export const MainContextProvider: FCWithChildren = ({ children }) => {
const [validators, setValidators] = React.useState<ApiState<ValidatorsResponse>>();
const [block, setBlock] = React.useState<ApiState<BlockResponse>>();
const [countryData, setCountryData] = React.useState<ApiState<CountryDataResponse>>();
const [serviceProviders, setServiceProviders] = React.useState<ApiState<DirectoryService>>();
const [serviceProviders, setServiceProviders] = React.useState<ApiState<DirectoryServiceProvider[]>>();
const toggleMode = () => setMode((m) => (m !== 'light' ? 'light' : 'dark'));
@@ -168,8 +169,12 @@ export const MainContextProvider: FCWithChildren = ({ children }) => {
const fetchServiceProviders = async () => {
setServiceProviders({ data: undefined, isLoading: true });
try {
const [res] = await Api.fetchServiceProviders();
setServiceProviders({ data: res, isLoading: false });
const res = await Api.fetchServiceProviders();
const resWithRoutingScorePercentage = res.map((item) => ({
...item,
routing_score: item.routing_score ? `${toPercentIntegerString(item.routing_score.toString())}%` : undefined,
}));
setServiceProviders({ data: resWithRoutingScorePercentage, isLoading: false });
} catch (error) {
setServiceProviders({
error: error instanceof Error ? error : new Error('Service provider api fail'),
@@ -187,9 +192,7 @@ export const MainContextProvider: FCWithChildren = ({ children }) => {
};
React.useEffect(() => {
if (environment === 'mainnet') {
fetchServiceProviders();
}
fetchServiceProviders();
}, [environment]);
React.useEffect(() => {
+1 -1
View File
@@ -78,7 +78,7 @@ export const PageOverview: FCWithChildren = () => {
onClick={() => navigate('/network-components/service-providers')}
title="Service providers"
icon={<PeopleAlt />}
count={serviceProviders.data?.items.length}
count={serviceProviders.data?.length}
errorMsg={summaryOverview?.error}
/>
</Grid>
+17 -9
View File
@@ -1,5 +1,6 @@
import React from 'react';
import { Button, Card, FormControl, Grid, ListItem, Menu, SelectChangeEvent, Typography } from '@mui/material';
import { GridRenderCellParams } from '@mui/x-data-grid';
import { TableToolbar } from '../../components/TableToolbar';
import { Title } from '../../components/Title';
import { UniversalDataGrid } from '../../components/Universal-DataGrid';
@@ -14,15 +15,27 @@ const columns = [
},
{
headerName: 'Type',
field: 'type',
field: 'service_type',
disableColumnMenu: true,
flex: 1,
},
{
headerName: 'Routing score',
field: 'routingScore',
field: 'routing_score',
disableColumnMenu: true,
flex: 1,
sortComparator: (a?: string, b?: string) => {
if (!a) return 1; // Place undefined values at the end
if (!b) return -1; // Place undefined values at the end
const aToNum = parseInt(a, 10);
const bToNum = parseInt(b, 10);
if (aToNum > bToNum) return -1;
return 1; // Sort numbers in ascending order
},
renderCell: (params: GridRenderCellParams) => (!params.value ? '-' : params.value),
},
];
@@ -49,7 +62,7 @@ const SupportedApps = () => {
>
Supported Apps
</Button>
<Menu id="basic-menu" anchorEl={anchorEl} open={open} onClose={handleClose}>
<Menu anchorEl={anchorEl} open={open} onClose={handleClose}>
<ListItem>Keybase</ListItem>
<ListItem>Telegram</ListItem>
<ListItem>Electrum</ListItem>
@@ -84,12 +97,7 @@ export const ServiceProviders = () => {
pageSize={pageSize}
childrenBefore={<SupportedApps />}
/>
<UniversalDataGrid
pagination
rows={serviceProviders?.data?.items}
columns={columns}
pageSize={pageSize}
/>
<UniversalDataGrid pagination rows={serviceProviders.data} columns={columns} pageSize={pageSize} />
</>
) : (
<Typography>No service providers to display</Typography>
+2 -2
View File
@@ -248,8 +248,8 @@ export type DirectoryServiceProvider = {
description: string;
address: string;
gateway: string;
routingScore: number;
serviceType: ServiceProviderType;
routing_score?: string;
service_type: ServiceProviderType;
};
export type DirectoryService = {
-65
View File
@@ -4210,101 +4210,51 @@
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-1.3.0.tgz#d0c853ab2cc7506bd826c5f7f260c67c7c15def5"
integrity sha512-AH+3FonkKZNtfRtGrObY38PrzEj4d+1emCbwNGu0V2ENbXjlLHMZQlUh+Bhu/CRmjaIwZMGJ3yFvWaZZgTHoog==
"@tauri-apps/api@^2.0.0-alpha.0":
version "2.0.0-alpha.3"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-2.0.0-alpha.3.tgz#7f467c188305944d67b5b6e82be0041b8b4dbbc9"
integrity sha512-F6seMDlcaxeCPy4gS0zJdp6Tet+0rd1qJi/fbKrOrhLM6Y5UtkiG1aSDnMPi+1udThSfadjhUwrLHINvfMCjzQ==
"@tauri-apps/cli-darwin-arm64@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-1.3.0.tgz#6c738af14f494546e0fbe64f6befa0eb08959150"
integrity sha512-uuhx3/LaqFyHkoGOnOltBLKWGOzC6WzdXu+/Qv3NmNnyQWkY7O34z5V0oP6ibfuiOBZufKjOuBR+8YAIR8Qh9Q==
"@tauri-apps/cli-darwin-arm64@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-2.0.0-alpha.8.tgz#399bec52290ea85f74470bc329376142e17e9878"
integrity sha512-ZF9nkkYCDiAEKZFwjEbuqTcFVp+DBgem3edKjsZDYPQpWg0VcZOSYr0o3/RPC81T1/FAy1lq478mkcMe0efvEw==
"@tauri-apps/cli-darwin-x64@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-darwin-x64/-/cli-darwin-x64-1.3.0.tgz#d3fda368b555663723337a70abe4b470592d9bda"
integrity sha512-fj0VXHMDvb/H1CjaS/JoYd7xcourxndJn1IyM4afYbpXibT/fpmM6uZflDI6rRa220NfnBtQvy+asgwC9wuyLA==
"@tauri-apps/cli-darwin-x64@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-darwin-x64/-/cli-darwin-x64-2.0.0-alpha.8.tgz#4935823acf880423f6e2c70097ab6584079321b3"
integrity sha512-N5V+tbP3qeAoXrrTZXvaLIeEWKCq11tqXoNFTkIZNGNC5yQdNpZSX0LqFqzmxVR1SHiOymebvcUlx+ADIpuXGw==
"@tauri-apps/cli-linux-arm-gnueabihf@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-linux-arm-gnueabihf/-/cli-linux-arm-gnueabihf-1.3.0.tgz#165ed5a299a944a8c0fc1ed5fc0d609db78a142b"
integrity sha512-f80DmFPnH5ZskG61KIlAyMVk9YkrTq0XM2uiQjOo5gToIdJidSwhPQVeBLv+7UxhqaRBx082Dg2fOkWlO3LiOQ==
"@tauri-apps/cli-linux-arm-gnueabihf@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-linux-arm-gnueabihf/-/cli-linux-arm-gnueabihf-2.0.0-alpha.8.tgz#5b46f8f38be9b0c6fe8c343e7e589c958a225775"
integrity sha512-7LHfZA99ncMDUO/wCGMtrqmDHt1uEKZiNmuzPljWLUwVvbAn0pNWNygnvPNVLEOyav5NnZSGPqT1Zmn+L6Fpyg==
"@tauri-apps/cli-linux-arm64-gnu@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-1.3.0.tgz#a68f2efc78e03d1ae59804e61ad9ee6bd78b08c0"
integrity sha512-s6/OByuGoppoUSnOXv/b6Oe6cVFk2w/KHs19aJJpo9ov/dUAA1w9wXlXu2l6sOFGsu/plaVomF2cw3iAQmaUCQ==
"@tauri-apps/cli-linux-arm64-gnu@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-2.0.0-alpha.8.tgz#56bfa1ec613bfff0aaecd8d38aaab470ae117d58"
integrity sha512-imq2MdhWdREvL2sqbU26mzH9sgSvfNWP0uvCPvPxUhK157xqdtGw+Gqm00hwnhTuT5bOFlsUNfnG2U19k1qMpA==
"@tauri-apps/cli-linux-arm64-musl@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.3.0.tgz#eff2221408d1040d6f4cbf98a851c16e9eeb11e5"
integrity sha512-yZfZAW4BG92cynL/D4wdrwBAl2oekRwiZnU5CM8k5yncalVEL0tyzuxQjjqbqrtDcw0rdkoBWrhFd+EB89vQaQ==
"@tauri-apps/cli-linux-arm64-musl@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.0.0-alpha.8.tgz#6a0e2a3f1a494481ce391d379284f688c59ba2aa"
integrity sha512-7hXEyvCosBHIN6ahkbFOI5JoyWZAulc0sYd3hWh9V/MBfU+LlPiapsJi6fdde0zew5nnzwcCtfEKkoR737tAig==
"@tauri-apps/cli-linux-x64-gnu@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-linux-x64-gnu/-/cli-linux-x64-gnu-1.3.0.tgz#2faaea4272278837df09edae90a9907c4dfe99c4"
integrity sha512-K3KRWSGKh7DTBr/ZKgWzeNX1Vdgx1ZBlUJXsm72R0Hb+93fDEp3TWgiwVkxqecB4aNWJhJsDcvRHuxw1G8xPlA==
"@tauri-apps/cli-linux-x64-gnu@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-linux-x64-gnu/-/cli-linux-x64-gnu-2.0.0-alpha.8.tgz#0ae1f0c19ab8fb9878161db4d40c3cbd581e37f3"
integrity sha512-S9T/trKpXcLc7hVIv7xFrRBlaivHD/HLUz0nYAkI2izNGFmbP3QpkqQDdwpWN/fxneodNgI2/mDFC3NULClj+A==
"@tauri-apps/cli-linux-x64-musl@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-linux-x64-musl/-/cli-linux-x64-musl-1.3.0.tgz#3f678ab7dc441da5582909230934204e23f85f6b"
integrity sha512-99bVHqL1EtF7oESrlmEb5BWJsMNQ2ha70gesZhaVO2qI9Vg089XvrFZWC+aGiUsXNFrOw270+D9DKn03xO5+Zg==
"@tauri-apps/cli-linux-x64-musl@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-linux-x64-musl/-/cli-linux-x64-musl-2.0.0-alpha.8.tgz#dbb668569ee71f041b38b05470697cc0ba761ff3"
integrity sha512-90mx6vSFNBbctaPaKhkH+um51gOoRJwLFOadOkklHS5Q6S6GjtSa1lmBEFyKUTAfFPtmiacuNYtoKx7nqm+z1Q==
"@tauri-apps/cli-win32-ia32-msvc@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-1.3.0.tgz#eeaaa3e59cb1f26f5e7d7ce5aa101d5821a5355b"
integrity sha512-ckBUTqXXdnCiYyf2xvxiuqiKZurg7ET++f6yzfvYa+gofd5dagQJkGLlkIg2pJ2c8mhEG1Cfk1vxWPqqGfN2GQ==
"@tauri-apps/cli-win32-ia32-msvc@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-2.0.0-alpha.8.tgz#f87db96860ca883efa7a7d96095583cb69a4dc5f"
integrity sha512-VAMsLJYfp6iVI7oJ+uIkfe8DKPRMtWDiSEkfFqvDyFX0WMTQl23B0AzYyapVwZc+WkTkLuoMLpIWMQCgAoQWfQ==
"@tauri-apps/cli-win32-x64-msvc@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-win32-x64-msvc/-/cli-win32-x64-msvc-1.3.0.tgz#8d67ab0e9bd3ae9e3a9b6e54845e0ca34ab1526c"
integrity sha512-vQ4wqRE0aziyRxgHIOLudGuxx4wETvFnmMvDBaNJRRrZQPlkOKnRxrvj1rNnI1845BdzSbDF4p7JDcFzToAfXA==
"@tauri-apps/cli-win32-x64-msvc@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-win32-x64-msvc/-/cli-win32-x64-msvc-2.0.0-alpha.8.tgz#d438b0231aaac35223d666d207b50c2794fc4ea6"
integrity sha512-zvWd13hRfRM0AEJJZ4t4CeB/cyru8hvbB6c+sxYDS9GPRWfHSH5dIeKoHhnMwP5fEOPZLN7VaeEP6tC88trD6g==
"@tauri-apps/cli@^1.0.5", "@tauri-apps/cli@^1.2.2":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli/-/cli-1.3.0.tgz#587b7d6ed34dab04f56f29925626ba1a248e298c"
@@ -4320,21 +4270,6 @@
"@tauri-apps/cli-win32-ia32-msvc" "1.3.0"
"@tauri-apps/cli-win32-x64-msvc" "1.3.0"
"@tauri-apps/cli@^2.0.0-alpha.2":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli/-/cli-2.0.0-alpha.8.tgz#84772a16889b38dcd6239fe159bb5a5f2b1e1cc9"
integrity sha512-cXt6pxh7oiV8Htz7eTPor7if4aN9f9emn10+5h2Y82YzST7I7wKXsrjuk0HIyzUiqiQjUgl3iT9gh791zgtI3w==
optionalDependencies:
"@tauri-apps/cli-darwin-arm64" "2.0.0-alpha.8"
"@tauri-apps/cli-darwin-x64" "2.0.0-alpha.8"
"@tauri-apps/cli-linux-arm-gnueabihf" "2.0.0-alpha.8"
"@tauri-apps/cli-linux-arm64-gnu" "2.0.0-alpha.8"
"@tauri-apps/cli-linux-arm64-musl" "2.0.0-alpha.8"
"@tauri-apps/cli-linux-x64-gnu" "2.0.0-alpha.8"
"@tauri-apps/cli-linux-x64-musl" "2.0.0-alpha.8"
"@tauri-apps/cli-win32-ia32-msvc" "2.0.0-alpha.8"
"@tauri-apps/cli-win32-x64-msvc" "2.0.0-alpha.8"
"@tauri-apps/tauri-forage@^1.0.0-beta.2":
version "1.0.0-beta.2"
resolved "https://registry.yarnpkg.com/@tauri-apps/tauri-forage/-/tauri-forage-1.0.0-beta.2.tgz#c11b438ba32731dc7b4c8689d9fda4130baadc07"