Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix validator badge in partner view #262

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 41 additions & 20 deletions src/components/Partners/PartnersFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ActionType, StatePartnersType, partnersActions } from '../../helpers/partnersReducer'

import { Box, Button, Checkbox, FormControlLabel, Typography } from '@mui/material'
import React from 'react'
import React, { useMemo } from 'react'
import store from 'wallet/store'
import { REGISTER_PARTNER_URL } from '../../constants/route-paths'
import { useAppSelector } from '../../hooks/reduxHooks'
import { useIsPartnerQuery } from '../../redux/services/partners'
import { getActiveNetwork } from '../../redux/slices/network'
import BusinessFieldFilter from './BusinessFieldFilter'
import SearchInput from './SearchInput'

Expand All @@ -14,6 +18,21 @@ interface PartnersFilterProps {
const PartnersFilter: React.FC<PartnersFilterProps> = ({ state, dispatchPartnersActions }) => {
const searchByName = param =>
dispatchPartnersActions({ type: partnersActions.UPDATE_COMPANY_NAME, payload: param })

const activeNetwork = useAppSelector(getActiveNetwork)
const { data } = useIsPartnerQuery({
cChainAddress: store?.state?.activeWallet?.ethAddress
? '0x' + store?.state?.activeWallet?.ethAddress
: '',
})
const partnerCChainAddress = useMemo(() => {
let cAddress = data?.attributes?.cChainAddresses.find(
elem => elem.Network === activeNetwork?.name?.toLowerCase(),
)
if (cAddress) return cAddress
return ''
}, [data])
const auth = useAppSelector(state => state.appConfig.isAuth)
return (
<Box
sx={{
Expand Down Expand Up @@ -76,28 +95,30 @@ const PartnersFilter: React.FC<PartnersFilterProps> = ({ state, dispatchPartners
/>
</Box>
</Box>
<Box
sx={{
flex: '1',
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'flex-start',
}}
>
<Button
variant="contained"
component="a"
href={REGISTER_PARTNER_URL}
target="_blank"
rel="noopener noreferrer"
{(!auth || !partnerCChainAddress) && (
<Box
sx={{
whiteSpace: 'nowrap',
minWidth: 'max-content',
flex: '1',
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'flex-start',
}}
>
Register as Partner
</Button>
</Box>
<Button
variant="contained"
component="a"
href={REGISTER_PARTNER_URL}
target="_blank"
rel="noopener noreferrer"
sx={{
whiteSpace: 'nowrap',
minWidth: 'max-content',
}}
>
Register as Partner
</Button>
</Box>
)}
</Box>
)
}
Expand Down
37 changes: 14 additions & 23 deletions src/views/partners/Partner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,24 @@ const Partner = () => {
useEffect(() => {
if (activeNetwork) refetch()
}, [activeNetwork])
const chackValidatorStatus = async (address: string) => {
if (!partner.attributes.pChainAddress) setIsValidator(false)

const partnerPChainAddress = useMemo(() => {
let pAddress = partner?.attributes?.pChainAddresses.find(
elem => elem.Network === activeNetwork?.name?.toLowerCase(),
)?.pAddress
if (pAddress) return pAddress
return ''
}, [partner, validators])

const chackValidatorStatus = async (address?: string) => {
if (partnerPChainAddress) setIsValidator(false)
let nodeID = await getRegisteredNode(getAddress(address))
setIsValidator(!!validators.find(v => v.nodeID === nodeID))
}

useEffect(() => {
if (partner?.attributes.pChainAddress)
chackValidatorStatus(partner.attributes.pChainAddress)
}, [partner, validators])
if (partnerPChainAddress) chackValidatorStatus(partnerPChainAddress)
}, [partnerPChainAddress])

if (error || (!partner && !isFetching && !isLoading)) {
navigate('/partners')
Expand Down Expand Up @@ -523,23 +531,6 @@ const Partner = () => {
}}
>
<Typography variant="h3">{partner.attributes.companyName}</Typography>
{/* the badge validator will be added when the api support getting p-chain
address */}
{/* {!!isConsortiumMember && (
<Box
sx={{
background: theme => theme.palette.background.gradient,
padding: '10px 14px 8px 12px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
borderRadius: theme => theme.shape.borderRadius,
width: 'fit-content',
}}
>
<Typography sx={{ color: 'common.white' }}>Validator</Typography>
</Box>
)} */}
</Box>
<Box sx={{ display: 'flex', alignItems: 'center', gap: '12px' }}>
{!!isValidator && (
Expand All @@ -564,7 +555,7 @@ const Partner = () => {
</Typography>
</Box>
)}
{partner.contractAddress && (
{!!partner.contractAddress && (
<Box
sx={{
width: '129px',
Expand Down
Loading