Skip to content

Commit

Permalink
Added a badge to the validator partners.
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddaqqa committed Mar 18, 2024
1 parent 38d3024 commit 1f40400
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 28 deletions.
31 changes: 31 additions & 0 deletions src/@types/partners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface AttributesType {
contactFirstname?: string
contactLastname?: string
contactPhone?: string
pChainAddress?: string
companyShortDescription?: string
companyLongDescription?: string
isConsortiumMember?: boolean
Expand Down Expand Up @@ -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
}
36 changes: 25 additions & 11 deletions src/components/Partners/PartnerCard.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -11,21 +13,33 @@ interface PartnerCardProps {
clickable: boolean
partner: PartnerDataType
index: number
validators: Validator[]
}

const PartnerCard: React.FC<PartnerCardProps> = ({ partner, clickable, onClick }) => {
const PartnerCard: React.FC<PartnerCardProps> = ({ 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])

Check warning on line 42 in src/components/Partners/PartnerCard.tsx

View workflow job for this annotation

GitHub Actions / yarn-build

React Hook useEffect has missing dependencies: 'chackValidatorStatus' and 'pChainAddress'. Either include them or remove the dependency array
return (
<Box
onClick={onClick}
Expand All @@ -45,13 +59,11 @@ const PartnerCard: React.FC<PartnerCardProps> = ({ 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 && (
<Box
sx={{
position: 'absolute',
background: theme => theme.palette.background.gradient,
background: theme => theme.palette.blue[50],
padding: '10px 14px 8px 12px',
display: 'flex',
alignItems: 'center',
Expand All @@ -61,9 +73,11 @@ const PartnerCard: React.FC<PartnerCardProps> = ({ partner, clickable, onClick }
top: '0',
}}
>
<Typography sx={{ color: 'common.white' }}>Validator</Typography>
<Typography sx={{ color: theme => theme.palette.grey[950] }} variant="overline">
Validator
</Typography>
</Box>
)} */}
)}
{!!companyLogoColor && !!companyName && (
<PartnerLogo
colorLogo={companyLogoColor}
Expand Down
10 changes: 4 additions & 6 deletions src/components/Partners/PartnersFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ActionType, StatePartnersType, partnersActions } from '../../helpers/partnersReducer'

import { Box } from '@mui/material'
import BusinessFieldFilter from './BusinessFieldFilter'
import { Box, Checkbox, FormControlLabel, Typography } from '@mui/material'
import React from 'react'
import BusinessFieldFilter from './BusinessFieldFilter'
import SearchInput from './SearchInput'

interface PartnersFilterProps {
Expand All @@ -17,11 +17,9 @@ const PartnersFilter: React.FC<PartnersFilterProps> = ({ state, dispatchPartners
<Box sx={{ display: 'flex', gap: '1rem', alignItems: 'center', flexWrap: 'wrap' }}>
<SearchInput searchByName={searchByName} />
<BusinessFieldFilter state={state} dispatchPartnersActions={dispatchPartnersActions} />
{/*
disabled for now because we don't have the pchain address for the partner in strapi
<Box sx={{ display: 'flex', alignItems: 'center', gap: '.5rem' }}>
<FormControlLabel
label="Only Validators"
label={<Typography variant="body2">Only Validators</Typography>}
control={
<Checkbox
sx={{
Expand All @@ -40,7 +38,7 @@ const PartnersFilter: React.FC<PartnersFilterProps> = ({ state, dispatchPartners
/>
}
/>
</Box> */}
</Box>
</Box>
)
}
Expand Down
9 changes: 8 additions & 1 deletion src/hooks/useWallet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { ava as caminoClient } from 'wallet/caminoClient'
import { getNameOfWallet, getPchainAddress } from '../helpers/walletStore'
import { updatePchainAddress } from '../redux/slices/app-config'
import { useAppDispatch } from './reduxHooks'

const useWallet = () => {
const dispatch = useAppDispatch()

async function getCurrentValidators() {
return caminoClient.PChain().getCurrentValidators()
}
async function getRegisteredNode(address: string): Promise<string> {
return await caminoClient.PChain().getRegisteredShortIDLink(address)
}
const updateStore = (type, params) => {
switch (type) {
case 'updateName':
Expand All @@ -16,7 +23,7 @@ const useWallet = () => {
)
}
}
return { updateStore }
return { updateStore, getRegisteredNode, getCurrentValidators }
}

export default useWallet
20 changes: 14 additions & 6 deletions src/layout/MainLayout.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -59,7 +67,7 @@ const MainLayout = ({ children }) => {
useEffectOnce(() => {
init()
})

dispatch(getCurrentValidators())
useEffect(() => {
const html = document.documentElement
if (loading || loadNetworks) html.style.overflow = 'hidden'
Expand Down
2 changes: 1 addition & 1 deletion src/redux/services/partners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/redux/slices/app-config.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -19,6 +20,7 @@ interface InitialStateAppConfigType {
account: any
showButton: boolean
pChainAddress: string
validators: Validator[]
}

let initialState: InitialStateAppConfigType = {
Expand All @@ -34,6 +36,7 @@ let initialState: InitialStateAppConfigType = {
notificationMessage: '',
account: null,
showButton: false,
validators: [],
}

const appConfigSlice = createSlice({
Expand Down Expand Up @@ -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
})
},
})

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/redux/slices/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createAsyncThunk } from '@reduxjs/toolkit'
import useWallet from '../../hooks/useWallet'

export const updateAuthStatus = createAsyncThunk(
'appConfig/updateAuthStatus',
Expand All @@ -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) {}
})
2 changes: 1 addition & 1 deletion src/theme/typography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const typography = {
},
overline: {
fontFamily: FONT,
fontWeight: 700,
fontWeight: 600,
lineHeight: '18px',
fontSize: pxToRem(12),
letterSpacing: '-1.1%',
Expand Down
6 changes: 5 additions & 1 deletion src/views/partners/ListPartners.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
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
setPartner: React.Dispatch<React.SetStateAction<PartnerDataType>>
}

const ListPartners: React.FC<ListPartnersProps> = ({ partners, setPartner }) => {
const validators = useAppSelector(selectValidators)
return (
<Box
sx={{
Expand All @@ -21,6 +24,7 @@ const ListPartners: React.FC<ListPartnersProps> = ({ partners, setPartner }) =>
>
{partners.data.map((partner, index) => (
<PartnerCard
validators={validators}
onClick={() => {
if (
!!(
Expand Down

0 comments on commit 1f40400

Please sign in to comment.