Skip to content

Commit

Permalink
feat(docs): added constant based on env
Browse files Browse the repository at this point in the history
  • Loading branch information
aednikanov committed Sep 26, 2024
1 parent 09c9820 commit f67e665
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/ParserOpenRPC/RequestBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styles from "./styles.module.css";
import global from "../global.module.css";
import { Tooltip } from "@site/src/components/Tooltip";
import { MetamaskProviderContext } from "@site/src/theme/Root";
import { LINEA_REQUEST_URL } from "@site/src/lib/constants";

interface RequestBoxProps {
isMetamaskInstalled: boolean;
Expand All @@ -32,12 +33,11 @@ export default function RequestBox({
const exampleRequest = useMemo(() => {
const preparedParams = JSON.stringify(paramsData, null, 2);
const preparedShellParams = JSON.stringify(paramsData);
const NETWORK_URL = "https://linea-mainnet.infura.io";
const API_KEY = userAPIKey ? userAPIKey : "<YOUR-API-KEY>";
if (isMetamaskNetwork) {
return `await window.ethereum.request({\n "method": "${method}",\n "params": ${preparedParams.replace(/"([^"]+)":/g, '$1:')},\n});`;
}
return `curl ${NETWORK_URL}/v3/${API_KEY} \\\n -X POST \\\n -H "Content-Type: application/json" \\\n -d '{\n "jsonrpc": "2.0",\n "method": "${method}",\n "params": ${preparedShellParams},\n "id": 1\n }'`;
return `curl ${LINEA_REQUEST_URL}/v3/${API_KEY} \\\n -X POST \\\n -H "Content-Type: application/json" \\\n -d '{\n "jsonrpc": "2.0",\n "method": "${method}",\n "params": ${preparedShellParams},\n "id": 1\n }'`;
}, [userAPIKey, method, paramsData]);

const exampleResponse = useMemo(() => {
Expand Down
5 changes: 2 additions & 3 deletions src/components/ParserOpenRPC/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { AuthBox } from "@site/src/components/ParserOpenRPC/AuthBox";
import { MetamaskProviderContext } from "@site/src/theme/Root";
import ProjectsBox from "@site/src/components/ParserOpenRPC/ProjectsBox";
import { REF_PATH } from "@site/src/lib/constants";
import { LINEA_REQUEST_URL, REF_PATH } from "@site/src/lib/constants";

interface ParserProps {
network: NETWORK_NAMES;
Expand Down Expand Up @@ -168,8 +168,7 @@ export default function ParserOpenRPC({
setReqResult(e);
}
} else {
const NETWORK_URL = "https://linea-mainnet.infura.io";
const URL = `${NETWORK_URL}/v3/${userAPIKey}`;
const URL = `${LINEA_REQUEST_URL}/v3/${userAPIKey}`;
let params = {
method: "POST",
"Content-Type": "application/json",
Expand Down
5 changes: 5 additions & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,8 @@ export const REQUEST_PARAMS = (method = "POST") => ({
export const AUTH_WALLET_SESSION_NAME = "auth.wallet.session";
export const AUTH_WALLET_TOKEN = "auth.wallet.token";
export const AUTH_WALLET_PROJECTS = "auth.wallet.projects";
export const LINEA_DEV_URL = "https://linea-mainnet.dev.infura.org";
export const LINEA_PROD_URL = "https://linea-mainnet.infura.io";
export const LINEA_REQUEST_URL = process.env.VERCEL_ENV === "production"
? LINEA_PROD_URL
: LINEA_DEV_URL;

0 comments on commit f67e665

Please sign in to comment.