@@ -16,6 +16,7 @@ import { WEB_API_BASE_URL } from "./constants";
16
16
import type { Interval } from "./types" ;
17
17
import { useDownloadBlob } from "../../hooks/use-download-blob" ;
18
18
import { priceFeedsSchema } from "../../schemas/pyth" ;
19
+ import { CLUSTER_NAMES } from "../../services/pyth" ;
19
20
20
21
// If interval is 'daily', set interval_days=1
21
22
// If interval is 'weekly', get the previous Sunday and set interval_days=7
@@ -62,7 +63,7 @@ const getRankingDateAndIntervalDays = (date: Date, interval: Interval) => {
62
63
}
63
64
} ;
64
65
65
- const getFeeds = async ( cluster : string ) => {
66
+ const getFeeds = async ( cluster : ( typeof CLUSTER_NAMES ) [ number ] ) => {
66
67
const url = new URL ( `/api/pyth/get-feeds` , globalThis . window . origin ) ;
67
68
url . searchParams . set ( "cluster" , cluster ) ;
68
69
const data = await fetch ( url ) ;
@@ -89,7 +90,7 @@ const PublisherQuantityScoreSchema = z.object({
89
90
} ) ;
90
91
91
92
const fetchRankingData = async (
92
- cluster : string ,
93
+ cluster : ( typeof CLUSTER_NAMES ) [ number ] ,
93
94
publisher : string ,
94
95
interval : Interval ,
95
96
) => {
@@ -140,6 +141,14 @@ const csvHeaders = [
140
141
"final_score" ,
141
142
] ;
142
143
144
+ const symbolsSort = ( a : string , b : string ) => {
145
+ const aSplit = a . split ( "." ) ;
146
+ const bSplit = b . split ( "." ) ;
147
+ const aLast = aSplit . at ( - 1 ) ;
148
+ const bLast = bSplit . at ( - 1 ) ;
149
+ return aLast ?. localeCompare ( bLast ?? "" ) ?? 0 ;
150
+ } ;
151
+
143
152
export const useDownloadReportForPublisher = ( ) => {
144
153
const download = useDownloadBlob ( ) ;
145
154
@@ -150,7 +159,7 @@ export const useDownloadReportForPublisher = () => {
150
159
interval,
151
160
} : {
152
161
publisher : string ;
153
- cluster : string ;
162
+ cluster : ( typeof CLUSTER_NAMES ) [ number ] ;
154
163
interval : Interval ;
155
164
} ) => {
156
165
const [ rankingData , allFeeds ] = await Promise . all ( [
@@ -176,11 +185,13 @@ export const useDownloadReportForPublisher = () => {
176
185
} ;
177
186
} ;
178
187
179
- const activePriceFeeds = rankingData . quantityRankData [ 0 ] ?. symbols ?? [ ] ;
188
+ const activePriceFeeds =
189
+ rankingData . quantityRankData [ 0 ] ?. symbols . sort ( symbolsSort ) ?? [ ] ;
180
190
181
191
const allSymbols = allFeeds
182
- . flatMap ( ( feed ) => feed . symbol )
192
+ . map ( ( feed ) => feed . symbol )
183
193
. filter ( ( symbol : string ) => symbol && ! symbol . includes ( "NULL" ) ) ;
194
+
184
195
// filter out inactive price feeds
185
196
const inactivePriceFeeds = allSymbols
186
197
. filter ( ( symbol ) => {
@@ -191,13 +202,8 @@ export const useDownloadReportForPublisher = () => {
191
202
meta . price . numComponentPrices > 0
192
203
) ;
193
204
} )
194
- . sort ( ( a , b ) => {
195
- const aSplit = a . split ( "." ) ;
196
- const bSplit = b . split ( "." ) ;
197
- const aLast = aSplit . at ( - 1 ) ;
198
- const bLast = bSplit . at ( - 1 ) ;
199
- return aLast ?. localeCompare ( bLast ?? "" ) ?? 0 ;
200
- } ) ;
205
+ . sort ( symbolsSort ) ;
206
+
201
207
const data = [
202
208
...activePriceFeeds . map ( ( feed ) => ( {
203
209
...getPriceFeedData ( feed ) ,
@@ -212,6 +218,7 @@ export const useDownloadReportForPublisher = () => {
212
218
: "unpermissioned" ,
213
219
} ) ) ,
214
220
] ;
221
+
215
222
const csv = stringifyCsv ( data , { header : true , columns : csvHeaders } ) ;
216
223
const blob = new Blob ( [ csv ] , { type : "text/csv;charset=utf-8" } ) ;
217
224
download ( blob , `${ publisher } -${ cluster } -price-feeds.csv` ) ;
0 commit comments