Skip to content

Commit

Permalink
lint: fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
HJunyuan committed Aug 30, 2024
1 parent 11b06af commit 15f648e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"func-names": ["error", "as-needed"],
"prettier/prettier": "error",
"no-unused-expressions": "off",
"import/prefer-default-export": "off"

"import/prefer-default-export": "off",
"no-console": "off"
}
}
50 changes: 27 additions & 23 deletions src/shared/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,29 @@ const config = require("./config");
const IS_MAINNET =
config.network === "mainnet" || config.network === "homestead";

/**
* A wrapper of verify to auto-switch between Ethereum and Polygon
*/
export const verify = async (document) => {
if (!validateSchema(document)) {
// Following current behaviour of from "@govtechsg/opencerts-verify"
// E.g. await verify({ "bad": "document" }) // returns undefined
return undefined;
}

const _verify = verificationBuilder(
[...openAttestationVerifiers, registryVerifier],
{
network: getNetworkName(document)
}
);

return await _verify(document);
};

function getNetworkName(document) {
const data = getData(document);

if (IS_MAINNET) {
if (IS_MAINNET && data.network) {
/* Production Network Whitelist */
switch (data.network?.chainId) {
switch (data.network.chainId) {
case "137":
return "matic";
default:
break;
}
} else {
/* Non-production Network Whitelist */
switch (data.network?.chainId) {
switch (data.network.chainId) {
case "80002":
// return "amoy";
// FIXME: Setting "amoy" will fail as it's an unsupported network in Ethers v5.7.2
// Create a custom provider and specify { chainId: 80002, name: "amoy" }
// https://github.com/OpenCerts/opencerts-website/blob/1de65c66795ec2f416d6c829259e9f9ab1e49e45/src/sagas/certificate.ts#L123
console.error(`"amoy" is not supported on Ethers v5.7.2 yet`);
break;
default:
break;
}
}

Expand All @@ -63,3 +47,23 @@ function getNetworkName(document) {

return config.network;
}

/**
* A wrapper of verify to auto-switch between Ethereum and Polygon
*/
export const verify = (document) => {
if (!validateSchema(document)) {
// Following current behaviour of from "@govtechsg/opencerts-verify"
// E.g. await verify({ "bad": "document" }) // returns undefined
return undefined;
}

const oaVerify = verificationBuilder(
[...openAttestationVerifiers, registryVerifier],
{
network: getNetworkName(document)
}
);

return oaVerify(document);
};

0 comments on commit 15f648e

Please sign in to comment.