refactor: rename testnet localStorage helpers
This commit is contained in:
		
							parent
							
								
									c058d500d0
								
							
						
					
					
						commit
						bb744c48c5
					
				| @ -7,7 +7,7 @@ import Column from "./components/Column"; | ||||
| import Header from "./components/Header"; | ||||
| import Modal from "./components/Modal"; | ||||
| import { DEFAULT_MAIN_CHAINS, DEFAULT_TEST_CHAINS } from "./constants"; | ||||
| import { AccountAction, setInitialStateTestnet, getInitialStateTestnet } from "./helpers"; | ||||
| import { AccountAction, getLocalStorageTestnetFlag, setLocaleStorageTestnetFlag } from "./helpers"; | ||||
| import Toggle from "./components/Toggle"; | ||||
| import RequestModal from "./modals/RequestModal"; | ||||
| import PairingModal from "./modals/PairingModal"; | ||||
| @ -26,7 +26,7 @@ import { useWalletConnectClient } from "./contexts/ClientContext"; | ||||
| import { useJsonRpc } from "./contexts/JsonRpcContext"; | ||||
| 
 | ||||
| export default function App() { | ||||
|   const [isTestnet, setIsTestnet] = useState(getInitialStateTestnet()); | ||||
|   const [isTestnet, setIsTestnet] = useState(getLocalStorageTestnetFlag()); | ||||
| 
 | ||||
|   const [modal, setModal] = useState(""); | ||||
| 
 | ||||
| @ -35,6 +35,7 @@ export default function App() { | ||||
|   const openPingModal = () => setModal("ping"); | ||||
|   const openRequestModal = () => setModal("request"); | ||||
| 
 | ||||
|   // Initialize the WalletConnect client.
 | ||||
|   const { | ||||
|     client, | ||||
|     session, | ||||
| @ -48,10 +49,11 @@ export default function App() { | ||||
|     setChains, | ||||
|   } = useWalletConnectClient(); | ||||
| 
 | ||||
|   // Use `JsonRpcContext` to provide us with relevant RPC methods and states.
 | ||||
|   const { chainData, ping, ethereumRpc, cosmosRpc, isRpcRequestPending, rpcResult } = useJsonRpc(); | ||||
| 
 | ||||
|   // Close the pairing modal after a session is established.
 | ||||
|   useEffect(() => { | ||||
|     // Close the pairing modal after a session is established.
 | ||||
|     if (session && modal === "pairing") { | ||||
|       closeModal(); | ||||
|     } | ||||
| @ -61,9 +63,11 @@ export default function App() { | ||||
|     if (typeof client === "undefined") { | ||||
|       throw new Error("WalletConnect is not initialized"); | ||||
|     } | ||||
|     // Suggest existing pairings (if any).
 | ||||
|     if (client.pairing.topics.length) { | ||||
|       return openPairingModal(); | ||||
|     } | ||||
|     // If no existing pairings are available, trigger `WalletConnectClient.connect`.
 | ||||
|     connect(); | ||||
|   }; | ||||
| 
 | ||||
| @ -123,8 +127,7 @@ export default function App() { | ||||
|   const toggleTestnets = () => { | ||||
|     const nextIsTestnetState = !isTestnet; | ||||
|     setIsTestnet(nextIsTestnetState); | ||||
|     // TODO: rename "setLocalStorage..."
 | ||||
|     setInitialStateTestnet(nextIsTestnetState); | ||||
|     setLocaleStorageTestnetFlag(nextIsTestnetState); | ||||
|   }; | ||||
| 
 | ||||
|   const handleChainSelectionClick = (chainId: string) => { | ||||
|  | ||||
| @ -185,15 +185,15 @@ export const fromWad = (wad: BigNumberish, decimals = 18): string => { | ||||
| export const LOCALSTORAGE_KEY_TESTNET = "TESTNET"; | ||||
| export const INITIAL_STATE_TESTNET_DEFAULT = true; | ||||
| 
 | ||||
| export function setInitialStateTestnet(value: boolean): void { | ||||
| export function setLocaleStorageTestnetFlag(value: boolean): void { | ||||
|   window.localStorage.setItem(LOCALSTORAGE_KEY_TESTNET, `${value}`); | ||||
| } | ||||
| 
 | ||||
| export function getInitialStateTestnet(): boolean { | ||||
| export function getLocalStorageTestnetFlag(): boolean { | ||||
|   let value = INITIAL_STATE_TESTNET_DEFAULT; | ||||
|   const persisted = window.localStorage.getItem(LOCALSTORAGE_KEY_TESTNET); | ||||
|   if (!persisted) { | ||||
|     setInitialStateTestnet(value); | ||||
|     setLocaleStorageTestnetFlag(value); | ||||
|   } else { | ||||
|     value = persisted === "true" ? true : false; | ||||
|   } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user