Skip to content

Commit

Permalink
Merge pull request #4 from 0xPolygonID/feature/switch-to-amoy-network
Browse files Browse the repository at this point in the history
switch network to amoy
  • Loading branch information
Meyanis95 authored Nov 8, 2024
2 parents 8b995f7 + bcc1dea commit e288214
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/src/app/components/qrCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Code: FunctionComponent<QRCodeData> = (props) => {
<Box>
<QRCode level={"L"} size={350} value={value} />
<Button onClick={() => dispachEvent(value)}
variant="contained" size="large" style={{width: '350px', marginTop: '15px'}}>Polygon ID</Button>
variant="contained" size="large" style={{width: '350px', marginTop: '15px'}}>Privado ID</Button>
</Box>
</Container>
);
Expand Down
2 changes: 2 additions & 0 deletions client/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -22,6 +23,7 @@ const App = () => {
};

useEffect(() => {
switchNetwork();
const fetchIssuers = async () => {
try {
const issuers = await getIssuersList();
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const MyPage = () => {

<Grid xs={12} style={{marginTop: '-30px'}}>
<Typography textAlign="center" variant='h2'>
Use polygonID mobile app to scan this QR code
Use PrivadoID mobile app to scan this QR code
</Typography>
</Grid>
<Grid alignItems="center" xs={12} style={{marginTop: '30px'}}>
Expand Down
20 changes: 20 additions & 0 deletions client/src/services/onchainIssuer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e288214

Please sign in to comment.