Skip to content

Commit

Permalink
complete
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Oct 8, 2024
1 parent dcabdac commit 2d721bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion apps/staking/src/components/Root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -79,7 +80,7 @@ const HtmlWithProviders = ({ lang, ...props }: HTMLProps<HTMLHtmlElement>) => (
walletConnectProjectId={WALLETCONNECT_PROJECT_ID}
mainnetRpc={MAINNET_RPC}
>
<ApiProvider hermesUrl={HERMES_URL}>
<ApiProvider hermesUrl={HERMES_URL} pythnetRpcUrl={PYTHNET_RPC}>
<ToastProvider>
<html lang={lang} {...props} />
</ToastProvider>
Expand Down
1 change: 1 addition & 0 deletions apps/staking/src/config/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, []);
Expand Down
15 changes: 10 additions & 5 deletions apps/staking/src/hooks/use-api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,29 @@ type ApiProviderProps = Omit<
ComponentProps<typeof ApiContext.Provider>,
"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 <ApiContext.Provider value={state} {...props} />;
};

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(
() =>
Expand Down

0 comments on commit 2d721bc

Please sign in to comment.