From bcc1deada0b50e2bc17bfa95a8eb3f4ae4d1c9a8 Mon Sep 17 00:00:00 2001 From: ilya-korotya Date: Fri, 8 Nov 2024 11:45:33 +0100 Subject: [PATCH] switch network to amoy --- client/src/app/components/qrCode.tsx | 2 +- client/src/pages/index.tsx | 2 ++ client/src/pages/signin.tsx | 2 +- client/src/services/onchainIssuer.tsx | 20 ++++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/client/src/app/components/qrCode.tsx b/client/src/app/components/qrCode.tsx index 2f5b007..f1ac533 100644 --- a/client/src/app/components/qrCode.tsx +++ b/client/src/app/components/qrCode.tsx @@ -13,7 +13,7 @@ const Code: FunctionComponent = (props) => { + variant="contained" size="large" style={{width: '350px', marginTop: '15px'}}>Privado ID ); diff --git a/client/src/pages/index.tsx b/client/src/pages/index.tsx index 9895e5d..4e673f3 100644 --- a/client/src/pages/index.tsx +++ b/client/src/pages/index.tsx @@ -5,6 +5,7 @@ import Button from "@mui/material/Button"; import Grid from "@mui/material/Unstable_Grid2"; import SelectedIssuerContext from "@/contexts/SelectedIssuerContext"; import { useRouter } from "next/router"; +import { switchNetwork } from '@/services/onchainIssuer'; const App = () => { const router = useRouter(); @@ -22,6 +23,7 @@ const App = () => { }; useEffect(() => { + switchNetwork(); const fetchIssuers = async () => { try { const issuers = await getIssuersList(); diff --git a/client/src/pages/signin.tsx b/client/src/pages/signin.tsx index 8ed4770..2368552 100644 --- a/client/src/pages/signin.tsx +++ b/client/src/pages/signin.tsx @@ -70,7 +70,7 @@ const MyPage = () => { - Use polygonID mobile app to scan this QR code + Use PrivadoID mobile app to scan this QR code diff --git a/client/src/services/onchainIssuer.tsx b/client/src/services/onchainIssuer.tsx index 1d86ea1..b961214 100644 --- a/client/src/services/onchainIssuer.tsx +++ b/client/src/services/onchainIssuer.tsx @@ -6,6 +6,26 @@ import abi from "./abi.json"; const nullifierSeed = process.env.NEXT_PUBLIC_NULLIFIER_SEED!; const contractABI = abi.abi; +const amoyChainID: bigint = BigInt(80002); +export const switchNetwork = async () => { + const web3 = new Web3(window.ethereum); + const networkId = await web3.eth.net.getId(); + if (networkId !== amoyChainID) { + try { + await window.ethereum.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: `0x${amoyChainID.toString(16)}` }], + }); + } catch (switchError: any) { + if (switchError.code === 4902) { + throw new Error('This network is not available in your MetaMask, please add it.'); + } else { + throw new Error('Failed to switch network'); + } + } + } +}; + export const issueCredential = async ( contractAddress: string, userId: Id,