Skip to content

Commit

Permalink
fix(partnerConfig): fix fetchPartnerData query to prevent undefined U…
Browse files Browse the repository at this point in the history
…RL error
  • Loading branch information
aeddaqqa committed Sep 30, 2024
1 parent 70ae509 commit 2e474b6
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/redux/services/partners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,16 @@ const getBaseUrl = () => {
const currentPath = typeof window !== 'undefined' ? window.location.hostname : ''
if (currentPath === 'localhost' || currentPath.includes('dev')) {
return BASE_URLS.dev
} else if (currentPath) {
return BASE_URLS.prod
} else {
return BASE_URLS.prod
}
}

export const partnersApi = createApi({
baseQuery: fetchBaseQuery({
baseUrl: '',
}),
reducerPath: 'partnersApi',
baseQuery: fetchBaseQuery({ baseUrl: '/' }),
endpoints: build => ({
listPartners: build.query<any, StatePartnersType>({
query: ({ page, companyName, businessField, validators, onMessenger }) => {
Expand Down Expand Up @@ -296,20 +297,26 @@ export const partnersApi = createApi({
{ companyName: string; cChainAddress?: string }
>({
query: ({ companyName, cChainAddress }) => {
const baseUrl = getBaseUrl()
if (!baseUrl) {
throw new Error('Base URL is undefined')
}

let query =
'?populate=*&sort[0]=companyName:asc&pagination[page]=1&pagination[pageSize]=12'

if (cChainAddress) {
const baseUrl = getBaseUrl()
const selectedNetwork = store.getters['Network/selectedNetwork']
let query =
'?populate=*&sort[0]=companyName:asc&pagination[page]=1&pagination[pageSize]=12'
if (!selectedNetwork) {
throw new Error('Selected network is undefined')
}
query += `&filters[$and][0][cChainAddresses][cAddress][$containsi]=${cChainAddress}&filters[$and][1][cChainAddresses][Network][$eq]=${selectedNetwork.name.toLowerCase()}`
return `${baseUrl}${query}`
}
if (companyName) {
const baseUrl = getBaseUrl()
let query =
'?populate=*&sort[0]=companyName:asc&pagination[page]=1&pagination[pageSize]=12'
} else if (companyName) {
query += `&filters[companyName][$contains]=${companyName}`
return `${baseUrl}${query}`
}
return {
url: `${baseUrl}${query}`,
method: 'GET',
}
},
async transformResponse(response: PartnersResponseType, _meta, arg) {
Expand Down

0 comments on commit 2e474b6

Please sign in to comment.