diff --git a/src/components/Partners/PartnerCard.tsx b/src/components/Partners/PartnerCard.tsx index 34da1523..a1e4b51a 100644 --- a/src/components/Partners/PartnerCard.tsx +++ b/src/components/Partners/PartnerCard.tsx @@ -1,9 +1,11 @@ import { Box, Typography } from '@mui/material' import React, { useEffect, useState } from 'react' -import { PartnerDataType, Validator } from '../../@types/partners' +import { PartnerDataType } from '../../@types/partners' +import { useAppSelector } from '../../hooks/reduxHooks' import { useEffectOnce } from '../../hooks/useEffectOnce' import useWallet from '../../hooks/useWallet' +import { selectValidators } from '../../redux/slices/app-config' import PartnerBusinessFields from './PartnerBusinessFields' import PartnerFlag from './PartnerFlag' import PartnerLogo from './PartnerLogo' @@ -13,17 +15,17 @@ interface PartnerCardProps { clickable: boolean partner: PartnerDataType index: number - validators: Validator[] } -const PartnerCard: React.FC = ({ partner, clickable, onClick, validators }) => { +const PartnerCard: React.FC = ({ partner, clickable, onClick }) => { useEffectOnce(() => {}) const { getRegisteredNode } = useWallet() const [isValidator, setIsValidator] = useState(false) - + const validators = useAppSelector(selectValidators) + const { getAddress } = useWallet() const chackValidatorStatus = async (address: string) => { if (!pChainAddress) setIsValidator(false) - let nodeID = await getRegisteredNode(address) + let nodeID = await getRegisteredNode(getAddress(address)) setIsValidator(!!validators.find(v => v.nodeID === nodeID)) } const { @@ -38,8 +40,8 @@ const PartnerCard: React.FC = ({ partner, clickable, onClick, }, } = partner useEffect(() => { - chackValidatorStatus(pChainAddress) - }, [partner]) + if (pChainAddress) chackValidatorStatus(pChainAddress) + }, [partner, validators]) return ( void @@ -73,6 +74,7 @@ const useNetwork = (): { severity: 'success', }), ) + dispatch(getCurrentValidators()) localStorage.setItem('selectedNetwork', network.name.toLowerCase()) } catch (e) { store.state.Network.selectedNetwork = null diff --git a/src/hooks/useWallet.ts b/src/hooks/useWallet.ts index 8de5f7f8..6ff9779e 100644 --- a/src/hooks/useWallet.ts +++ b/src/hooks/useWallet.ts @@ -6,12 +6,18 @@ 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 getAddress = address => { + if (address) { + let res = caminoClient + .PChain() + .addressFromBuffer(caminoClient.PChain().parseAddress(address)) + return res + } + return '' + } const updateStore = (type, params) => { switch (type) { case 'updateName': @@ -23,7 +29,7 @@ const useWallet = () => { ) } } - return { updateStore, getRegisteredNode, getCurrentValidators } + return { updateStore, getRegisteredNode, getAddress } } export default useWallet diff --git a/src/layout/MainLayout.tsx b/src/layout/MainLayout.tsx index d04cdef6..94bf6e9e 100644 --- a/src/layout/MainLayout.tsx +++ b/src/layout/MainLayout.tsx @@ -30,7 +30,6 @@ import { useEffectOnce } from '../hooks/useEffectOnce' 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) @@ -67,7 +66,6 @@ const MainLayout = ({ children }) => { useEffectOnce(() => { init() }) - dispatch(getCurrentValidators()) useEffect(() => { const html = document.documentElement if (loading || loadNetworks) html.style.overflow = 'hidden' diff --git a/src/redux/slices/utils.ts b/src/redux/slices/utils.ts index c3791846..aa06b7cc 100644 --- a/src/redux/slices/utils.ts +++ b/src/redux/slices/utils.ts @@ -1,5 +1,5 @@ import { createAsyncThunk } from '@reduxjs/toolkit' -import useWallet from '../../hooks/useWallet' +import { ava as caminoClient } from 'wallet/caminoClient' export const updateAuthStatus = createAsyncThunk( 'appConfig/updateAuthStatus', @@ -12,8 +12,7 @@ export const updateAuthStatus = createAsyncThunk( ) export const getCurrentValidators = createAsyncThunk('appConfig/getCurrentValidators', async () => { - const { getCurrentValidators } = useWallet() try { - return (await getCurrentValidators()).validators + return (await caminoClient.PChain().getCurrentValidators()).validators } catch (e) {} }) diff --git a/src/views/partners/ListPartners.tsx b/src/views/partners/ListPartners.tsx index 7860d37b..64615a4c 100644 --- a/src/views/partners/ListPartners.tsx +++ b/src/views/partners/ListPartners.tsx @@ -1,11 +1,11 @@ import { PartnersResponseType } from '../../@types/partners' import { Box } from '@mui/material' -import React from 'react' +import React, { useEffect } from 'react' import { useNavigate } from 'react-router' import PartnerCard from '../../components/Partners/PartnerCard' -import { useAppSelector } from '../../hooks/reduxHooks' -import { selectValidators } from '../../redux/slices/app-config' +import { useAppDispatch } from '../../hooks/reduxHooks' +import { getCurrentValidators } from '../../redux/slices/utils' interface ListPartnersProps { partners: PartnersResponseType @@ -13,7 +13,10 @@ interface ListPartnersProps { const ListPartners: React.FC = ({ partners }) => { const navigate = useNavigate() - const validators = useAppSelector(selectValidators) + const dispatch = useAppDispatch() + useEffect(() => { + dispatch(getCurrentValidators()) + }, []) return ( = ({ partners }) => { > {partners.data.map((partner, index) => ( { if ( !!( @@ -42,7 +44,7 @@ const ListPartners: React.FC = ({ partners }) => { } }} partner={partner} - key={index} + key={partner.attributes.companyName} clickable={ !!( partner.attributes.companyName && diff --git a/src/views/partners/Partner.tsx b/src/views/partners/Partner.tsx index f8138f72..79f76639 100644 --- a/src/views/partners/Partner.tsx +++ b/src/views/partners/Partner.tsx @@ -52,19 +52,7 @@ const Partner = () => { companyName: partnerID, }) const navigate = useNavigate() - if ( - error || - !partner || - !!( - partner.attributes.companyName && - partner.attributes.companyLongDescription && - partner.attributes.companyWebsite && - partner.attributes.contactEmail && - partner.attributes.contactFirstname && - partner.attributes.contactLastname && - partner.attributes.contactPhone - ) - ) { + if (error || (!partner && !isFetching && !isLoading)) { navigate('/partners') return null }