From 8c51f823681bd385033900f3e45f337123561091 Mon Sep 17 00:00:00 2001 From: Felix Hildebrandt <61689369+fhildeb@users.noreply.github.com> Date: Tue, 9 Jul 2024 17:02:54 +0200 Subject: [PATCH] Feat: Global Parameter Handling (#104) * remove inspector-specific network settings * set up global network parameter * adjust nav bar to include params in links * fix navbar css module name * resolve array type issue * add local storage on new tabs * add network tag to all network-related tools * cleanup + fix address updates * add parameter handling to data fetcher * remove logging * refactor: remove network badges and rename variable --------- Co-authored-by: CJ42 --- .../KeyManagerNonceChecker.tsx | 4 +- ...{NvaBar.module.scss => NavBar.module.scss} | 0 components/NavBar/NavBar.tsx | 36 +++++-- .../NetworksSwitch/NetworksSwitch.tsx | 11 +- contexts/NetworksContext.tsx | 101 ++++++++++++++++-- pages/data-fetcher.tsx | 35 +++++- pages/inspector.tsx | 49 ++------- 7 files changed, 170 insertions(+), 66 deletions(-) rename components/NavBar/{NvaBar.module.scss => NavBar.module.scss} (100%) diff --git a/components/KeyManagerNonceChecker/KeyManagerNonceChecker.tsx b/components/KeyManagerNonceChecker/KeyManagerNonceChecker.tsx index af89944..2176f53 100644 --- a/components/KeyManagerNonceChecker/KeyManagerNonceChecker.tsx +++ b/components/KeyManagerNonceChecker/KeyManagerNonceChecker.tsx @@ -1,9 +1,10 @@ /* eslint-disable react/no-unescaped-entities */ -import { useState } from 'react'; +import { useContext, useState } from 'react'; import LSP6KeyManager from '@lukso/lsp-smart-contracts/artifacts/LSP6KeyManager.json'; import useWeb3 from '../../hooks/useWeb3'; +import { NetworkContext } from '../../contexts/NetworksContext'; const KeyManagerNonceChecker: React.FC = () => { const web3 = useWeb3(); @@ -12,6 +13,7 @@ const KeyManagerNonceChecker: React.FC = () => { const [callerAddress, setCallerAddress] = useState(''); const [channelId, setChannelId] = useState(''); const [nonce, setNonce] = useState(''); + const { network } = useContext(NetworkContext); const [showNonce, setShowNonce] = useState(false); const [error, showError] = useState(false); diff --git a/components/NavBar/NvaBar.module.scss b/components/NavBar/NavBar.module.scss similarity index 100% rename from components/NavBar/NvaBar.module.scss rename to components/NavBar/NavBar.module.scss diff --git a/components/NavBar/NavBar.tsx b/components/NavBar/NavBar.tsx index 68c52c7..ddbd1c9 100644 --- a/components/NavBar/NavBar.tsx +++ b/components/NavBar/NavBar.tsx @@ -6,7 +6,7 @@ import React, { useState } from 'react'; import Link from 'next/link'; import { useRouter } from 'next/router'; import NetworkSwitch from './components/NetworksSwitch'; -import styles from './NvaBar.module.scss'; +import styles from './NavBar.module.scss'; const NavBar: React.FC = () => { const [isActive, setIsActive] = useState(false); @@ -16,10 +16,28 @@ const NavBar: React.FC = () => { setIsActive(!isActive); }; + const createLink = (path) => { + if (typeof window === 'undefined') { + return path; + } + const urlParams = new URLSearchParams(window.location.search); + + const keys = Array.from(urlParams.keys()); + + // Remove all page-specific parameters + for (const key of keys) { + if (key !== 'network') { + urlParams.delete(key); + } + } + + return `${path}?${urlParams.toString()}`; + }; + return (