Skip to content

Commit 4f88aa2

Browse files
committed
chore: envio-query-migration-scout-v2
1 parent 9f14d20 commit 4f88aa2

File tree

18 files changed

+2531
-2057
lines changed

18 files changed

+2531
-2057
lines changed

websites/app/src/components/Dashboard/RecentActivity.tsx

Lines changed: 244 additions & 214 deletions
Large diffs are not rendered by default.

websites/app/src/consts/index.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
export const EMAIL_REGEX =
2-
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
3-
export const TELEGRAM_REGEX = /^@\w{5,32}$/;
4-
export const ETH_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
5-
export const ETH_SIGNATURE_REGEX = /^0x[a-fA-F0-9]{130}$/;
2+
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
3+
export const TELEGRAM_REGEX = /^@\w{5,32}$/
4+
export const ETH_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/
5+
export const ETH_SIGNATURE_REGEX = /^0x[a-fA-F0-9]{130}$/
66

7-
export const DAPPLOOKER_API_KEY = import.meta.env.REACT_APP_DAPPLOOKER_API_KEY || "";
8-
export const SUBGRAPH_GNOSIS_ENDPOINT = import.meta.env.REACT_APP_SUBGRAPH_GNOSIS_ENDPOINT || "https://api.studio.thegraph.com/query/108432/gtcr-subgraph-gnosis/version/latest";
9-
export const SUBGRAPH_KLEROS_DISPLAY_GNOSIS_ENDPOINT = import.meta.env.REACT_APP_SUBGRAPH_KLEROS_DISPLAY_GNOSIS_ENDPOINT || "https://api.studio.thegraph.com/query/61738/kleros-display-gnosis/version/latest";
7+
export const DAPPLOOKER_API_KEY =
8+
import.meta.env.REACT_APP_DAPPLOOKER_API_KEY || ''
9+
export const SUBGRAPH_GNOSIS_ENDPOINT =
10+
import.meta.env.REACT_APP_SUBGRAPH_GNOSIS_ENDPOINT ||
11+
'https://indexer.hyperindex.xyz/1a2f51c/v1/graphql'
12+
export const SUBGRAPH_KLEROS_DISPLAY_GNOSIS_ENDPOINT =
13+
import.meta.env.REACT_APP_SUBGRAPH_KLEROS_DISPLAY_GNOSIS_ENDPOINT ||
14+
'https://api.studio.thegraph.com/query/61738/kleros-display-gnosis/version/latest'
Lines changed: 131 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import { gql, request } from 'graphql-request';
2-
import { GraphItem } from 'utils/fetchItems';
3-
import { useQuery } from '@tanstack/react-query';
4-
import { SUBGRAPH_GNOSIS_ENDPOINT } from 'consts/index';
5-
import { chains, getNamespaceForChainId } from 'utils/chains';
1+
import { gql, request } from 'graphql-request'
2+
import { GraphItem } from 'utils/fetchItems'
3+
import { useQuery } from '@tanstack/react-query'
4+
import { SUBGRAPH_GNOSIS_ENDPOINT } from 'consts/index'
5+
import { chains, getNamespaceForChainId } from 'utils/chains'
66

77
export interface ExportFilters {
8-
registryId?: string;
9-
status?: string[];
10-
disputed?: boolean[];
11-
fromDate?: string;
12-
toDate?: string;
13-
network?: string[];
14-
text?: string;
8+
registryId?: string
9+
status?: string[]
10+
disputed?: boolean[]
11+
fromDate?: string
12+
toDate?: string
13+
network?: string[]
14+
text?: string
1515
}
1616

1717
export const useExportItems = (filters: ExportFilters) => {
1818
return useQuery<GraphItem[]>({
1919
queryKey: ['exportItems', filters],
2020
enabled: false, // Only fetch when export button is clicked
2121
queryFn: async () => {
22-
let allData: GraphItem[] = [];
23-
const first = 1000;
24-
let skip = 0;
25-
let keepFetching = true;
22+
let allData: GraphItem[] = []
23+
const first = 1000
24+
let skip = 0
25+
let keepFetching = true
2626

2727
const {
2828
registryId,
@@ -31,102 +31,113 @@ export const useExportItems = (filters: ExportFilters) => {
3131
fromDate,
3232
toDate,
3333
network = [],
34-
text = ''
35-
} = filters;
34+
text = '',
35+
} = filters
3636

3737
if (!registryId) {
38-
throw new Error('Registry ID is required for export');
38+
throw new Error('Registry ID is required for export')
3939
}
4040

41-
const isTagsQueriesRegistry = registryId === '0xae6aaed5434244be3699c56e7ebc828194f26dc3';
41+
const isTagsQueriesRegistry =
42+
registryId === '0xae6aaed5434244be3699c56e7ebc828194f26dc3'
4243

4344
// Build network filter
44-
const selectedChainIds = network.filter((id) => id !== 'unknown');
45-
const includeUnknown = network.includes('unknown');
46-
const definedChainIds = chains.map((c) => c.id);
47-
const knownPrefixes = [...new Set(chains.map((chain) => {
48-
if (chain.namespace === 'solana') {
49-
return 'solana:';
50-
}
51-
return `${chain.namespace}:${chain.id}:`;
52-
}))];
45+
const selectedChainIds = network.filter((id) => id !== 'unknown')
46+
const includeUnknown = network.includes('unknown')
47+
const definedChainIds = chains.map((c) => c.id)
48+
const knownPrefixes = [
49+
...new Set(
50+
chains.map((chain) => {
51+
if (chain.namespace === 'solana') {
52+
return 'solana:'
53+
}
54+
return `${chain.namespace}:${chain.id}:`
55+
}),
56+
),
57+
]
5358

54-
let networkQueryObject = '';
59+
let networkQueryObject = ''
5560
if (isTagsQueriesRegistry && network.length > 0) {
5661
const conditions = selectedChainIds.map(
5762
(chainId) =>
58-
`{or: [{metadata_: {key2: "${chainId}"}}, {metadata_: {key1: "${chainId}"}}]}`
59-
);
63+
`{ _or: [{ key2: { _eq: "${chainId}"}}, { key1: { _eq: "${chainId}"}}]}`,
64+
)
6065
if (includeUnknown) {
6166
conditions.push(
62-
`{and: [{metadata_: {key1_not_in: $definedChainIds}}, {metadata_: {key2_not_in: $definedChainIds}}]}`
63-
);
67+
`{ _and: [{ key1: { _nin: $definedChainIds}}, { key2: { _nin: $definedChainIds}}]}`,
68+
)
6469
}
65-
networkQueryObject = conditions.length > 0 ? `{or: [${conditions.join(',')}]}` : '{}';
70+
networkQueryObject =
71+
conditions.length > 0 ? `{_or: [${conditions.join(',')}]}` : '{}'
6672
} else if (network.length > 0) {
6773
const conditions = selectedChainIds.map((chainId) => {
68-
const namespace = getNamespaceForChainId(chainId);
74+
const namespace = getNamespaceForChainId(chainId)
6975
if (namespace === 'solana') {
70-
return `{metadata_: {key0_starts_with_nocase: "solana:"}}`;
76+
return `{key0: { _ilike: "solana:%"}}`
7177
}
72-
return `{metadata_: {key0_starts_with_nocase: "${namespace}:${chainId}:"}}`;
73-
});
74-
networkQueryObject = conditions.length > 0 ? `{or: [${conditions.join(',')}]}` : '{}';
78+
return `{key0: {_ilike: "${namespace}:${chainId}:%"}}`
79+
})
80+
networkQueryObject =
81+
conditions.length > 0 ? `{_or: [${conditions.join(',')}]}` : '{}'
7582
}
7683

7784
// Build text filter
7885
const textFilterObject = text
79-
? `{or: [
80-
{metadata_: {key0_contains_nocase: $text}},
81-
{metadata_: {key1_contains_nocase: $text}},
82-
{metadata_: {key2_contains_nocase: $text}},
83-
{metadata_: {key3_contains_nocase: $text}},
84-
{metadata_: {key4_contains_nocase: $text}}
85-
]}`
86-
: '';
86+
? `{_or: [
87+
{key0: {_ilike: $text}},
88+
{key1: {_ilike: $text}},
89+
{key2: {_ilike: $text}},
90+
{key3: {_ilike: $text}},
91+
{key4: {_ilike: $text}}
92+
]}`
93+
: ''
8794

8895
// Build date filter
89-
let dateFilterObject = '';
96+
let dateFilterObject = ''
9097
if (fromDate || toDate) {
91-
const conditions = [];
98+
const conditions: string[] = []
9299
if (fromDate) {
93-
const fromTimestamp = Math.floor(new Date(fromDate).getTime() / 1000);
94-
conditions.push(`{latestRequestSubmissionTime_gte: "${fromTimestamp}"}`);
100+
const fromTimestamp = Math.floor(new Date(fromDate).getTime() / 1000)
101+
conditions.push(
102+
`{latestRequestSubmissionTime: { _gte: "${fromTimestamp}"}}`,
103+
)
95104
}
96105
if (toDate) {
97-
const toTimestamp = Math.floor(new Date(toDate).getTime() / 1000);
98-
conditions.push(`{latestRequestSubmissionTime_lte: "${toTimestamp}"}`);
106+
const toTimestamp = Math.floor(new Date(toDate).getTime() / 1000)
107+
conditions.push(
108+
`{latestRequestSubmissionTime: {_lte: "${toTimestamp}"}}`,
109+
)
99110
}
100-
dateFilterObject = conditions.length > 0 ? `{and: [${conditions.join(',')}]}` : '';
111+
dateFilterObject =
112+
conditions.length > 0 ? `{_and: [${conditions.join(',')}]}` : ''
101113
}
102114

103115
// Build the complete where clause
104116
const whereConditions = [
105-
`{registry: "${registryId}"}`,
106-
`{status_in: $status}`,
107-
`{disputed_in: $disputed}`,
117+
`{registry_id: {_eq: "${registryId}"}}`,
118+
`{status: {_in: $status}}`,
119+
`{disputed: {_in: $disputed}}`,
108120
networkQueryObject && `${networkQueryObject}`,
109121
textFilterObject && `${textFilterObject}`,
110-
dateFilterObject && `${dateFilterObject}`
111-
].filter(Boolean) as string[];
122+
dateFilterObject && `${dateFilterObject}`,
123+
].filter(Boolean) as string[]
112124

113125
const query = gql`
114126
query (
115-
$status: [String!]!
127+
$status: [status!]!
116128
$disputed: [Boolean!]!
117-
$text: String!
129+
$text: String
118130
$skip: Int!
119131
$first: Int!
120132
${includeUnknown && isTagsQueriesRegistry ? '$definedChainIds: [String!]!' : ''}
121133
) {
122-
litems(
134+
litems: LItem(
123135
where: {
124-
and: [${whereConditions.join(',')}]
136+
_and: [${whereConditions.join(',')}]
125137
}
126-
skip: $skip
127-
first: $first
128-
orderBy: "latestRequestSubmissionTime"
129-
orderDirection: desc
138+
offset: $skip
139+
limit: $first
140+
order_by: {latestRequestSubmissionTime : $orderDirection }
130141
) {
131142
id
132143
latestRequestSubmissionTime
@@ -135,21 +146,19 @@ export const useExportItems = (filters: ExportFilters) => {
135146
status
136147
disputed
137148
data
138-
metadata {
139-
key0
140-
key1
141-
key2
142-
key3
143-
key4
144-
props {
145-
value
146-
type
147-
label
148-
description
149-
isIdentifier
150-
}
149+
key0
150+
key1
151+
key2
152+
key3
153+
key4
154+
props {
155+
value
156+
type: itemType
157+
label
158+
description
159+
isIdentifier
151160
}
152-
requests(first: 1, orderBy: submissionTime, orderDirection: desc) {
161+
requests(limit: 1, order_by: {submissionTime: desc})) {
153162
disputed
154163
disputeID
155164
submissionTime
@@ -158,7 +167,7 @@ export const useExportItems = (filters: ExportFilters) => {
158167
challenger
159168
resolutionTime
160169
deposit
161-
rounds(first: 1, orderBy: creationTime, orderDirection: desc) {
170+
rounds(limit: 1, order_by: {creationTime : desc}) {
162171
appealPeriodStart
163172
appealPeriodEnd
164173
ruling
@@ -170,65 +179,77 @@ export const useExportItems = (filters: ExportFilters) => {
170179
}
171180
}
172181
}
173-
`;
182+
`
174183

175184
try {
176185
while (keepFetching) {
177186
const variables: any = {
178187
status,
179188
disputed,
180-
text,
181189
skip,
182190
first,
183-
};
191+
}
192+
193+
if (text) {
194+
variables.text = `%${text}%`
195+
}
196+
184197
if (includeUnknown && isTagsQueriesRegistry) {
185-
variables.definedChainIds = definedChainIds;
198+
variables.definedChainIds = definedChainIds
186199
}
187200

188201
const result = (await request({
189202
url: SUBGRAPH_GNOSIS_ENDPOINT,
190203
document: query,
191204
variables,
192-
})) as any;
205+
})) as any
193206

194-
let items = result.litems;
207+
let items = result.litems
195208

196209
// Client-side filtering for non-Tags_Queries registries
197210
if (!isTagsQueriesRegistry && network.length > 0) {
198211
const selectedPrefixes = selectedChainIds.map((chainId) => {
199-
const namespace = getNamespaceForChainId(chainId);
212+
const namespace = getNamespaceForChainId(chainId)
200213
if (namespace === 'solana') {
201-
return 'solana:';
214+
return 'solana:'
202215
}
203-
return `${namespace}:${chainId}:`;
204-
});
216+
return `${namespace}:${chainId}:`
217+
})
205218

206219
items = items.filter((item: GraphItem) => {
207-
const key0 = item.metadata?.key0?.toLowerCase() || '';
208-
const matchesSelectedChain = selectedPrefixes.length > 0
209-
? selectedPrefixes.some((prefix) => key0.startsWith(prefix.toLowerCase()))
210-
: false;
211-
212-
const isUnknownChain = !knownPrefixes.some((prefix) => key0.startsWith(prefix.toLowerCase()));
213-
214-
return (selectedPrefixes.length > 0 && matchesSelectedChain) || (includeUnknown && isUnknownChain);
215-
});
220+
const key0 = item?.key0?.toLowerCase() || ''
221+
const matchesSelectedChain =
222+
selectedPrefixes.length > 0
223+
? selectedPrefixes.some((prefix) =>
224+
key0.startsWith(prefix.toLowerCase()),
225+
)
226+
: false
227+
228+
const isUnknownChain = !knownPrefixes.some((prefix) =>
229+
key0.startsWith(prefix.toLowerCase()),
230+
)
231+
232+
return (
233+
(selectedPrefixes.length > 0 && matchesSelectedChain) ||
234+
(includeUnknown && isUnknownChain)
235+
)
236+
})
216237
}
217238

218-
allData = allData.concat(items);
239+
allData = allData.concat(items)
219240

220241
if (items.length < first) {
221-
keepFetching = false;
242+
keepFetching = false
222243
}
223244

224-
skip += first;
245+
skip += first
225246
}
226247
} catch (error) {
227-
console.error('Error fetching export data:', error);
228-
throw error;
248+
console.error('Error fetching export data:', error)
249+
throw error
229250
}
230251

231-
return allData;
252+
return allData
232253
},
233-
});
234-
};
254+
})
255+
}

0 commit comments

Comments
 (0)