diff --git a/docs/site/src/components/API/api-ref/networkselect.js b/docs/site/src/components/API/api-ref/networkselect.js index a829efce98e..17756bf0720 100644 --- a/docs/site/src/components/API/api-ref/networkselect.js +++ b/docs/site/src/components/API/api-ref/networkselect.js @@ -3,57 +3,56 @@ // SPDX-License-Identifier: Apache-2.0 import React, { useState, useEffect } from "react"; -import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment"; +import BrowserOnly from "@docusaurus/BrowserOnly"; import { Select, MenuItem, FormControl, InputLabel } from "@mui/material"; import { StyledEngineProvider } from "@mui/material/styles"; const NETWORKS = ["Devnet", "Testnet", "Mainnet"]; const NetworkSelect = () => { - const [selection, setSelection] = useState(() => { - if (ExecutionEnvironment.canUseDOM) { - const network = localStorage.getItem("RPC"); - if (network === null) { - return "mainnet"; - } - return localStorage.getItem("RPC"); - } else { - return "mainnet"; - } - }); + return ( + Loading...}> + {() => { + const [selection, setSelection] = useState(() => { + const network = localStorage.getItem("RPC"); + return network !== null ? network : "mainnet"; + }); - useEffect(() => { - localStorage.setItem("RPC", selection); - window.dispatchEvent(new Event("storage")); - }, [selection]); + useEffect(() => { + localStorage.setItem("RPC", selection); + window.dispatchEvent(new Event("storage")); + }, [selection]); - const handleChange = (e) => { - setSelection(e.target.value); - }; + const handleChange = (e) => { + setSelection(e.target.value); + }; - return ( - -
- - {`RPC: https://fullnode.${selection.toLowerCase()}.iota.io:443`} - - -
-
+ return ( + +
+ + {`RPC: https://fullnode.${selection.toLowerCase()}.iota.io:443`} + + +
+
+ ); + }} +
); }; diff --git a/docs/site/src/components/API/index.js b/docs/site/src/components/API/index.js index b32313d27a9..f2c1389f9f0 100644 --- a/docs/site/src/components/API/index.js +++ b/docs/site/src/components/API/index.js @@ -3,11 +3,10 @@ // SPDX-License-Identifier: Apache-2.0 import React, { useState, useEffect } from "react"; -import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment"; +import BrowserOnly from "@docusaurus/BrowserOnly"; import Heading from "@theme/Heading"; import RefNav from "./api-ref/refnav"; import Methods from "./api-ref/method"; - import ScrollSpy from "react-ui-scrollspy"; // TODO: Once the repo is public, we can use the old imports again and reactivate the ../../utils/getopenrpcspecs.js script @@ -20,89 +19,87 @@ export function getRef(url) { } const Rpc = () => { - const [openrpc, setOpenRpc] = useState(() => { - if (ExecutionEnvironment.canUseDOM) { - const network = localStorage.getItem("RPC"); - switch (network) { - case "mainnet": - return openrpc_mainnet; - case "testnet": - return openrpc_testnet; - case "devnet": - return openrpc_devnet; - default: - return openrpc_mainnet; - } - } else { - return openrpc_mainnet; - } - }); - const [openDropdown, setOpenDropdown] = useState(null); + return ( + Loading...

}> + {() => { + const [openrpc, setOpenRpc] = useState(() => { + const network = localStorage.getItem("RPC"); + switch (network) { + case "mainnet": + return openrpc_mainnet; + case "testnet": + return openrpc_testnet; + case "devnet": + return openrpc_devnet; + default: + return openrpc_mainnet; + } + }); - useEffect(() => { - const rpcswitch = () => { - if (localStorage.getItem("RPC")) { - switch (localStorage.getItem("RPC")) { - case "mainnet": - setOpenRpc(openrpc_mainnet); - break; - case "testnet": - setOpenRpc(openrpc_testnet); - break; - case "devnet": - setOpenRpc(openrpc_devnet); - break; - default: - setOpenRpc(openrpc_mainnet); - } - } else { - setOpenRpc(openrpc_mainnet); - } - }; + const [openDropdown, setOpenDropdown] = useState(null); - window.addEventListener("storage", rpcswitch); + useEffect(() => { + const rpcswitch = () => { + const network = localStorage.getItem("RPC"); + switch (network) { + case "mainnet": + setOpenRpc(openrpc_mainnet); + break; + case "testnet": + setOpenRpc(openrpc_testnet); + break; + case "devnet": + setOpenRpc(openrpc_devnet); + break; + default: + setOpenRpc(openrpc_mainnet); + } + }; - return () => { - window.removeEventListener("storage", rpcswitch); - }; - }, [openrpc]); + window.addEventListener("storage", rpcswitch); + return () => { + window.removeEventListener("storage", rpcswitch); + }; + }, []); - const apis = [ - ...new Set(openrpc["methods"].map((api) => api.tags[0].name)), - ].sort(); - const schemas = openrpc.components.schemas; + const apis = [ + ...new Set(openrpc["methods"].map((api) => api.tags[0].name)), + ].sort(); + const schemas = openrpc.components.schemas; - if (!openrpc) { - return

Open RPC file not found.

; - } + if (!openrpc) { + return

Open RPC file not found.

; + } - let ids = []; - openrpc["methods"].map((method) => { - ids.push(method.name.replaceAll(/\s/g, "-").toLowerCase()); - }); + let ids = openrpc["methods"].map((method) => + method.name.replaceAll(/\s/g, "-").toLowerCase() + ); - return ( -
-
- -
+ return ( +
+
+ +
-
-
-
- - IOTA JSON-RPC Reference - Version: {openrpc.info.version} - - -
-

{openrpc.info.description}

- +
+
+
+ + IOTA JSON-RPC Reference - Version: {openrpc.info.version} + + +
+

{openrpc.info.description}

+ +
+
+
- +
-
-
-
+ ); + }} + ); };