From 7b9843ca6aef4917a2be166e60b65643e9d3bc6e Mon Sep 17 00:00:00 2001 From: Lionell Briones Date: Fri, 23 Feb 2024 18:55:58 +0800 Subject: [PATCH 1/2] fix switch chain --- demo/react-app/src/App.tsx | 23 +- demo/react-app/src/services/web3auth.tsx | 9 +- package-lock.json | 10062 ++++++++++------ .../adapters/base-evm-adapter/package.json | 2 +- .../adapters/base-solana-adapter/package.json | 2 +- .../wallet-services-plugin/package.json | 3 +- .../wallet-services-plugin/src/plugin.ts | 46 +- packages/providers/base-provider/package.json | 2 +- .../providers/ethereum-provider/package.json | 2 +- .../providers/solana-provider/package.json | 2 +- packages/providers/xrpl-provider/package.json | 2 +- 11 files changed, 6266 insertions(+), 3889 deletions(-) diff --git a/demo/react-app/src/App.tsx b/demo/react-app/src/App.tsx index 2dbacd144..c1a3f8718 100644 --- a/demo/react-app/src/App.tsx +++ b/demo/react-app/src/App.tsx @@ -7,9 +7,26 @@ import { Web3AuthProvider } from "./services/web3auth"; import Setting from "./components/Setting"; import Main from "./components/Main"; +const STORAGE_KEY = { + WEB3AUTH_NETWORK: "web3auth_network", + BLOCKCHAIN: "blockchain", +}; + function App() { - const [web3AuthNetwork, setWeb3AuthNetwork] = useState("sapphire_mainnet"); - const [chain, setChain] = useState("sepolia"); + const savedNetwork = window.localStorage.getItem(STORAGE_KEY.WEB3AUTH_NETWORK) as WEB3AUTH_NETWORK_TYPE; + const savedChain = window.localStorage.getItem(STORAGE_KEY.BLOCKCHAIN) as CHAIN_CONFIG_TYPE; + const [web3AuthNetwork, setWeb3AuthNetwork] = useState(savedNetwork || "sapphire_mainnet"); + const [chain, setChain] = useState(savedChain || "polygon-mumbai"); + + const networkChangeHandler = (network: WEB3AUTH_NETWORK_TYPE) => { + window.localStorage.setItem(STORAGE_KEY.BLOCKCHAIN, network); + setWeb3AuthNetwork(network); + }; + + const chainChangeHandler = (chain: CHAIN_CONFIG_TYPE) => { + window.localStorage.setItem(STORAGE_KEY.BLOCKCHAIN, chain); + setChain(chain); + }; return (
@@ -20,7 +37,7 @@ function App() { {" "} & ReactJS Example - +