Skip to content

Commit

Permalink
rpc switch
Browse files Browse the repository at this point in the history
  • Loading branch information
xieqian committed Mar 18, 2024
1 parent 5373573 commit 8e6fed0
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConnectConfig } from "near-api-js";
import { getRpcList } from "../components/Rpc/tool";

export const LOGIC_CONTRACT_NAME = process.env.NEXT_PUBLIC_CONTRACT_NAME as string;
export const DUST_THRESHOLD = 0.001;
Expand Down Expand Up @@ -27,12 +28,21 @@ export const incentiveTokens = [
"usdt.tether-token.near",
];
const getConfig = (env: string = defaultNetwork) => {
const RPC_LIST = getRpcList();
let endPoint = "defaultRpc";
try {
endPoint = window.localStorage.getItem("endPoint") || endPoint;
if (!RPC_LIST[endPoint]) {
endPoint = "defaultRpc";
localStorage.removeItem("endPoint");
}
} catch (error) {}
switch (env) {
case "production":
case "mainnet":
return {
networkId: "mainnet",
nodeUrl: "https://rpc.mainnet.near.org",
nodeUrl: RPC_LIST[endPoint].url,
walletUrl: "https://wallet.near.org",
helperUrl: "https://helper.mainnet.near.org",
explorerUrl: "https://explorer.mainnet.near.org",
Expand All @@ -58,7 +68,7 @@ const getConfig = (env: string = defaultNetwork) => {
case "testnet":
return {
networkId: "testnet",
nodeUrl: "https://rpc.testnet.near.org",
nodeUrl: RPC_LIST[endPoint].url,
walletUrl: "https://wallet.testnet.near.org",
helperUrl: "https://helper.testnet.near.org",
explorerUrl: "https://explorer.testnet.near.org",
Expand All @@ -74,7 +84,7 @@ const getConfig = (env: string = defaultNetwork) => {
case "betanet":
return {
networkId: "betanet",
nodeUrl: "https://rpc.betanet.near.org",
nodeUrl: RPC_LIST[endPoint].url,
walletUrl: "https://wallet.betanet.near.org",
helperUrl: "https://helper.betanet.near.org",
explorerUrl: "https://explorer.betanet.near.org",
Expand All @@ -83,21 +93,21 @@ const getConfig = (env: string = defaultNetwork) => {
case "local":
return {
networkId: "local",
nodeUrl: "http://localhost:3030",
nodeUrl: RPC_LIST[endPoint].url,
keyPath: `${process.env.HOME}/.near/validator_key.json`,
walletUrl: "http://localhost:4000/wallet",
} as ConnectConfig;
case "test":
case "ci":
return {
networkId: "shared-test",
nodeUrl: "https://rpc.ci-testnet.near.org",
nodeUrl: RPC_LIST[endPoint].url,
masterAccount: "test.near",
} as ConnectConfig;
case "ci-betanet":
return {
networkId: "shared-test-staging",
nodeUrl: "https://rpc.ci-betanet.near.org",
nodeUrl: RPC_LIST[endPoint].url,
masterAccount: "test.near",
} as ConnectConfig;
default:
Expand Down

0 comments on commit 8e6fed0

Please sign in to comment.