From 5083953fb18791c5dde4c23555cceb74347937e3 Mon Sep 17 00:00:00 2001 From: Connor Prussin Date: Thu, 31 Jul 2025 15:53:36 -0700 Subject: [PATCH] feat(insights): allow overriding rpc from env --- apps/insights/src/config/isomorphic.ts | 8 ++++++++ apps/insights/src/services/pyth.ts | 10 ++++++++-- apps/insights/turbo.json | 4 +++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/insights/src/config/isomorphic.ts b/apps/insights/src/config/isomorphic.ts index db2626f0dc..907dd616a3 100644 --- a/apps/insights/src/config/isomorphic.ts +++ b/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"); diff --git a/apps/insights/src/services/pyth.ts b/apps/insights/src/services/pyth.ts index e442b4cee3..89e66f21c3 100644 --- a/apps/insights/src/services/pyth.ts +++ b/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), diff --git a/apps/insights/turbo.json b/apps/insights/turbo.json index 0a5ec06ed6..f66e3e263f 100644 --- a/apps/insights/turbo.json +++ b/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": {