Эх сурвалжийг харах

feat(insights): allow overriding rpc from env

Connor Prussin 3 сар өмнө
parent
commit
5083953fb1

+ 8 - 0
apps/insights/src/config/isomorphic.ts

@@ -1,5 +1,7 @@
 /* eslint-disable n/no-process-env */
 
+import { getPythClusterApiUrl } from "@pythnetwork/client";
+
 /**
  * Indicates this is a production-optimized build.  Note this does NOT
  * necessarily indicate that we're running on a cloud machine or the live build
@@ -11,3 +13,9 @@
  * with the optimized React build, etc.
  */
 export const IS_PRODUCTION_BUILD = process.env.NODE_ENV === "production";
+
+export const PYTHNET_RPC =
+  process.env.NEXT_PUBLIC_PYTHNET_RPC ?? getPythClusterApiUrl("pythnet");
+export const PYTHTEST_CONFORMANCE_RPC =
+  process.env.NEXT_PUBLIC_PYTHTEST_CONFORMANCE_RPC ??
+  getPythClusterApiUrl("pythtest-conformance");

+ 8 - 2
apps/insights/src/services/pyth.ts

@@ -1,13 +1,14 @@
 import {
   PythHttpClient,
   PythConnection,
-  getPythClusterApiUrl,
   getPythProgramKeyForCluster,
 } from "@pythnetwork/client";
 import type { PythPriceCallback } from "@pythnetwork/client/lib/PythConnection";
 import { Connection, PublicKey } from "@solana/web3.js";
 import { z } from "zod";
 
+import { PYTHNET_RPC, PYTHTEST_CONFORMANCE_RPC } from "../config/isomorphic";
+
 export enum Cluster {
   Pythnet,
   PythtestConformance,
@@ -18,6 +19,11 @@ export const ClusterToName = {
   [Cluster.PythtestConformance]: "pythtest-conformance",
 } as const;
 
+const ClusterToRPC = {
+  [Cluster.Pythnet]: PYTHNET_RPC,
+  [Cluster.PythtestConformance]: PYTHTEST_CONFORMANCE_RPC,
+} as const;
+
 export const CLUSTER_NAMES = ["pythnet", "pythtest-conformance"] as const;
 
 export const toCluster = (name: (typeof CLUSTER_NAMES)[number]): Cluster => {
@@ -37,7 +43,7 @@ export const parseCluster = (name: string): Cluster | undefined =>
     : undefined;
 
 const mkConnection = (cluster: Cluster) =>
-  new Connection(getPythClusterApiUrl(ClusterToName[cluster]));
+  new Connection(ClusterToRPC[cluster]);
 
 const connections = {
   [Cluster.Pythnet]: mkConnection(Cluster.Pythnet),

+ 3 - 1
apps/insights/turbo.json

@@ -11,7 +11,9 @@
         "CLICKHOUSE_USERNAME",
         "CLICKHOUSE_PASSWORD",
         "SOLANA_RPC",
-        "DISABLE_ACCESSIBILITY_REPORTING"
+        "DISABLE_ACCESSIBILITY_REPORTING",
+        "NEXT_PUBLIC_PYTHNET_RPC",
+        "NEXT_PUBLIC_PYTHTEST_CONFORMANCE_RPC"
       ]
     },
     "fix:lint": {