Skip to content

Commit

Permalink
feat: make RPC configurable via env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Apr 3, 2024
1 parent 08d2357 commit ac2af74
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FORK_URL=
NODE_ENV=
STAKING_TEST_KEYS_PATH=
STAKING_TEST_KEYS_PATH=
DEV_RPC=
9 changes: 6 additions & 3 deletions frontend/context/UserBalanceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { useInterval } from 'usehooks-ts';

import { useAppInfo } from '@/hooks';
import { EthersService } from '@/service';
import { env } from "process";

const RPC = env.DEV_RPC ? env.DEV_RPC : "https://rpc.gnosischain.com";

export const UserBalanceContext = createContext<{
balance: number;
Expand All @@ -15,10 +18,10 @@ export const UserBalanceProvider = ({ children }: PropsWithChildren) => {
const [balance, setBalance] = useState<number>(0);

const updateBalance = async () => {
const isRpcValid = await EthersService.checkRpc('http://localhost:8545');
const isRpcValid = await EthersService.checkRpc(RPC);
if (userPublicKey && isRpcValid)
EthersService.getEthBalance(userPublicKey, 'http://localhost:8545').then(
(res) => setBalance(res),
EthersService.getEthBalance(userPublicKey, RPC).then(
(res) => setBalance(res)
);
};

Expand Down
5 changes: 4 additions & 1 deletion frontend/service/Services.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Deployment, Service, ServiceHash, ServiceTemplate } from '@/client';
import { BACKEND_URL } from '@/constants';
import { env } from "process"

const RPC = env.DEV_RPC ? env.DEV_RPC : "https://rpc.gnosischain.com"

/**
* Get a single service from the backend
Expand Down Expand Up @@ -42,7 +45,7 @@ const createService = async ({
deploy,
configuration: {
...serviceTemplate.configuration,
rpc: 'http://localhost:8545',
rpc: RPC,
},
}),
headers: {
Expand Down
9 changes: 5 additions & 4 deletions operate/ledger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

"""Ledger helpers."""

import os
import typing as t

from operate.ledger.base import LedgerHelper
Expand All @@ -27,10 +28,10 @@
from operate.types import ChainType, LedgerType


ETHEREUM_RPC = "https://ethereum.publicnode.com"
GNOSIS_RPC = "https://rpc.gnosischain.com"
GOERLI_RPC = "https://ethereum-goerli.publicnode.com"
SOLANA_RPC = "https://api.mainnet-beta.solana.com"
ETHEREUM_RPC = os.environ.get("DEV_RPC", "https://ethereum.publicnode.com")
GNOSIS_RPC = os.environ.get("DEV_RPC", "https://rpc.gnosischain.com")
GOERLI_RPC = os.environ.get("DEV_RPC", "https://ethereum-goerli.publicnode.com")
SOLANA_RPC = os.environ.get("DEV_RPC", "https://api.mainnet-beta.solana.com")


DEFAULT_RPCS = {
Expand Down

0 comments on commit ac2af74

Please sign in to comment.