Skip to content

Commit 0014f7e

Browse files
authored
Merge pull request #2917 from pyth-network/cprussin/use-rpc-from-env
feat(insights): allow overriding rpc from env
2 parents 774f5b6 + 5083953 commit 0014f7e

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

apps/insights/src/config/isomorphic.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable n/no-process-env */
22

3+
import { getPythClusterApiUrl } from "@pythnetwork/client";
4+
35
/**
46
* Indicates this is a production-optimized build. Note this does NOT
57
* necessarily indicate that we're running on a cloud machine or the live build
@@ -11,3 +13,9 @@
1113
* with the optimized React build, etc.
1214
*/
1315
export const IS_PRODUCTION_BUILD = process.env.NODE_ENV === "production";
16+
17+
export const PYTHNET_RPC =
18+
process.env.NEXT_PUBLIC_PYTHNET_RPC ?? getPythClusterApiUrl("pythnet");
19+
export const PYTHTEST_CONFORMANCE_RPC =
20+
process.env.NEXT_PUBLIC_PYTHTEST_CONFORMANCE_RPC ??
21+
getPythClusterApiUrl("pythtest-conformance");

apps/insights/src/services/pyth.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {
22
PythHttpClient,
33
PythConnection,
4-
getPythClusterApiUrl,
54
getPythProgramKeyForCluster,
65
} from "@pythnetwork/client";
76
import type { PythPriceCallback } from "@pythnetwork/client/lib/PythConnection";
87
import { Connection, PublicKey } from "@solana/web3.js";
98
import { z } from "zod";
109

10+
import { PYTHNET_RPC, PYTHTEST_CONFORMANCE_RPC } from "../config/isomorphic";
11+
1112
export enum Cluster {
1213
Pythnet,
1314
PythtestConformance,
@@ -18,6 +19,11 @@ export const ClusterToName = {
1819
[Cluster.PythtestConformance]: "pythtest-conformance",
1920
} as const;
2021

22+
const ClusterToRPC = {
23+
[Cluster.Pythnet]: PYTHNET_RPC,
24+
[Cluster.PythtestConformance]: PYTHTEST_CONFORMANCE_RPC,
25+
} as const;
26+
2127
export const CLUSTER_NAMES = ["pythnet", "pythtest-conformance"] as const;
2228

2329
export const toCluster = (name: (typeof CLUSTER_NAMES)[number]): Cluster => {
@@ -37,7 +43,7 @@ export const parseCluster = (name: string): Cluster | undefined =>
3743
: undefined;
3844

3945
const mkConnection = (cluster: Cluster) =>
40-
new Connection(getPythClusterApiUrl(ClusterToName[cluster]));
46+
new Connection(ClusterToRPC[cluster]);
4147

4248
const connections = {
4349
[Cluster.Pythnet]: mkConnection(Cluster.Pythnet),

apps/insights/turbo.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"CLICKHOUSE_USERNAME",
1212
"CLICKHOUSE_PASSWORD",
1313
"SOLANA_RPC",
14-
"DISABLE_ACCESSIBILITY_REPORTING"
14+
"DISABLE_ACCESSIBILITY_REPORTING",
15+
"NEXT_PUBLIC_PYTHNET_RPC",
16+
"NEXT_PUBLIC_PYTHTEST_CONFORMANCE_RPC"
1517
]
1618
},
1719
"fix:lint": {

0 commit comments

Comments
 (0)