-
Notifications
You must be signed in to change notification settings - Fork 104
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
Add verification feature #631
base: main
Are you sure you want to change the base?
Changes from 2 commits
65e2401
e395ddc
d1ab871
da95892
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {useCallback} from "react"; | ||
import {useGlobalState} from "../../global-config/GlobalConfig"; | ||
import {VerificationStatus} from "../../constants"; | ||
|
||
export interface AptosVerificationCheckDto { | ||
network: string; | ||
account: string; | ||
moduleName: string; | ||
status?: VerificationStatus; | ||
errMsg?: string; | ||
} | ||
const useVerificationChecker = () => { | ||
const [, , endpoint] = useGlobalState(); | ||
|
||
return useCallback( | ||
async (params: { | ||
network: string; | ||
account: string; | ||
moduleName: string; | ||
}): Promise<AptosVerificationCheckDto> => { | ||
const queryString = new URLSearchParams(params).toString(); | ||
const res = await fetch(`${endpoint}?${queryString}`); | ||
if (!res.ok) { | ||
throw new Error("Verification service is not working."); | ||
} | ||
return res.json(); | ||
}, | ||
[endpoint], | ||
); | ||
}; | ||
|
||
export default useVerificationChecker; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {useCallback} from "react"; | ||
import {useGlobalState} from "../../global-config/GlobalConfig"; | ||
|
||
export interface AptosVerificationResultDto { | ||
network: string; | ||
account: string; | ||
moduleName: string; | ||
errMsg?: string; | ||
status?: "VERIFIED_SAME" | "VERIFIED_DIFFERENT" | "NOT_VERIFIED"; | ||
onChainByteCode?: string; | ||
compiledByteCode?: string; | ||
} | ||
|
||
const useVerificationRequester = () => { | ||
const [, , endpoint] = useGlobalState(); | ||
|
||
return useCallback( | ||
async (body: { | ||
network: string; | ||
account: string; | ||
moduleName: string; | ||
}): Promise<AptosVerificationResultDto> => { | ||
const res = await fetch(endpoint, { | ||
method: "post", | ||
body: JSON.stringify(body), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
if (!res.ok) { | ||
throw new Error("Verification service is not working."); | ||
} | ||
return res.json(); | ||
}, | ||
[endpoint], | ||
); | ||
}; | ||
|
||
export default useVerificationRequester; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, {useState} from "react"; | ||
import {Button, CircularProgress} from "@mui/material"; | ||
import useVerificationRequester from "../../../api/hooks/useVerificationRequester"; | ||
import {VerificationStatus} from "../../../constants"; | ||
import {genCodeDescription} from "./codeDescription"; | ||
|
||
interface VerificationButtonProps { | ||
network: string; | ||
account?: string; | ||
moduleName?: string; | ||
verificationStatus?: VerificationStatus; | ||
setVerificationStatus: React.Dispatch< | ||
React.SetStateAction<VerificationStatus> | ||
>; | ||
setVerificationServerErr: React.Dispatch<React.SetStateAction<string>>; | ||
setCodeDescription: React.Dispatch<React.SetStateAction<string>>; | ||
} | ||
|
||
export default function VerificationButton({ | ||
network, | ||
account, | ||
moduleName, | ||
verificationStatus, | ||
setVerificationStatus, | ||
setVerificationServerErr, | ||
setCodeDescription, | ||
}: VerificationButtonProps) { | ||
const [isInProgress, setIsInProgress] = useState(false); | ||
const verificationRequester = useVerificationRequester(); | ||
|
||
const verifyClick = () => { | ||
if (!(account && moduleName)) { | ||
return; | ||
} | ||
setIsInProgress(true); | ||
verificationRequester({ | ||
network: network, | ||
account: account, | ||
moduleName: moduleName, | ||
}) | ||
.then((dto) => { | ||
setIsInProgress(false); | ||
if (dto.errMsg) { | ||
setVerificationStatus("NOT_VERIFIED"); | ||
setVerificationServerErr(`${dto.errMsg}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My main concern is the messages that currently come out of this need to be cleaned up a bit. Would be great to see some of the code for the verification service. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed verification server to show the actual error message. |
||
} | ||
|
||
if (!dto.status) { | ||
setVerificationStatus("NOT_VERIFIED"); | ||
return; | ||
} | ||
|
||
setVerificationStatus(dto.status); | ||
setCodeDescription(genCodeDescription(dto.status)); | ||
setVerificationServerErr(""); | ||
}) | ||
.catch((reason: Error) => { | ||
console.error(reason); | ||
setVerificationStatus("NOT_VERIFIED"); | ||
setCodeDescription(genCodeDescription("NOT_VERIFIED")); | ||
setVerificationServerErr("Verification service is not working."); | ||
}) | ||
.finally(() => { | ||
setIsInProgress(false); | ||
}); | ||
}; | ||
|
||
if (verificationStatus === "VERIFIED_DIFFERENT") { | ||
return ( | ||
<Button | ||
type="submit" | ||
disabled={true} | ||
variant="contained" | ||
sx={{width: "10rem", height: "3rem"}} | ||
> | ||
<span style={{color: "red"}}>No Match</span> | ||
gregnazario marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Button> | ||
); | ||
} | ||
|
||
if (verificationStatus === "VERIFIED_SAME") { | ||
return ( | ||
<Button | ||
type="submit" | ||
disabled={true} | ||
variant="contained" | ||
sx={{width: "10rem", height: "3rem"}} | ||
> | ||
<span style={{color: "green"}}>Match</span> | ||
gregnazario marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Button> | ||
); | ||
} | ||
|
||
return ( | ||
<Button | ||
type="submit" | ||
disabled={isInProgress} | ||
variant="contained" | ||
sx={{width: "10rem", height: "3rem"}} | ||
onClick={verifyClick} | ||
> | ||
{verificationStatus === undefined || isInProgress ? ( | ||
<CircularProgress size={30}></CircularProgress> | ||
) : ( | ||
"Verify" | ||
gregnazario marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)} | ||
</Button> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a service for this, we should possibly provide help details somewhere for how someone can run it themselves. Since, this is essentially trusting this URL entirely, it would be good to provide a more trustless system (you can run it yourself), or that the foundation will run it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will inform you once I have prepared for it.