diff --git a/src/@types/partners.ts b/src/@types/partners.ts index 4be89d19..23123e40 100644 --- a/src/@types/partners.ts +++ b/src/@types/partners.ts @@ -11,6 +11,7 @@ export interface AttributesType { contactFirstname?: string contactLastname?: string contactPhone?: string + pChainAddress?: string companyShortDescription?: string companyLongDescription?: string isConsortiumMember?: boolean @@ -146,3 +147,33 @@ export interface PaginationType { pageCount: number total: number } + +type RewardOwner = { + locktime: string + threshold: string + addresses: string[] +} + +type RewardInfo = { + locktime: string + threshold: string + addresses: string[] +} + +export type Validator = { + txID: string + startTime: string + endTime: string + weight: string + nodeID: string + stakeAmount: string + rewardOwner: RewardOwner + validationRewardOwner: RewardInfo + delegationRewardOwner: RewardInfo + potentialReward: string + delegationFee: string + uptime: string + connected: boolean + delegatorCount: string + delegatorWeight: string +} diff --git a/src/components/Partners/PartnerCard.tsx b/src/components/Partners/PartnerCard.tsx index 477a205a..34da1523 100644 --- a/src/components/Partners/PartnerCard.tsx +++ b/src/components/Partners/PartnerCard.tsx @@ -1,7 +1,9 @@ import { Box, Typography } from '@mui/material' -import React from 'react' -import { PartnerDataType } from '../../@types/partners' +import React, { useEffect, useState } from 'react' +import { PartnerDataType, Validator } from '../../@types/partners' +import { useEffectOnce } from '../../hooks/useEffectOnce' +import useWallet from '../../hooks/useWallet' import PartnerBusinessFields from './PartnerBusinessFields' import PartnerFlag from './PartnerFlag' import PartnerLogo from './PartnerLogo' @@ -11,21 +13,33 @@ interface PartnerCardProps { clickable: boolean partner: PartnerDataType index: number + validators: Validator[] } -const PartnerCard: React.FC = ({ partner, clickable, onClick }) => { +const PartnerCard: React.FC = ({ partner, clickable, onClick, validators }) => { + useEffectOnce(() => {}) + const { getRegisteredNode } = useWallet() + const [isValidator, setIsValidator] = useState(false) + + const chackValidatorStatus = async (address: string) => { + if (!pChainAddress) setIsValidator(false) + let nodeID = await getRegisteredNode(address) + setIsValidator(!!validators.find(v => v.nodeID === nodeID)) + } const { attributes: { - isConsortiumMember, companyName, companyShortDescription, business_fields, companyLogoColor, country_flag, logoBox, + pChainAddress, }, } = partner - + useEffect(() => { + chackValidatorStatus(pChainAddress) + }, [partner]) return ( = ({ partner, clickable, onClick } overflow: 'hidden', }} > - {/* - // this value is incorrect, it should be based on the pchain addres but its not yet added to the api - {!!isConsortiumMember && ( + {!!isValidator && ( theme.palette.background.gradient, + background: theme => theme.palette.blue[50], padding: '10px 14px 8px 12px', display: 'flex', alignItems: 'center', @@ -61,9 +73,11 @@ const PartnerCard: React.FC = ({ partner, clickable, onClick } top: '0', }} > - Validator + theme.palette.grey[950] }} variant="overline"> + Validator + - )} */} + )} {!!companyLogoColor && !!companyName && ( = ({ state, dispatchPartners - {/* - disabled for now because we don't have the pchain address for the partner in strapi Only Validators} control={ = ({ state, dispatchPartners /> } /> - */} + ) } diff --git a/src/hooks/useWallet.ts b/src/hooks/useWallet.ts index de5e5967..8de5f7f8 100644 --- a/src/hooks/useWallet.ts +++ b/src/hooks/useWallet.ts @@ -1,3 +1,4 @@ +import { ava as caminoClient } from 'wallet/caminoClient' import { getNameOfWallet, getPchainAddress } from '../helpers/walletStore' import { updatePchainAddress } from '../redux/slices/app-config' import { useAppDispatch } from './reduxHooks' @@ -5,6 +6,12 @@ import { useAppDispatch } from './reduxHooks' const useWallet = () => { const dispatch = useAppDispatch() + async function getCurrentValidators() { + return caminoClient.PChain().getCurrentValidators() + } + async function getRegisteredNode(address: string): Promise { + return await caminoClient.PChain().getRegisteredShortIDLink(address) + } const updateStore = (type, params) => { switch (type) { case 'updateName': @@ -16,7 +23,7 @@ const useWallet = () => { ) } } - return { updateStore } + return { updateStore, getRegisteredNode, getCurrentValidators } } export default useWallet diff --git a/src/layout/MainLayout.tsx b/src/layout/MainLayout.tsx index fd55188b..d04cdef6 100644 --- a/src/layout/MainLayout.tsx +++ b/src/layout/MainLayout.tsx @@ -1,5 +1,12 @@ -import { Backdrop, CircularProgress, Paper, Typography } from '@mui/material' -import { Box, Toolbar, useTheme } from '@mui/material' +import { + Backdrop, + Box, + CircularProgress, + Paper, + Toolbar, + Typography, + useTheme, +} from '@mui/material' import React, { useState } from 'react' import { addNetworks, @@ -8,21 +15,22 @@ import { changeNetworkStatus, } from '../redux/slices/network' +import { Status } from '../@types' import Footer from '../components/Footer' import Navbar from '../components/Navbar' import Notifications from '../components/Notification' -import { Status } from '../@types' import { changeActiveApp } from '../redux/slices/app-config' import { matchNetworkStatus } from '../utils/componentsUtils' // @ts-ignore +import { useEffect } from 'react' +import { useLocation } from 'react-router-dom' import store from 'wallet/store' import { useAppDispatch } from '../hooks/reduxHooks' -import { useEffect } from 'react' import { useEffectOnce } from '../hooks/useEffectOnce' -import { useLocation } from 'react-router-dom' import useNetwork from '../hooks/useNetwork' // @ts-ignore import { useStore } from 'Explorer/useStore' +import { getCurrentValidators } from '../redux/slices/utils' const MainLayout = ({ children }) => { const [loadNetworks, setLoadNetworks] = useState(true) @@ -59,7 +67,7 @@ const MainLayout = ({ children }) => { useEffectOnce(() => { init() }) - + dispatch(getCurrentValidators()) useEffect(() => { const html = document.documentElement if (loading || loadNetworks) html.style.overflow = 'hidden' diff --git a/src/redux/services/partners.ts b/src/redux/services/partners.ts index ec860c93..594b1bec 100644 --- a/src/redux/services/partners.ts +++ b/src/redux/services/partners.ts @@ -28,7 +28,7 @@ export const partnersApi = createApi({ query += `&filters[companyName][$contains]=${companyName}` } if (validators) { - query += `&filters[isConsortiumMember][$eq]=true` + query += `&filters[pChainAddress][$ne]=null` } return query diff --git a/src/redux/slices/app-config.ts b/src/redux/slices/app-config.ts index 4fa3c190..8ee28f53 100644 --- a/src/redux/slices/app-config.ts +++ b/src/redux/slices/app-config.ts @@ -1,9 +1,10 @@ import { createSlice } from '@reduxjs/toolkit' import store from 'wallet/store' import { Status, SuitePlatforms } from '../../@types' +import { Validator } from '../../@types/partners' import { APPS_CONSTS } from '../../constants/apps-consts' import { RootState } from '../store' -import { updateAuthStatus } from './utils' +import { getCurrentValidators, updateAuthStatus } from './utils' type NotificationSeverityType = 'success' | 'warning' | 'info' | 'error' interface InitialStateAppConfigType { @@ -19,6 +20,7 @@ interface InitialStateAppConfigType { account: any showButton: boolean pChainAddress: string + validators: Validator[] } let initialState: InitialStateAppConfigType = { @@ -34,6 +36,7 @@ let initialState: InitialStateAppConfigType = { notificationMessage: '', account: null, showButton: false, + validators: [], } const appConfigSlice = createSlice({ @@ -94,6 +97,9 @@ const appConfigSlice = createSlice({ builder.addCase(updateAuthStatus.rejected, (state, { payload }) => { state.isAuth = false }) + builder.addCase(getCurrentValidators.fulfilled, (state, { payload }) => { + state.validators = payload + }) }, }) @@ -130,6 +136,8 @@ export const getPChainAddress = (state: RootState) => state.appConfig.pChainAddr // getWalletName export const getWalletName = (state: RootState) => state.appConfig.walletName +export const selectValidators = (state: RootState) => state.appConfig.validators + export const { changeActiveApp, updateValues, diff --git a/src/redux/slices/utils.ts b/src/redux/slices/utils.ts index 5626f794..c3791846 100644 --- a/src/redux/slices/utils.ts +++ b/src/redux/slices/utils.ts @@ -1,4 +1,5 @@ import { createAsyncThunk } from '@reduxjs/toolkit' +import useWallet from '../../hooks/useWallet' export const updateAuthStatus = createAsyncThunk( 'appConfig/updateAuthStatus', @@ -9,3 +10,10 @@ export const updateAuthStatus = createAsyncThunk( return false }, ) + +export const getCurrentValidators = createAsyncThunk('appConfig/getCurrentValidators', async () => { + const { getCurrentValidators } = useWallet() + try { + return (await getCurrentValidators()).validators + } catch (e) {} +}) diff --git a/src/theme/typography.ts b/src/theme/typography.ts index 33693359..d83f4804 100644 --- a/src/theme/typography.ts +++ b/src/theme/typography.ts @@ -140,7 +140,7 @@ const typography = { }, overline: { fontFamily: FONT, - fontWeight: 700, + fontWeight: 600, lineHeight: '18px', fontSize: pxToRem(12), letterSpacing: '-1.1%', diff --git a/src/views/partners/ListPartners.tsx b/src/views/partners/ListPartners.tsx index ff9b07d5..fc6cd7ff 100644 --- a/src/views/partners/ListPartners.tsx +++ b/src/views/partners/ListPartners.tsx @@ -1,8 +1,10 @@ import { PartnerDataType, PartnersResponseType } from '../../@types/partners' import { Box } from '@mui/material' -import PartnerCard from '../../components/Partners/PartnerCard' import React from 'react' +import PartnerCard from '../../components/Partners/PartnerCard' +import { useAppSelector } from '../../hooks/reduxHooks' +import { selectValidators } from '../../redux/slices/app-config' interface ListPartnersProps { partners: PartnersResponseType @@ -10,6 +12,7 @@ interface ListPartnersProps { } const ListPartners: React.FC = ({ partners, setPartner }) => { + const validators = useAppSelector(selectValidators) return ( = ({ partners, setPartner }) => > {partners.data.map((partner, index) => ( { if ( !!(