@@ -16,6 +16,7 @@ import { WEB_API_BASE_URL } from "./constants";
1616import type { Interval } from "./types" ;
1717import { useDownloadBlob } from "../../hooks/use-download-blob" ;
1818import { priceFeedsSchema } from "../../schemas/pyth" ;
19+ import { CLUSTER_NAMES } from "../../services/pyth" ;
1920
2021// If interval is 'daily', set interval_days=1
2122// If interval is 'weekly', get the previous Sunday and set interval_days=7
@@ -62,7 +63,7 @@ const getRankingDateAndIntervalDays = (date: Date, interval: Interval) => {
6263 }
6364} ;
6465
65- const getFeeds = async ( cluster : string ) => {
66+ const getFeeds = async ( cluster : ( typeof CLUSTER_NAMES ) [ number ] ) => {
6667 const url = new URL ( `/api/pyth/get-feeds` , globalThis . window . origin ) ;
6768 url . searchParams . set ( "cluster" , cluster ) ;
6869 const data = await fetch ( url ) ;
@@ -89,7 +90,7 @@ const PublisherQuantityScoreSchema = z.object({
8990} ) ;
9091
9192const fetchRankingData = async (
92- cluster : string ,
93+ cluster : ( typeof CLUSTER_NAMES ) [ number ] ,
9394 publisher : string ,
9495 interval : Interval ,
9596) => {
@@ -140,6 +141,14 @@ const csvHeaders = [
140141 "final_score" ,
141142] ;
142143
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+
143152export const useDownloadReportForPublisher = ( ) => {
144153 const download = useDownloadBlob ( ) ;
145154
@@ -150,7 +159,7 @@ export const useDownloadReportForPublisher = () => {
150159 interval,
151160 } : {
152161 publisher : string ;
153- cluster : string ;
162+ cluster : ( typeof CLUSTER_NAMES ) [ number ] ;
154163 interval : Interval ;
155164 } ) => {
156165 const [ rankingData , allFeeds ] = await Promise . all ( [
@@ -176,11 +185,13 @@ export const useDownloadReportForPublisher = () => {
176185 } ;
177186 } ;
178187
179- const activePriceFeeds = rankingData . quantityRankData [ 0 ] ?. symbols ?? [ ] ;
188+ const activePriceFeeds =
189+ rankingData . quantityRankData [ 0 ] ?. symbols . sort ( symbolsSort ) ?? [ ] ;
180190
181191 const allSymbols = allFeeds
182- . flatMap ( ( feed ) => feed . symbol )
192+ . map ( ( feed ) => feed . symbol )
183193 . filter ( ( symbol : string ) => symbol && ! symbol . includes ( "NULL" ) ) ;
194+
184195 // filter out inactive price feeds
185196 const inactivePriceFeeds = allSymbols
186197 . filter ( ( symbol ) => {
@@ -191,13 +202,8 @@ export const useDownloadReportForPublisher = () => {
191202 meta . price . numComponentPrices > 0
192203 ) ;
193204 } )
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+
201207 const data = [
202208 ...activePriceFeeds . map ( ( feed ) => ( {
203209 ...getPriceFeedData ( feed ) ,
@@ -212,6 +218,7 @@ export const useDownloadReportForPublisher = () => {
212218 : "unpermissioned" ,
213219 } ) ) ,
214220 ] ;
221+
215222 const csv = stringifyCsv ( data , { header : true , columns : csvHeaders } ) ;
216223 const blob = new Blob ( [ csv ] , { type : "text/csv;charset=utf-8" } ) ;
217224 download ( blob , `${ publisher } -${ cluster } -price-feeds.csv` ) ;
0 commit comments