From 6b68800e755ff11ae8d04d0c2c6f15c2a6379413 Mon Sep 17 00:00:00 2001 From: aeddaqqa Date: Mon, 30 Sep 2024 16:51:57 +0100 Subject: [PATCH] fix(partnerConfig): added check for CMaccount created and claim profile --- src/components/Partners/PartnerCard.tsx | 2 +- src/helpers/useSmartContract.tsx | 10 +++++----- src/layout/PartnersLayout.tsx | 6 +++--- src/views/landing/LandingPage.tsx | 6 +++--- src/views/partners/MatchingPartners.tsx | 25 +++++++++++++++++++++---- src/views/settings/Links.tsx | 4 ++-- 6 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/components/Partners/PartnerCard.tsx b/src/components/Partners/PartnerCard.tsx index 729ae12d..eb1f0fa3 100644 --- a/src/components/Partners/PartnerCard.tsx +++ b/src/components/Partners/PartnerCard.tsx @@ -47,7 +47,7 @@ const PartnerCard: React.FC = ({ partner, clickable, onClick } useEffect(() => { if (pChainAddresses) { let partnerAddresses = pChainAddresses.find( - elem => elem.Network.toLowerCase() === activeNetwork.name.toLowerCase(), + elem => elem.Network.toLowerCase() === activeNetwork?.name?.toLowerCase(), ) if (partnerAddresses) chackValidatorStatus(partnerAddresses.pAddress) } diff --git a/src/helpers/useSmartContract.tsx b/src/helpers/useSmartContract.tsx index f902f7a2..02798c05 100644 --- a/src/helpers/useSmartContract.tsx +++ b/src/helpers/useSmartContract.tsx @@ -114,12 +114,12 @@ export const SmartContractProvider: React.FC = ({ ch ) try { if ( - activeNetwork.name.toLowerCase() !== 'columbus' && - activeNetwork.name.toLowerCase() !== 'camino' + activeNetwork?.name?.toLowerCase() !== 'columbus' && + activeNetwork?.name?.toLowerCase() !== 'camino' ) return let contractAddress = - activeNetwork.name.toLowerCase() === 'columbus' + activeNetwork?.name?.toLowerCase() === 'columbus' ? CONTRACTCMACCOUNTMANAGERADDRESSCOLUMBUS : CONTRACTCMACCOUNTMANAGERADDRESSCAMINO if (auth) { @@ -148,8 +148,8 @@ export const SmartContractProvider: React.FC = ({ ch const path = window.location.pathname useEffect(() => { if ( - activeNetwork.name.toLowerCase() === 'columbus' || - activeNetwork.name.toLowerCase() === 'camino' + activeNetwork?.name?.toLowerCase() === 'columbus' || + activeNetwork?.name?.toLowerCase() === 'camino' ) { setAccountReadContract(null) setAccountWriteContract(null) diff --git a/src/layout/PartnersLayout.tsx b/src/layout/PartnersLayout.tsx index b84f9081..ff2567cf 100644 --- a/src/layout/PartnersLayout.tsx +++ b/src/layout/PartnersLayout.tsx @@ -104,7 +104,7 @@ const PartnersLayout = () => { const partnerCChainAddress = useMemo(() => { let cAddress = data?.attributes?.cChainAddresses.find( - elem => elem.Network === activeNetwork.name.toLowerCase(), + elem => elem.Network === activeNetwork?.name?.toLowerCase(), ) if (cAddress) return cAddress return '' @@ -113,8 +113,8 @@ const PartnersLayout = () => { if ( path.includes('partners/messenger-configuration') && !store.state.isAuth && - (activeNetwork.name.toLowerCase() !== 'columbus' || - activeNetwork.name.toLowerCase() !== 'camino') + (activeNetwork?.name?.toLowerCase() !== 'columbus' || + activeNetwork?.name?.toLowerCase() !== 'camino') ) { return } diff --git a/src/views/landing/LandingPage.tsx b/src/views/landing/LandingPage.tsx index 6a494f01..de184910 100644 --- a/src/views/landing/LandingPage.tsx +++ b/src/views/landing/LandingPage.tsx @@ -1,12 +1,12 @@ import { Box, Grid, Typography } from '@mui/material' import { changeActiveApp, getAllApps } from '../../redux/slices/app-config' -import LandingPageAppWidget from './LandingPageAppWidget' import React from 'react' -import { getActiveNetwork } from '../../redux/slices/network' -import { useAppSelector } from '../../hooks/reduxHooks' import { useDispatch } from 'react-redux' import { useNavigate } from 'react-router' +import { useAppSelector } from '../../hooks/reduxHooks' +import { getActiveNetwork } from '../../redux/slices/network' +import LandingPageAppWidget from './LandingPageAppWidget' export default function LandingPage() { const activeNetwork = useAppSelector(getActiveNetwork) diff --git a/src/views/partners/MatchingPartners.tsx b/src/views/partners/MatchingPartners.tsx index 4953aae0..4c345521 100644 --- a/src/views/partners/MatchingPartners.tsx +++ b/src/views/partners/MatchingPartners.tsx @@ -1,11 +1,12 @@ import { Box, Typography } from '@mui/material' import React, { useEffect, useMemo } from 'react' import { useNavigate } from 'react-router' +import store from 'wallet/store' import PartnerCard from '../../components/Partners/PartnerCard' import { usePartnerConfigurationContext } from '../../helpers/partnerConfigurationContext' import { useSmartContract } from '../../helpers/useSmartContract' import { useAppSelector } from '../../hooks/reduxHooks' -import { useListMatchingPartnersQuery } from '../../redux/services/partners' +import { useIsPartnerQuery, useListMatchingPartnersQuery } from '../../redux/services/partners' import { getActiveNetwork } from '../../redux/slices/network' const MatchingPartners = ({ state }) => { @@ -21,21 +22,36 @@ const MatchingPartners = ({ state }) => { supportedResult: value?.state?.stepsConfig[1]?.services, wantedResult: value?.state?.stepsConfig[2]?.services, }) + const { data, refetch: refetchIsPartner } = useIsPartnerQuery({ + cChainAddress: store?.state?.activeWallet?.ethAddress + ? '0x' + store?.state?.activeWallet?.ethAddress + : '', + }) const activeNetwork = useAppSelector(getActiveNetwork) const sc = useSmartContract() const matchingPartnersFiltred = useMemo(() => { return partners?.data ? partners?.data?.filter(elem => { let address = elem?.attributes?.cChainAddresses.find( - elem => elem.Network.toLowerCase() === activeNetwork.name.toLowerCase(), + elem => elem.Network.toLowerCase() === activeNetwork?.name?.toLowerCase(), )?.cAddress if (address !== sc?.wallet?.address) return true return false }) : [] }, [partners]) + const partnerCChainAddress = useMemo(() => { + let cAddress = data?.attributes?.cChainAddresses.find( + elem => elem.Network === activeNetwork?.name?.toLowerCase(), + ) + if (cAddress) return cAddress + return '' + }, [data]) useEffect(() => { - if (activeNetwork) refetch() + if (activeNetwork) { + refetch() + refetchIsPartner() + } }, [activeNetwork]) const navigate = useNavigate() if ( @@ -43,7 +59,8 @@ const MatchingPartners = ({ state }) => { isFetching || error || !matchingPartnersFiltred || - matchingPartnersFiltred?.length === 0 + matchingPartnersFiltred?.length === 0 || + !partnerCChainAddress ) return <> return ( diff --git a/src/views/settings/Links.tsx b/src/views/settings/Links.tsx index 90b94a59..917092da 100644 --- a/src/views/settings/Links.tsx +++ b/src/views/settings/Links.tsx @@ -98,8 +98,8 @@ export default function Links({ type = 'else', partner }: { type?: string; partn />, auth && store.state.activeWallet?.type !== 'multisig' && - (activeNetwork.name.toLowerCase() === 'columbus' || - activeNetwork.name.toLowerCase() === 'camino') && ( + (activeNetwork?.name?.toLowerCase() === 'columbus' || + activeNetwork?.name?.toLowerCase() === 'camino') && ( navigate('/partners/messenger-configuration')} className="tab"