From fc1864ea08ffe5e8662813bb8d814ffcaba78ce1 Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Wed, 10 Apr 2024 13:09:50 +0200 Subject: [PATCH] chore(demos): update chain id settings in demos --- demos/taco-demo/src/App.tsx | 14 +++++++++++--- demos/taco-nft-demo/src/App.tsx | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/demos/taco-demo/src/App.tsx b/demos/taco-demo/src/App.tsx index 118099df1..7267f25ed 100644 --- a/demos/taco-demo/src/App.tsx +++ b/demos/taco-demo/src/App.tsx @@ -17,6 +17,12 @@ import { Encrypt } from './Encrypt'; import { Spinner } from './Spinner'; import { DEFAULT_DOMAIN, DEFAULT_RITUAL_ID } from './config'; +const chainIdForDomain = { + [domains.DEVNET]: 80002, + [domains.TESTNET]: 80002, + [domains.MAINNET]: 137, +}; + export default function App() { const { activateBrowserWallet, deactivate, account, switchNetwork } = useEthers(); @@ -30,10 +36,12 @@ export default function App() { const [ritualId, setRitualId] = useState(DEFAULT_RITUAL_ID); const [domain, setDomain] = useState(DEFAULT_DOMAIN); + const chainId = chainIdForDomain[domain]; + useEffect(() => { initialize(); - switchNetwork(80002); - }, []); + switchNetwork(chainId); + }, [chainId]); const encryptMessage = async (message: string) => { if (!condition) { @@ -41,7 +49,7 @@ export default function App() { } setLoading(true); - await switchNetwork(80002); + await switchNetwork(chainId); const provider = new ethers.providers.Web3Provider(window.ethereum); const encryptedMessage = await encrypt( diff --git a/demos/taco-nft-demo/src/App.tsx b/demos/taco-nft-demo/src/App.tsx index e27e1847f..6302e4ccc 100644 --- a/demos/taco-nft-demo/src/App.tsx +++ b/demos/taco-nft-demo/src/App.tsx @@ -17,6 +17,12 @@ import { NFTConditionBuilder } from './NFTConditionBuilder'; import { Spinner } from './Spinner'; import { DEFAULT_DOMAIN, DEFAULT_RITUAL_ID } from './config'; +const chainIdForDomain = { + [domains.DEVNET]: 80002, + [domains.TESTNET]: 80002, + [domains.MAINNET]: 137, +}; + export default function App() { const { activateBrowserWallet, deactivate, account, switchNetwork } = useEthers(); @@ -30,9 +36,13 @@ export default function App() { const [ritualId, setRitualId] = useState(DEFAULT_RITUAL_ID); const [domain, setDomain] = useState(DEFAULT_DOMAIN); + const chainId = chainIdForDomain[domain]; + useEffect(() => { initialize(); - }, []); + switchNetwork(chainId); + }, [chainId]); + const encryptMessage = async (message: string) => { if (!condition) { @@ -40,7 +50,7 @@ export default function App() { } setLoading(true); - await switchNetwork(80002); + await switchNetwork(chainId); const provider = new ethers.providers.Web3Provider(window.ethereum); const encryptedMessage = await encrypt(