From a044278419c38e0f41c70c8ba0a500953f23bc87 Mon Sep 17 00:00:00 2001 From: aeddaqqa Date: Thu, 26 Sep 2024 00:47:37 +0100 Subject: [PATCH] fix(partnerConfig): fix fetching partners on messenger and matchig partners --- src/helpers/usePartnerConfig.tsx | 10 ++++++---- src/helpers/useSmartContract.tsx | 17 +++++++++++++++-- src/redux/services/partners.ts | 16 +++++++--------- src/views/partners/ConfigurDistrubitor.tsx | 15 +++++++++++++-- src/views/partners/ConfigurSupplier.tsx | 12 ++++++++++-- src/views/partners/ManageBots.tsx | 17 ++++++++++++++--- src/views/settings/Links.tsx | 2 +- 7 files changed, 66 insertions(+), 23 deletions(-) diff --git a/src/helpers/usePartnerConfig.tsx b/src/helpers/usePartnerConfig.tsx index b1474a08..f6b82713 100644 --- a/src/helpers/usePartnerConfig.tsx +++ b/src/helpers/usePartnerConfig.tsx @@ -1,6 +1,7 @@ import { ethers } from 'ethers' import { useCallback, useEffect } from 'react' -import { useAppDispatch } from '../hooks/reduxHooks' +import { useAppDispatch, useAppSelector } from '../hooks/reduxHooks' +import { getActiveNetwork } from '../redux/slices/network' import { updateCMAcocuntContract } from '../redux/slices/partner' import { useSmartContract } from './useSmartContract' @@ -17,7 +18,8 @@ export const usePartnerConfig = () => { CMAccountCreated, accountReadContract, } = useSmartContract() - + const activeNetwork = useAppSelector(getActiveNetwork) + const auth = useAppSelector(state => state.appConfig.isAuth) const dispatch = useAppDispatch() async function CreateConfiguration(state) { @@ -142,8 +144,8 @@ export const usePartnerConfig = () => { }, [account, managerReadContract]) useEffect(() => { - if (wallet) isCMAccount() - }, [wallet]) + if (wallet && auth) isCMAccount() + }, [wallet, activeNetwork]) const addServices = useCallback( async services => { diff --git a/src/helpers/useSmartContract.tsx b/src/helpers/useSmartContract.tsx index 3282479b..f902f7a2 100644 --- a/src/helpers/useSmartContract.tsx +++ b/src/helpers/useSmartContract.tsx @@ -7,6 +7,7 @@ import React, { useEffect, useState, } from 'react' +import { useNavigate } from 'react-router' import store from 'wallet/store' import { CONTRACTCMACCOUNTMANAGERADDRESSCAMINO, @@ -143,13 +144,25 @@ export const SmartContractProvider: React.FC = ({ ch console.error('User denied account access:', error) } } - + const navigate = useNavigate() + const path = window.location.pathname useEffect(() => { if ( activeNetwork.name.toLowerCase() === 'columbus' || activeNetwork.name.toLowerCase() === 'camino' - ) + ) { + setAccountReadContract(null) + setAccountWriteContract(null) + if ( + contractCMAccountAddress && + (path.includes('partners/messenger-configuration/supplier') || + path.includes('partners/messenger-configuration/distribution') || + path.includes('partners/messenger-configuration/bots')) + ) + navigate('/partners/messenger-configuration/mydetails') + setContractCMAccountAddress('') initializeEthers() + } }, [activeNetwork, auth]) useEffect(() => { diff --git a/src/redux/services/partners.ts b/src/redux/services/partners.ts index 1e41f1ec..d427f966 100644 --- a/src/redux/services/partners.ts +++ b/src/redux/services/partners.ts @@ -141,11 +141,7 @@ function getServiceName(fullName: unknown): string { const getBaseUrl = () => { const currentPath = typeof window !== 'undefined' ? window.location.hostname : '' - if ( - currentPath === 'localhost' || - currentPath.includes('dev') || - currentPath.includes('stage') - ) { + if (currentPath === 'localhost' || currentPath.includes('dev')) { return BASE_URLS.dev } else { return BASE_URLS.prod @@ -163,7 +159,7 @@ export const partnersApi = createApi({ let query = '?populate=*' - if (!isNaN(page)) { + if (!isNaN(page) && !onMessenger) { query += `&sort[0]=companyName:asc&pagination[page]=${page}&pagination[pageSize]=12` } if (businessField) { @@ -184,7 +180,7 @@ export const partnersApi = createApi({ } // Only add the cChainAddress filter if onMessenger is explicitly true if (onMessenger === true) { - query += `&filters[cChainAddress][$ne]=null` + query += `&sort[0]=companyName:asc&_limit=-1&filters[cChainAddress][$ne]=null` } return { @@ -283,7 +279,9 @@ export const partnersApi = createApi({ ...response.meta, pagination: { ...response.meta.pagination, - // total: filteredPartners.length, + total: onMessenger + ? filteredPartners.length + : response.meta.pagination.total, }, } @@ -389,7 +387,7 @@ export const partnersApi = createApi({ let query = '?populate=*' if (!isNaN(page)) { - query += `&sort[0]=companyName:asc&pagination[page]=${page}&pagination[pageSize]=12` + query += `&sort[0]=companyName:asc&_limit=-1` } if (businessField) { let filterWith = businessField diff --git a/src/views/partners/ConfigurDistrubitor.tsx b/src/views/partners/ConfigurDistrubitor.tsx index 0c7dd084..dcb0c1a4 100644 --- a/src/views/partners/ConfigurDistrubitor.tsx +++ b/src/views/partners/ConfigurDistrubitor.tsx @@ -15,7 +15,7 @@ import { } from '@mui/material' import { ethers } from 'ethers' import React, { useEffect, useMemo, useReducer, useState } from 'react' -import { useParams } from 'react-router' +import { useNavigate, useParams } from 'react-router' import MainButton from '../../components/MainButton' import UpdatedSelectComponent from '../../components/Partners/UpdatedSelectComponent' import { @@ -151,6 +151,7 @@ export const BasicWantedServices = () => { const { data: partner } = useFetchPartnerDataQuery({ companyName: partnerID, }) + const navigate = useNavigate() useEffect(() => { if (partner) dispatchDistrubitorState({ @@ -158,6 +159,9 @@ export const BasicWantedServices = () => { payload: { wantedServices: partner.wantedServices, reset: true }, }) }, [partner]) + if (!partner) return <> + + if (partner && !partner.contractAddress) navigate('/partners') return ( { > Wanted Services + + This page lists all Wanted Services by this partner. A Wanted Service is a + service this partner is looking to buy. + {/*
*/} + {/* {supplierState.stepsConfig[1].services.length === 0 && ( + <> No bot addresses are currently registered with this Messenger Account. + )} */} +
{ disabled={true} /> -
) diff --git a/src/views/partners/ConfigurSupplier.tsx b/src/views/partners/ConfigurSupplier.tsx index 8ca68ed9..c2861d5b 100644 --- a/src/views/partners/ConfigurSupplier.tsx +++ b/src/views/partners/ConfigurSupplier.tsx @@ -15,7 +15,7 @@ import { } from '@mui/material' import { ethers } from 'ethers' import React, { useEffect, useMemo, useReducer, useState } from 'react' -import { useParams } from 'react-router' +import { useNavigate, useParams } from 'react-router' import MainButton from '../../components/MainButton' import UpdatedSelectComponent from '../../components/Partners/UpdatedSelectComponent' import { @@ -294,6 +294,7 @@ export const BasicSupportedServices = () => { const { data: partner } = useFetchPartnerDataQuery({ companyName: partnerID, }) + const navigate = useNavigate() useEffect(() => { if (partner) { dispatchSupplierState({ @@ -302,6 +303,9 @@ export const BasicSupportedServices = () => { }) } }, [partner]) + if (!partner) return <> + + if (partner && !partner.contractAddress) navigate('/partners') return ( { > Offered Services + + This page lists all Offered Services by this partner. An Offered Service is a + service that this partner is selling, and all the bots run by this partner + support those services. + { dispatch={dispatchSupplierState} /> - ) diff --git a/src/views/partners/ManageBots.tsx b/src/views/partners/ManageBots.tsx index 45e4d584..791e1387 100644 --- a/src/views/partners/ManageBots.tsx +++ b/src/views/partners/ManageBots.tsx @@ -1,7 +1,7 @@ import { Box, Button, CircularProgress, TextField, Typography } from '@mui/material' import { ethers } from 'ethers' import React, { useEffect, useState } from 'react' -import { useParams } from 'react-router' +import { useNavigate, useParams } from 'react-router' import Alert from '../../components/Alert' import { usePartnerConfig } from '../../helpers/usePartnerConfig' import { useAppDispatch } from '../../hooks/reduxHooks' @@ -14,6 +14,10 @@ export const BasicManageBots = () => { const { data: partner } = useFetchPartnerDataQuery({ companyName: partnerID, }) + const navigate = useNavigate() + if (!partner) return <> + + if (partner && !partner?.contractAddress) navigate('/partners') return ( { }} > - Manage Bots + Bots - List in this page the addresses of all bots using this Messenger Account. + This page lists all bot addresses registered to this Messenger Account. + {partner && partner.bots && partner?.bots?.length === 0 && ( + <> +
+
+ No bot addresses are currently registered with this Messenger Account. + + )}
{partner.bots && partner.bots.length > 0 && diff --git a/src/views/settings/Links.tsx b/src/views/settings/Links.tsx index 2b406505..90b94a59 100644 --- a/src/views/settings/Links.tsx +++ b/src/views/settings/Links.tsx @@ -43,7 +43,7 @@ export default function Links({ type = 'else', partner }: { type?: string; partn else if (path.includes('bots')) setSecondValue(4) else setSecondValue(0) } else setValue(0) - dispatch(changeActiveApp('Network')) + if (!path.includes('partners')) dispatch(changeActiveApp('Network')) }, [path]) // eslint-disable-line react-hooks/exhaustive-deps const auth = useAppSelector(state => state.appConfig.isAuth) const sc = useSmartContract()