Get constructor arguments

pull/51/head
yuriy 3 years ago
parent afba14e0a1
commit dabe5eccb7
No known key found for this signature in database
GPG Key ID: 6D8D9AD3D80B0F2C
  1. 1
      src/api/explorerV1.ts
  2. 63
      src/pages/VerifyContract/VerifyContract.tsx

@ -12,6 +12,7 @@ export interface IVerifyContractData {
contractName: string;
statusText: string;
isLoading: boolean;
argsLoading: boolean;
error: string;
}

@ -16,7 +16,8 @@ import { toaster } from "src/App";
import { breakpoints } from "../../Responive/breakpoints";
import { useMediaQuery } from "react-responsive";
import { useHistory } from "react-router";
import { getQueryVariable } from "../../utils";
import { getAddress, getQueryVariable } from "../../utils";
import { getContractsByField, getTransactionByField } from "../../api/client";
const Field = styled(Box)``;
@ -53,10 +54,49 @@ class VerifyContractBase extends React.Component<
constructorArguments: "",
contractName: "",
isLoading: false,
argsLoading: false,
statusText: "",
error: "",
};
getBytecode = async () => {
this.setState({ ...this.state, argsLoading: true });
try {
if (this.state.contractAddress) {
const address = getAddress(this.state.contractAddress).basicHex;
const contracts: any = await getContractsByField([
0,
"address",
address,
]);
if (contracts?.transactionHash) {
const trx = await getTransactionByField([
0,
"hash",
contracts.transactionHash,
]);
if (trx?.input) {
const argStart = trx.input.lastIndexOf("0033");
if (argStart) {
this.setState({
...this.state,
constructorArguments: trx.input.slice(argStart + 4),
});
}
}
}
}
} catch (e) {
console.error(e);
}
this.setState({ ...this.state, argsLoading: false });
};
onClickSubmitBtn = async () => {
this.setState({
...this.state,
@ -200,7 +240,24 @@ class VerifyContractBase extends React.Component<
</Field>
<Field margin={"small"}>
<Text>Constructor Arguments (ABI-encoded)</Text>
<Box direction="row" justify="between">
<Box>
<Text>Constructor Arguments (ABI-encoded)</Text>
</Box>
{this.state.argsLoading ? (
<Box
style={{ width: "120px" }}
direction="row"
justify="center"
>
<Spinner size={"xsmall"} />
</Box>
) : (
<Box onClick={() => this.getBytecode()}>
<Text color="#00AEE9">paste arguments from tx input</Text>
</Box>
)}
</Box>
<TextArea
style={{ minHeight: "80px", height: "80px" }}
onChange={(evt: React.ChangeEvent<HTMLTextAreaElement>) => {
@ -209,7 +266,7 @@ class VerifyContractBase extends React.Component<
constructorArguments: evt.currentTarget.value,
});
}}
disabled={isLoading}
disabled={isLoading || this.state.argsLoading}
value={this.state.constructorArguments}
/>
</Field>

Loading…
Cancel
Save