Sfoglia il codice sorgente

fix(insights): implement pr feedback

Connor Prussin 3 settimane fa
parent
commit
1712c13de6

+ 4 - 9
apps/insights/src/components/Publisher/performance.tsx

@@ -63,7 +63,7 @@ export const Performance = async ({ params }: Props) => {
       prefetch: false,
       nameAsString: knownPublisher?.name ?? publisher.key,
       data: {
-        ranking: (
+        ranking: (publisher.rank !== undefined || publisher.key === key) && (
           <Ranking isCurrent={publisher.key === key} className={styles.ranking}>
             {publisher.rank}
           </Ranking>
@@ -86,14 +86,9 @@ export const Performance = async ({ params }: Props) => {
             {publisher.inactiveFeeds}
           </Link>
         ),
-        averageScore:
-          // eslint-disable-next-line unicorn/no-null
-          publisher.averageScore === undefined ? null : (
-            <Score
-              width={PUBLISHER_SCORE_WIDTH}
-              score={publisher.averageScore}
-            />
-          ),
+        averageScore: publisher.averageScore !== undefined && (
+          <Score width={PUBLISHER_SCORE_WIDTH} score={publisher.averageScore} />
+        ),
         name: (
           <PublisherTag
             cluster={parsedCluster}

+ 4 - 8
apps/insights/src/components/Publishers/publishers-card.tsx

@@ -155,9 +155,7 @@ const ResolvedPublishersCard = ({
           textValue: publisher.name ?? id,
           prefetch: false,
           data: {
-            ranking:
-              // eslint-disable-next-line unicorn/no-null
-              ranking === undefined ? null : <Ranking>{ranking}</Ranking>,
+            ranking: ranking !== undefined && <Ranking>{ranking}</Ranking>,
             name: (
               <PublisherTag
                 publisherKey={id}
@@ -177,11 +175,9 @@ const ResolvedPublishersCard = ({
                 {activeFeeds}
               </Link>
             ),
-            averageScore:
-              // eslint-disable-next-line unicorn/no-null
-              averageScore === undefined ? null : (
-                <Score score={averageScore} width={PUBLISHER_SCORE_WIDTH} />
-              ),
+            averageScore: averageScore !== undefined && (
+              <Score score={averageScore} width={PUBLISHER_SCORE_WIDTH} />
+            ),
           },
         }),
       ),

+ 6 - 12
apps/insights/src/components/Root/search-button.tsx

@@ -291,12 +291,9 @@ const SearchDialogContents = ({
                         <>
                           <dt>Average Score</dt>
                           <dd>
-                            {
-                              // eslint-disable-next-line unicorn/no-null
-                              result.averageScore === undefined ? null : (
-                                <Score score={result.averageScore} />
-                              )
-                            }
+                            {result.averageScore !== undefined && (
+                              <Score score={result.averageScore} />
+                            )}
                           </dd>
                         </>
                       )}
@@ -340,12 +337,9 @@ const SearchDialogContents = ({
                           icon: result.icon,
                         })}
                       />
-                      {
-                        // eslint-disable-next-line unicorn/no-null
-                        result.averageScore === undefined ? null : (
-                          <Score score={result.averageScore} />
-                        )
-                      }
+                      {result.averageScore !== undefined && (
+                        <Score score={result.averageScore} />
+                      )}
                     </>
                   )}
                 </div>

+ 16 - 14
apps/insights/src/services/pyth/get-publishers-for-cluster.ts

@@ -5,27 +5,29 @@ import { redisCache } from "../../cache";
 const _getPublishersByFeedForCluster = async (cluster: Cluster) => {
   const data = await getPythMetadata(cluster);
   const result: Record<string, string[]> = {};
-  for (const key of data.productPrice.keys()) {
-    const price = data.productPrice.get(key);
-    result[key] =
-      price?.priceComponents.map(({ publisher }) => publisher.toBase58()) ?? [];
+  for (const [key, price] of data.productPrice.entries()) {
+    result[key] = price.priceComponents.map(({ publisher }) =>
+      publisher.toBase58(),
+    );
   }
   return result;
 };
 
+/**
+ * Given a cluster, this function will return a record which maps each
+ * permissioned publisher to the list of price feed IDs for which that publisher
+ * is permissioned.
+ */
 const _getFeedsByPublisherForCluster = async (cluster: Cluster) => {
   const data = await getPythMetadata(cluster);
   const result: Record<string, string[]> = {};
-  for (const symbol of data.productPrice.keys()) {
-    const price = data.productPrice.get(symbol);
-    if (price !== undefined) {
-      for (const component of price.priceComponents) {
-        const publisherKey = component.publisher.toBase58();
-        if (result[publisherKey] === undefined) {
-          result[publisherKey] = [symbol];
-        } else {
-          result[publisherKey].push(symbol);
-        }
+  for (const [symbol, price] of data.productPrice.entries()) {
+    for (const component of price.priceComponents) {
+      const publisherKey = component.publisher.toBase58();
+      if (result[publisherKey] === undefined) {
+        result[publisherKey] = [symbol];
+      } else {
+        result[publisherKey].push(symbol);
       }
     }
   }