Skip to content

Commit f63197c

Browse files
committed
fix explorer
1 parent 089d838 commit f63197c

File tree

9 files changed

+126
-96
lines changed

9 files changed

+126
-96
lines changed

packages/data-layer/src/data-layer.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959
getRoundsForManagerByAddress,
6060
getDirectDonationsByProjectId,
6161
} from "./queries";
62-
import { mergeCanonicalAndLinkedProjects } from "./utils";
62+
import { mergeCanonicalAndLinkedProjects, orderByMapping } from "./utils";
6363
import {
6464
AttestationService,
6565
type MintingAttestationIdsData,
@@ -329,13 +329,16 @@ export class DataLayer {
329329
async getPaginatedProjects({
330330
first,
331331
offset,
332+
chainIds,
332333
}: {
333334
first: number;
334335
offset: number;
336+
chainIds: number[];
335337
}): Promise<v2Project[]> {
336338
const requestVariables = {
337339
first,
338340
offset,
341+
chainIds,
339342
};
340343

341344
const response: { projects: v2Project[] } = await request(
@@ -344,11 +347,7 @@ export class DataLayer {
344347
requestVariables,
345348
);
346349

347-
const projects: v2Project[] = mergeCanonicalAndLinkedProjects(
348-
response.projects,
349-
);
350-
351-
return projects;
350+
return response.projects;
352351
}
353352

354353
/**
@@ -363,28 +362,27 @@ export class DataLayer {
363362
searchTerm,
364363
first,
365364
offset,
365+
chainIds,
366366
}: {
367367
searchTerm: string;
368368
first: number;
369369
offset: number;
370+
chainIds: number[];
370371
}): Promise<v2Project[]> {
371372
const requestVariables = {
372-
searchTerm,
373+
searchTerm: `(?i)`.concat(searchTerm.replace(/^['"]|['"]$/g, "")),
373374
first,
374375
offset,
376+
chainIds,
375377
};
376378

377-
const response: { searchProjects: v2Project[] } = await request(
379+
const response: { projects: v2Project[] } = await request(
378380
this.gsIndexerEndpoint,
379381
getProjectsBySearchTerm,
380382
requestVariables,
381383
);
382384

383-
const projects: v2Project[] = mergeCanonicalAndLinkedProjects(
384-
response.searchProjects,
385-
);
386-
387-
return projects;
385+
return response.projects;
388386
}
389387

390388
/**
@@ -503,12 +501,12 @@ export class DataLayer {
503501

504502
const applicationToFilter = (r: ExpandedApplicationRef): string => {
505503
return `{
506-
and: {
507-
chainId: { equalTo: ${r.chainId} }
504+
_and: {
505+
chainId: { _eq: ${r.chainId} }
508506
roundId: {
509-
equalTo: "${r.roundId}"
507+
_eq: "${r.roundId}"
510508
}
511-
id: { equalTo: "${r.id}" }
509+
id: { _eq: "${r.id}" }
512510
}
513511
}`;
514512
};
@@ -520,9 +518,9 @@ export class DataLayer {
520518
applications(
521519
first: 300
522520
filter: {
523-
and: [
524-
{ status: { equalTo: APPROVED } },
525-
{ or: [ ${filters} ] }
521+
_and: [
522+
{ status: { _eq: APPROVED } },
523+
{ _or: [ ${filters} ] }
526524
]
527525
}
528526
) {
@@ -790,7 +788,7 @@ export class DataLayer {
790788
this.gsIndexerEndpoint,
791789
getDonationsByDonorAddress,
792790
{
793-
address: address.toLowerCase(),
791+
address: getAddress(address),
794792
chainIds,
795793
},
796794
);
@@ -948,13 +946,13 @@ export class DataLayer {
948946
query?: string | undefined;
949947
}): Promise<{ rounds: RoundGetRound[] }> {
950948
return await request(this.gsIndexerEndpoint, getRoundsQuery, {
951-
orderBy: orderBy ?? "NATURAL",
952-
chainIds,
953949
first,
950+
orderBy: orderByMapping[orderBy ?? "NATURAL"],
954951
filter: whitelistedPrograms
955952
? {
956953
...filter,
957-
projectId: { in: whitelistedPrograms },
954+
projectId: { _in: whitelistedPrograms },
955+
chainId: { _in: chainIds },
958956
}
959957
: filter,
960958
});

packages/data-layer/src/data.types.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -531,38 +531,38 @@ export interface Round {
531531
}
532532

533533
export type TimeFilter = {
534-
greaterThan?: string;
535-
lessThan?: string;
536-
greaterThanOrEqualTo?: string;
537-
lessThanOrEqualTo?: string;
538-
isNull?: boolean;
534+
_gt?: string;
535+
_lt?: string;
536+
_gte?: string;
537+
_lte?: string;
538+
_isNull?: boolean;
539539
};
540540

541541
export type TimeFilterVariables = {
542542
applicationsStartTime?: TimeFilter;
543543
applicationsEndTime?: TimeFilter;
544544
donationsStartTime?: TimeFilter;
545545
donationsEndTime?: TimeFilter;
546-
or?: TimeFilterVariables[];
546+
_or?: TimeFilterVariables[];
547547
};
548548

549549
export type RoundsQueryVariables = {
550550
first?: number;
551551
orderBy?: OrderByRounds;
552552
filter?: {
553-
and: (
554-
| { or: TimeFilterVariables[] }
555-
| { or: { strategyName: { in: string[] } } }
553+
_and: (
554+
| { _or: TimeFilterVariables[] }
555+
| { _or: { strategyName: { _in: string[] } } }
556556
| {
557-
or: {
557+
_or: {
558558
chainId: {
559559
in: number[];
560560
};
561561
};
562562
}
563563
| {
564564
tags: {
565-
contains: "allo-v1" | "allo-v2";
565+
_contains: "allo-v1" | "allo-v2";
566566
};
567567
}
568568
)[];

packages/data-layer/src/queries.ts

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -457,30 +457,14 @@ export const getProjectsByAddress = gql`
457457
* @returns The v2Projects
458458
*/
459459
export const getPaginatedProjects = gql`
460-
query getPaginatedProjects($first: Int!, $offset: Int!) {
460+
query getPaginatedProjects($first: Int!, $offset: Int!, $chainIds: [Int!]!) {
461461
projects(
462462
where: {
463463
metadata: { _isNull: false }
464464
tags: { _contains: "allo-v2" }
465465
_not: { tags: { _contains: "program" } }
466-
chainId: {
467-
_in: [
468-
1
469-
137
470-
10
471-
324
472-
42161
473-
42220
474-
43114
475-
534352
476-
8453
477-
1329
478-
100
479-
42
480-
1088
481-
]
482-
}
483-
//TODO: Not sure if removing rounds filter is correct
466+
chainId: { _in: $chainIds }
467+
projectType: { _eq: "canonical" }
484468
}
485469
limit: $first
486470
offset: $offset
@@ -513,34 +497,17 @@ export const getProjectsBySearchTerm = gql`
513497
$searchTerm: String!
514498
$first: Int!
515499
$offset: Int!
500+
$chainIds: [Int!]!
516501
) {
517-
searchProjects(
518-
args: { search_term: $searchTerm }
502+
projects(
519503
limit: $first
520504
offset: $offset
521505
where: {
522-
metadata: { _isNull: false }
506+
metadata: { _isNull: false, _cast: { String: { _regex: $searchTerm } } }
523507
tags: { _contains: "allo-v2" }
524508
_not: { tags: { _contains: "program" } }
525-
chainId: {
526-
_in: [
527-
1
528-
137
529-
10
530-
324
531-
42161
532-
42220
533-
43114
534-
534352
535-
8453
536-
1329
537-
100
538-
42
539-
1088
540-
]
541-
}
542-
//TODO: Not sure if removing rounds filter is correct
543-
509+
chainId: { _in: $chainIds }
510+
projectType: { _eq: "canonical" }
544511
}
545512
) {
546513
id

packages/data-layer/src/utils.ts

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RoundCategory, RoundPayoutType, v2Project } from ".";
1+
import { OrderByRounds, RoundCategory, RoundPayoutType, v2Project } from ".";
22

33
/**
44
* Merges canonical and linked projects into a single array of projects
@@ -54,3 +54,62 @@ export const strategyNameToCategory = (
5454
throw new Error(`Unknown round strategy: ${name}`);
5555
}
5656
};
57+
58+
export const orderByMapping: Record<
59+
OrderByRounds,
60+
{ [key: string]: "ASC" | "DESC" }
61+
> = {
62+
NATURAL: {},
63+
ID_ASC: { id: "ASC" },
64+
ID_DESC: { id: "DESC" },
65+
CHAIN_ID_ASC: { chainId: "ASC" },
66+
CHAIN_ID_DESC: { chainId: "DESC" },
67+
TAGS_ASC: { tags: "ASC" },
68+
TAGS_DESC: { tags: "DESC" },
69+
MATCH_AMOUNT_ASC: { matchAmount: "ASC" },
70+
MATCH_AMOUNT_DESC: { matchAmount: "DESC" },
71+
MATCH_TOKEN_ADDRESS_ASC: { matchTokenAddress: "ASC" },
72+
MATCH_TOKEN_ADDRESS_DESC: { matchTokenAddress: "DESC" },
73+
MATCH_AMOUNT_IN_USD_ASC: { matchAmountInUsd: "ASC" },
74+
MATCH_AMOUNT_IN_USD_DESC: { matchAmountInUsd: "DESC" },
75+
APPLICATION_METADATA_CID_ASC: { applicationMetadataCid: "ASC" },
76+
APPLICATION_METADATA_CID_DESC: { applicationMetadataCid: "DESC" },
77+
APPLICATION_METADATA_ASC: { applicationMetadata: "ASC" },
78+
APPLICATION_METADATA_DESC: { applicationMetadata: "DESC" },
79+
ROUND_METADATA_CID_ASC: { roundMetadataCid: "ASC" },
80+
ROUND_METADATA_CID_DESC: { roundMetadataCid: "DESC" },
81+
ROUND_METADATA_ASC: { roundMetadata: "ASC" },
82+
ROUND_METADATA_DESC: { roundMetadata: "DESC" },
83+
APPLICATIONS_START_TIME_ASC: { applicationsStartTime: "ASC" },
84+
APPLICATIONS_START_TIME_DESC: { applicationsStartTime: "DESC" },
85+
APPLICATIONS_END_TIME_ASC: { applicationsEndTime: "ASC" },
86+
APPLICATIONS_END_TIME_DESC: { applicationsEndTime: "DESC" },
87+
DONATIONS_START_TIME_ASC: { donationsStartTime: "ASC" },
88+
DONATIONS_START_TIME_DESC: { donationsStartTime: "DESC" },
89+
DONATIONS_END_TIME_ASC: { donationsEndTime: "ASC" },
90+
DONATIONS_END_TIME_DESC: { donationsEndTime: "DESC" },
91+
CREATED_AT_BLOCK_ASC: { createdAtBlock: "ASC" },
92+
CREATED_AT_BLOCK_DESC: { createdAtBlock: "DESC" },
93+
UPDATED_AT_BLOCK_ASC: { updatedAtBlock: "ASC" },
94+
UPDATED_AT_BLOCK_DESC: { updatedAtBlock: "DESC" },
95+
MANAGER_ROLE_ASC: { managerRole: "ASC" },
96+
MANAGER_ROLE_DESC: { managerRole: "DESC" },
97+
ADMIN_ROLE_ASC: { adminRole: "ASC" },
98+
ADMIN_ROLE_DESC: { adminRole: "DESC" },
99+
STRATEGY_ADDRESS_ASC: { strategyAddress: "ASC" },
100+
STRATEGY_ADDRESS_DESC: { strategyAddress: "DESC" },
101+
STRATEGY_ID_ASC: { strategyId: "ASC" },
102+
STRATEGY_ID_DESC: { strategyId: "DESC" },
103+
STRATEGY_NAME_ASC: { strategyName: "ASC" },
104+
STRATEGY_NAME_DESC: { strategyName: "DESC" },
105+
PROJECT_ID_ASC: { projectId: "ASC" },
106+
PROJECT_ID_DESC: { projectId: "DESC" },
107+
TOTAL_AMOUNT_DONATED_IN_USD_ASC: { totalAmountDonatedInUsd: "ASC" },
108+
TOTAL_AMOUNT_DONATED_IN_USD_DESC: { totalAmountDonatedInUsd: "DESC" },
109+
TOTAL_DONATIONS_COUNT_ASC: { totalDonationsCount: "ASC" },
110+
TOTAL_DONATIONS_COUNT_DESC: { totalDonationsCount: "DESC" },
111+
UNIQUE_DONORS_COUNT_ASC: { uniqueDonorsCount: "ASC" },
112+
UNIQUE_DONORS_COUNT_DESC: { uniqueDonorsCount: "DESC" },
113+
PRIMARY_KEY_ASC: { id: "ASC" },
114+
PRIMARY_KEY_DESC: { id: "DESC" },
115+
};

packages/grant-explorer/src/app/wagmi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { providers } from "ethers";
77
import { type Account, type Chain, type Client, type Transport } from "viem";
88
import { Connector } from "wagmi";
99

10-
const allChains: RChain[] =
10+
export const allChains: RChain[] =
1111
process.env.REACT_APP_ENV === "development" ? allNetworks : mainnetNetworks;
1212

1313
/* TODO: remove hardcoded value once we have environment variables validation */

packages/grant-explorer/src/features/discovery/ExploreProjectsPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export function ExploreProjectsPage(): JSX.Element {
3939
dataLayer
4040
);
4141

42+
console.log("===> projects", projects);
43+
console.log("===> projectsFromSearch", projectsFromSearch);
44+
4245
const onQueryChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
4346
const q = e.target.value;
4447
setSearchInput(q);

packages/grant-explorer/src/features/discovery/hooks/useFilterRounds.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,30 @@ const createRoundWhereFilter = (
116116
// @ts-expect-error TS thinks that some of the items can be undefined,
117117
// even though they can't, because they are filtered out down the line
118118
// so we ignore the error here
119-
and: [
119+
_and: [
120120
// Find rounds that match both statusFilter and round type
121-
{ or: statusFilter },
121+
{ _or: statusFilter },
122122
{
123123
...(strategyNames.length > 0 && {
124-
or: {
125-
strategyName: { in: strategyNames },
124+
_or: {
125+
strategyName: { _in: strategyNames },
126126
},
127127
}),
128128
},
129129
{
130130
...(chainIds.length > 0 && {
131-
or: {
131+
_or: {
132132
chainId: {
133-
in: chainIds,
133+
_in: chainIds,
134134
},
135135
},
136136
}),
137137
},
138138
{
139139
...(version && {
140-
or: {
140+
_or: {
141141
tags: {
142-
contains: version,
142+
_contains: version,
143143
},
144144
},
145145
}),

0 commit comments

Comments
 (0)