From 895f6d37b2cd82be8e17fb0005712cb3a2a4557d Mon Sep 17 00:00:00 2001 From: apoorvlathey Date: Wed, 30 Oct 2024 17:05:41 +0400 Subject: [PATCH] fix localStorage build --- components/Body/NotificationBar.tsx | 2 +- components/Body/index.tsx | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/components/Body/NotificationBar.tsx b/components/Body/NotificationBar.tsx index 67b4d39..f7f25d4 100644 --- a/components/Body/NotificationBar.tsx +++ b/components/Body/NotificationBar.tsx @@ -16,7 +16,7 @@ import axios from "axios"; const CLOSED_KEY = "new-ui-notif-closed"; function NotificationBar() { - const isClosed = localStorage.getItem(CLOSED_KEY); + // const isClosed = localStorage.getItem(CLOSED_KEY); // const [isVisible, setIsVisible] = useState( // isClosed === "true" ? false : true diff --git a/components/Body/index.tsx b/components/Body/index.tsx index b6f72cf..3fc9050 100644 --- a/components/Body/index.tsx +++ b/components/Body/index.tsx @@ -66,17 +66,23 @@ const allNetworksOptions = [ function Body() { let addressFromURL: string | null = null; + let showAddressCache: string | null = null; let urlFromURL: string | null = null; let urlFromCache: string | null = null; let chainFromURL: string | null = null; + let tenderlyForkIdCache: string | null = null; if (typeof window !== "undefined") { const urlParams = new URLSearchParams(window.location.search); addressFromURL = urlParams.get("address"); urlFromURL = urlParams.get("url"); - urlFromCache = localStorage.getItem("appUrl"); chainFromURL = urlParams.get("chain"); } + if (typeof localStorage !== "undefined") { + showAddressCache = localStorage.getItem("showAddress"); + urlFromCache = localStorage.getItem("appUrl"); + tenderlyForkIdCache = localStorage.getItem("tenderlyForkId"); + } let networkIdViaURL = 1; if (chainFromURL) { for (let i = 0; i < allNetworksOptions.length; i++) { @@ -103,10 +109,10 @@ function Body() { const [provider, setProvider] = useState(); const [showAddress, setShowAddress] = useState( - addressFromURL ?? localStorage.getItem("showAddress") ?? "" + addressFromURL ?? showAddressCache ?? "" ); // gets displayed in input. ENS name remains as it is const [address, setAddress] = useState( - addressFromURL ?? localStorage.getItem("showAddress") ?? "" + addressFromURL ?? showAddressCache ?? "" ); // internal resolved address const [isAddressValid, setIsAddressValid] = useState(true); const [uri, setUri] = useState(""); @@ -133,7 +139,7 @@ function Body() { const [iframeKey, setIframeKey] = useState(0); // hacky way to reload iframe when key changes const [tenderlyForkId, setTenderlyForkId] = useState( - localStorage.getItem("tenderlyForkId") ?? "" + tenderlyForkIdCache ?? "" ); const [sendTxnData, setSendTxnData] = useState([]);