From 2d721bccb9fe54e95e14dadd64e47ee3704df44f Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Tue, 8 Oct 2024 14:09:50 +0100 Subject: [PATCH] complete --- apps/staking/src/components/Root/index.tsx | 3 ++- apps/staking/src/config/server.ts | 1 + apps/staking/src/hooks/use-api.tsx | 15 ++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/staking/src/components/Root/index.tsx b/apps/staking/src/components/Root/index.tsx index 0216f9f31..c8e4544f3 100644 --- a/apps/staking/src/components/Root/index.tsx +++ b/apps/staking/src/components/Root/index.tsx @@ -13,6 +13,7 @@ import { WALLETCONNECT_PROJECT_ID, MAINNET_RPC, HERMES_URL, + PYTHNET_RPC, } from "../../config/server"; import { ApiProvider } from "../../hooks/use-api"; import { LoggerProvider } from "../../hooks/use-logger"; @@ -79,7 +80,7 @@ const HtmlWithProviders = ({ lang, ...props }: HTMLProps) => ( walletConnectProjectId={WALLETCONNECT_PROJECT_ID} mainnetRpc={MAINNET_RPC} > - + diff --git a/apps/staking/src/config/server.ts b/apps/staking/src/config/server.ts index adafd096c..081020a5f 100644 --- a/apps/staking/src/config/server.ts +++ b/apps/staking/src/config/server.ts @@ -52,6 +52,7 @@ export const WALLETCONNECT_PROJECT_ID = demandInProduction( "WALLETCONNECT_PROJECT_ID", ); export const MAINNET_RPC = process.env.MAINNET_RPC; +export const PYTHNET_RPC = getOr("PYTHNET_RPC", "https://pythnet.rpcpool.com"); export const HERMES_URL = getOr("HERMES_URL", "https://hermes.pyth.network"); export const BLOCKED_REGIONS = transformOr("BLOCKED_REGIONS", fromCsv, []); export const IP_ALLOWLIST = transformOr("IP_ALLOWLIST", fromCsv, []); diff --git a/apps/staking/src/hooks/use-api.tsx b/apps/staking/src/hooks/use-api.tsx index 646ec218e..c18621bd8 100644 --- a/apps/staking/src/hooks/use-api.tsx +++ b/apps/staking/src/hooks/use-api.tsx @@ -129,24 +129,29 @@ type ApiProviderProps = Omit< ComponentProps, "value" > & { + pythnetRpcUrl: string; hermesUrl: string; }; -export const ApiProvider = ({ hermesUrl, ...props }: ApiProviderProps) => { - const state = useApiContext(hermesUrl); +export const ApiProvider = ({ + hermesUrl, + pythnetRpcUrl, + ...props +}: ApiProviderProps) => { + const state = useApiContext(hermesUrl, pythnetRpcUrl); return ; }; -const useApiContext = (hermesUrl: string) => { +const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => { const wallet = useWallet(); const { connection } = useConnection(); const { isMainnet } = useNetwork(); const { mutate } = useSWRConfig(); const hermesClient = useMemo(() => new HermesClient(hermesUrl), [hermesUrl]); const pythnetClient = useMemo( - () => new PythnetClient(new Connection("https://pythnet.rpcpool.com")), - [], + () => new PythnetClient(new Connection(pythnetRpcUrl)), + [pythnetRpcUrl], ); const pythStakingClient = useMemo( () =>