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'
6
6
7
7
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
15
15
}
16
16
17
17
export const useExportItems = ( filters : ExportFilters ) => {
18
18
return useQuery < GraphItem [ ] > ( {
19
19
queryKey : [ 'exportItems' , filters ] ,
20
20
enabled : false , // Only fetch when export button is clicked
21
21
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
26
26
27
27
const {
28
28
registryId,
@@ -31,102 +31,113 @@ export const useExportItems = (filters: ExportFilters) => {
31
31
fromDate,
32
32
toDate,
33
33
network = [ ] ,
34
- text = ''
35
- } = filters ;
34
+ text = '' ,
35
+ } = filters
36
36
37
37
if ( ! registryId ) {
38
- throw new Error ( 'Registry ID is required for export' ) ;
38
+ throw new Error ( 'Registry ID is required for export' )
39
39
}
40
40
41
- const isTagsQueriesRegistry = registryId === '0xae6aaed5434244be3699c56e7ebc828194f26dc3' ;
41
+ const isTagsQueriesRegistry =
42
+ registryId === '0xae6aaed5434244be3699c56e7ebc828194f26dc3'
42
43
43
44
// 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
+ ]
53
58
54
- let networkQueryObject = '' ;
59
+ let networkQueryObject = ''
55
60
if ( isTagsQueriesRegistry && network . length > 0 ) {
56
61
const conditions = selectedChainIds . map (
57
62
( chainId ) =>
58
- `{or : [{metadata_ : {key2 : "${ chainId } "}}, {metadata_ : {key1 : "${ chainId } "}}]}`
59
- ) ;
63
+ `{ _or : [{ key2 : { _eq : "${ chainId } "}}, { key1 : { _eq : "${ chainId } "}}]}` ,
64
+ )
60
65
if ( includeUnknown ) {
61
66
conditions . push (
62
- `{and : [{metadata_ : {key1_not_in : $definedChainIds}}, {metadata_ : {key2_not_in : $definedChainIds}}]}`
63
- ) ;
67
+ `{ _and : [{ key1 : { _nin : $definedChainIds}}, { key2 : { _nin : $definedChainIds}}]}` ,
68
+ )
64
69
}
65
- networkQueryObject = conditions . length > 0 ? `{or: [${ conditions . join ( ',' ) } ]}` : '{}' ;
70
+ networkQueryObject =
71
+ conditions . length > 0 ? `{_or: [${ conditions . join ( ',' ) } ]}` : '{}'
66
72
} else if ( network . length > 0 ) {
67
73
const conditions = selectedChainIds . map ( ( chainId ) => {
68
- const namespace = getNamespaceForChainId ( chainId ) ;
74
+ const namespace = getNamespaceForChainId ( chainId )
69
75
if ( namespace === 'solana' ) {
70
- return `{metadata_ : {key0_starts_with_nocase : "solana:"}}` ;
76
+ return `{key0 : { _ilike : "solana:% "}}`
71
77
}
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 ( ',' ) } ]}` : '{}'
75
82
}
76
83
77
84
// Build text filter
78
85
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
+ : ''
87
94
88
95
// Build date filter
89
- let dateFilterObject = '' ;
96
+ let dateFilterObject = ''
90
97
if ( fromDate || toDate ) {
91
- const conditions = [ ] ;
98
+ const conditions : string [ ] = [ ]
92
99
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
+ )
95
104
}
96
105
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
+ )
99
110
}
100
- dateFilterObject = conditions . length > 0 ? `{and: [${ conditions . join ( ',' ) } ]}` : '' ;
111
+ dateFilterObject =
112
+ conditions . length > 0 ? `{_and: [${ conditions . join ( ',' ) } ]}` : ''
101
113
}
102
114
103
115
// Build the complete where clause
104
116
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} }` ,
108
120
networkQueryObject && `${ networkQueryObject } ` ,
109
121
textFilterObject && `${ textFilterObject } ` ,
110
- dateFilterObject && `${ dateFilterObject } `
111
- ] . filter ( Boolean ) as string [ ] ;
122
+ dateFilterObject && `${ dateFilterObject } ` ,
123
+ ] . filter ( Boolean ) as string [ ]
112
124
113
125
const query = gql `
114
126
query (
115
- $status: [String !]!
127
+ $status: [status !]!
116
128
$disputed: [Boolean!]!
117
- $text: String!
129
+ $text: String
118
130
$skip: Int!
119
131
$first: Int!
120
132
${ includeUnknown && isTagsQueriesRegistry ? '$definedChainIds: [String!]!' : '' }
121
133
) {
122
- litems(
134
+ litems: LItem (
123
135
where: {
124
- and : [${ whereConditions . join ( ',' ) } ]
136
+ _and : [${ whereConditions . join ( ',' ) } ]
125
137
}
126
- skip: $skip
127
- first: $first
128
- orderBy: "latestRequestSubmissionTime"
129
- orderDirection: desc
138
+ offset: $skip
139
+ limit: $first
140
+ order_by: {latestRequestSubmissionTime : $orderDirection }
130
141
) {
131
142
id
132
143
latestRequestSubmissionTime
@@ -135,21 +146,19 @@ export const useExportItems = (filters: ExportFilters) => {
135
146
status
136
147
disputed
137
148
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
151
160
}
152
- requests(first : 1, orderBy: submissionTime, orderDirection : desc) {
161
+ requests(limit : 1, order_by: { submissionTime: desc}) ) {
153
162
disputed
154
163
disputeID
155
164
submissionTime
@@ -158,7 +167,7 @@ export const useExportItems = (filters: ExportFilters) => {
158
167
challenger
159
168
resolutionTime
160
169
deposit
161
- rounds(first : 1, orderBy: creationTime, orderDirection : desc) {
170
+ rounds(limit : 1, order_by: { creationTime : desc} ) {
162
171
appealPeriodStart
163
172
appealPeriodEnd
164
173
ruling
@@ -170,65 +179,77 @@ export const useExportItems = (filters: ExportFilters) => {
170
179
}
171
180
}
172
181
}
173
- ` ;
182
+ `
174
183
175
184
try {
176
185
while ( keepFetching ) {
177
186
const variables : any = {
178
187
status,
179
188
disputed,
180
- text,
181
189
skip,
182
190
first,
183
- } ;
191
+ }
192
+
193
+ if ( text ) {
194
+ variables . text = `%${ text } %`
195
+ }
196
+
184
197
if ( includeUnknown && isTagsQueriesRegistry ) {
185
- variables . definedChainIds = definedChainIds ;
198
+ variables . definedChainIds = definedChainIds
186
199
}
187
200
188
201
const result = ( await request ( {
189
202
url : SUBGRAPH_GNOSIS_ENDPOINT ,
190
203
document : query ,
191
204
variables,
192
- } ) ) as any ;
205
+ } ) ) as any
193
206
194
- let items = result . litems ;
207
+ let items = result . litems
195
208
196
209
// Client-side filtering for non-Tags_Queries registries
197
210
if ( ! isTagsQueriesRegistry && network . length > 0 ) {
198
211
const selectedPrefixes = selectedChainIds . map ( ( chainId ) => {
199
- const namespace = getNamespaceForChainId ( chainId ) ;
212
+ const namespace = getNamespaceForChainId ( chainId )
200
213
if ( namespace === 'solana' ) {
201
- return 'solana:' ;
214
+ return 'solana:'
202
215
}
203
- return `${ namespace } :${ chainId } :` ;
204
- } ) ;
216
+ return `${ namespace } :${ chainId } :`
217
+ } )
205
218
206
219
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
+ } )
216
237
}
217
238
218
- allData = allData . concat ( items ) ;
239
+ allData = allData . concat ( items )
219
240
220
241
if ( items . length < first ) {
221
- keepFetching = false ;
242
+ keepFetching = false
222
243
}
223
244
224
- skip += first ;
245
+ skip += first
225
246
}
226
247
} catch ( error ) {
227
- console . error ( 'Error fetching export data:' , error ) ;
228
- throw error ;
248
+ console . error ( 'Error fetching export data:' , error )
249
+ throw error
229
250
}
230
251
231
- return allData ;
252
+ return allData
232
253
} ,
233
- } ) ;
234
- } ;
254
+ } )
255
+ }
0 commit comments