Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch network to amoy #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading