From e0504e589a7e80b00b913fc88fefbfa826ddcf79 Mon Sep 17 00:00:00 2001
From: soaresa <10797037+soaresa@users.noreply.github.com>
Date: Sat, 23 Nov 2024 22:43:22 -0300
Subject: [PATCH] Adds tooltip to the vouch chip icons (#65)
---
web-app/package-lock.json | 21 +++++
web-app/package.json | 1 +
.../core/routes/Validators/Validators.tsx | 2 +-
.../Validators/components/ValidatorRow.tsx | 2 +-
.../Validators/components/ValidatorsStats.tsx | 8 --
.../components/Vouch/FamilyIcon.tsx | 9 +++
.../Validators/components/Vouch/VouchChip.tsx | 76 +++++++++++++++++++
.../components/Vouch/VouchLegend.tsx | 22 ++++++
.../components/{ => Vouch}/Vouches.tsx | 2 +-
.../components/{ => Vouch}/VouchesRow.tsx | 68 ++---------------
.../{ => Vouch}/VouchesRowSkeleton.tsx | 0
.../components/{ => Vouch}/VouchesTable.tsx | 8 +-
.../components/Vouch/legendItems.tsx | 59 ++++++++++++++
.../Validators/components/VouchesLegend.tsx | 72 ------------------
web-app/src/utils.ts | 4 +
15 files changed, 205 insertions(+), 149 deletions(-)
create mode 100644 web-app/src/modules/core/routes/Validators/components/Vouch/FamilyIcon.tsx
create mode 100644 web-app/src/modules/core/routes/Validators/components/Vouch/VouchChip.tsx
create mode 100644 web-app/src/modules/core/routes/Validators/components/Vouch/VouchLegend.tsx
rename web-app/src/modules/core/routes/Validators/components/{ => Vouch}/Vouches.tsx (98%)
rename web-app/src/modules/core/routes/Validators/components/{ => Vouch}/VouchesRow.tsx (53%)
rename web-app/src/modules/core/routes/Validators/components/{ => Vouch}/VouchesRowSkeleton.tsx (100%)
rename web-app/src/modules/core/routes/Validators/components/{ => Vouch}/VouchesTable.tsx (96%)
create mode 100644 web-app/src/modules/core/routes/Validators/components/Vouch/legendItems.tsx
delete mode 100644 web-app/src/modules/core/routes/Validators/components/VouchesLegend.tsx
diff --git a/web-app/package-lock.json b/web-app/package-lock.json
index 1b4b6a4..55e10cd 100644
--- a/web-app/package-lock.json
+++ b/web-app/package-lock.json
@@ -34,6 +34,7 @@
"react-dom": "^18.3.1",
"react-qr-code": "^2.0.14",
"react-router-dom": "^6.23.1",
+ "react-tooltip": "^5.28.0",
"styled-components": "^6.1.11"
},
"devDependencies": {
@@ -1837,6 +1838,12 @@
"node": ">= 6"
}
},
+ "node_modules/classnames": {
+ "version": "2.5.1",
+ "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz",
+ "integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==",
+ "license": "MIT"
+ },
"node_modules/clone-response": {
"version": "1.0.3",
"license": "MIT",
@@ -3733,6 +3740,20 @@
"react-dom": ">=16.8"
}
},
+ "node_modules/react-tooltip": {
+ "version": "5.28.0",
+ "resolved": "https://registry.npmjs.org/react-tooltip/-/react-tooltip-5.28.0.tgz",
+ "integrity": "sha512-R5cO3JPPXk6FRbBHMO0rI9nkUG/JKfalBSQfZedZYzmqaZQgq7GLzF8vcCWx6IhUCKg0yPqJhXIzmIO5ff15xg==",
+ "license": "MIT",
+ "dependencies": {
+ "@floating-ui/dom": "^1.6.1",
+ "classnames": "^2.3.0"
+ },
+ "peerDependencies": {
+ "react": ">=16.14.0",
+ "react-dom": ">=16.14.0"
+ }
+ },
"node_modules/read-cache": {
"version": "1.0.0",
"dev": true,
diff --git a/web-app/package.json b/web-app/package.json
index a102c08..7daaad1 100644
--- a/web-app/package.json
+++ b/web-app/package.json
@@ -41,6 +41,7 @@
"react-dom": "^18.3.1",
"react-qr-code": "^2.0.14",
"react-router-dom": "^6.23.1",
+ "react-tooltip": "^5.28.0",
"styled-components": "^6.1.11"
},
"devDependencies": {
diff --git a/web-app/src/modules/core/routes/Validators/Validators.tsx b/web-app/src/modules/core/routes/Validators/Validators.tsx
index 6b90def..ebe8aa3 100644
--- a/web-app/src/modules/core/routes/Validators/Validators.tsx
+++ b/web-app/src/modules/core/routes/Validators/Validators.tsx
@@ -3,7 +3,7 @@ import { gql, useQuery } from '@apollo/client';
import Page from '../../../ui/Page';
import ValidatorsTable from './components/ValidatorsTable';
import ValidatorsStats from './components/ValidatorsStats';
-import VouchesTable from './components/VouchesTable';
+import VouchesTable from './components/Vouch/VouchesTable';
import ToggleButton from '../../../ui/ToggleButton';
const GET_VALIDATORS = gql`
diff --git a/web-app/src/modules/core/routes/Validators/components/ValidatorRow.tsx b/web-app/src/modules/core/routes/Validators/components/ValidatorRow.tsx
index 483efc2..5982a6f 100644
--- a/web-app/src/modules/core/routes/Validators/components/ValidatorRow.tsx
+++ b/web-app/src/modules/core/routes/Validators/components/ValidatorRow.tsx
@@ -11,7 +11,7 @@ import {
XCircleIcon,
} from '@heroicons/react/20/solid';
// import ProgressBar from './ProgressBar';
-import Vouches from './Vouches';
+import Vouches from './Vouch/Vouches';
// Define icons for each status
const statusIcons = {
diff --git a/web-app/src/modules/core/routes/Validators/components/ValidatorsStats.tsx b/web-app/src/modules/core/routes/Validators/components/ValidatorsStats.tsx
index 6352e21..155802f 100644
--- a/web-app/src/modules/core/routes/Validators/components/ValidatorsStats.tsx
+++ b/web-app/src/modules/core/routes/Validators/components/ValidatorsStats.tsx
@@ -67,12 +67,4 @@ function formatPercentage(value: number) {
return `${(value / 10).toFixed(1)}%`;
}
-// print percentage 0-100
-/*function formatPercentage(value: number, didChange: boolean, didIncrease: boolean) {
- if (didChange) {
- return didIncrease ? `+${value}%` : `-${value}%`;
- }
- return `${value}%`;
-}*/
-
export default ValidatorsStats;
diff --git a/web-app/src/modules/core/routes/Validators/components/Vouch/FamilyIcon.tsx b/web-app/src/modules/core/routes/Validators/components/Vouch/FamilyIcon.tsx
new file mode 100644
index 0000000..8f42f9b
--- /dev/null
+++ b/web-app/src/modules/core/routes/Validators/components/Vouch/FamilyIcon.tsx
@@ -0,0 +1,9 @@
+export const FamilyIcon: React.FC<{ family: string }> = ({ family }) => {
+ const bgColor = family && family.length > 8 ? `#${family.slice(2, 8)}` : `#f87171`;
+ return (
+
+ );
+};
diff --git a/web-app/src/modules/core/routes/Validators/components/Vouch/VouchChip.tsx b/web-app/src/modules/core/routes/Validators/components/Vouch/VouchChip.tsx
new file mode 100644
index 0000000..da225e5
--- /dev/null
+++ b/web-app/src/modules/core/routes/Validators/components/Vouch/VouchChip.tsx
@@ -0,0 +1,76 @@
+// VouchChip.tsx
+import React from 'react';
+import clsx from 'clsx';
+import { legendItems } from './legendItems';
+import { formatAddress } from '../../../../../../utils';
+import { FamilyIcon } from './FamilyIcon';
+
+interface VouchDetails {
+ inSet: boolean;
+ compliant: boolean;
+ epochsToExpire: number;
+ handle?: string;
+ address: string;
+ family: string;
+}
+
+export const VouchChip: React.FC<{ vouch: VouchDetails; index: number }> = ({ vouch, index }) => {
+ // Determine which icons to display based on vouch properties
+ const activeIcons = legendItems.filter((item) => {
+ switch (item.title) {
+ case 'In Set':
+ return vouch.inSet;
+ case 'Compliant':
+ return vouch.compliant;
+ case 'Non-Compliant':
+ return !vouch.compliant;
+ case 'Expiring Soon':
+ return vouch.epochsToExpire <= 7 && vouch.epochsToExpire > 0;
+ case 'Expired':
+ return vouch.epochsToExpire <= 0;
+ default:
+ return false;
+ }
+ });
+
+ return (
+
+ {activeIcons.map((item, idx) => (
+
+
The data in this table is updated every 60 seconds.
diff --git a/web-app/src/modules/core/routes/Validators/components/Vouch/legendItems.tsx b/web-app/src/modules/core/routes/Validators/components/Vouch/legendItems.tsx new file mode 100644 index 0000000..a9a9116 --- /dev/null +++ b/web-app/src/modules/core/routes/Validators/components/Vouch/legendItems.tsx @@ -0,0 +1,59 @@ +// legendItems.tsx +import { + GlobeAltIcon, + CheckIcon, + XMarkIcon, + ExclamationTriangleIcon, + ClockIcon, +} from '@heroicons/react/20/solid'; + +export interface LegendItem { + Icon: React.ComponentType