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

Added optional field for implementation contract address on AbiForm #539

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { constants } from 'ethers';

type FormInput = {
contractAddress: string;
implementationAddress: string;
abi: string;
};

Expand All @@ -45,15 +46,17 @@ export const AbiForm: React.FC = () => {
}, [getValues, gotoFunctionSelector]);

const fetchAbi = useCallback(async () => {
const validationResult = await trigger('contractAddress');
const validationResult =
(await trigger('contractAddress')) && (await trigger('implementationAddress'));
if (validationResult === false) {
// address is invalid
return;
}

const address = getValues('contractAddress');
const implementationAddress = getValues('implementationAddress');
const abiHandler = new AbiHandler(networkName);
const abi = await abiHandler.get(address);
const abi = await abiHandler.get(implementationAddress || address);
if (abi) {
gotoFunctionSelector(address, abi);
} else {
Expand Down Expand Up @@ -101,7 +104,29 @@ export const AbiForm: React.FC = () => {
)}
/>
</div>
<div style={{ width: `${compact ? '100%' : 'auto'}` }}>
<div style={{ flex: '1', minWidth: '400px' }}>
<StyledText name="title3">Implementation address (optional)</StyledText>
<Controller
name="implementationAddress"
control={control}
shouldUnregister={true}
defaultValue=""
rules={{
validate: async (value) => !value || (await validateContract(value, provider)),
}}
render={({ field: { onChange, value }, fieldState: { error } }) => (
<TextInput
wide
value={value}
placeholder={constants.AddressZero}
onChange={onChange}
status={error ? 'error' : 'normal'}
error={error ? error.message : null}
/>
)}
/>
</div>
<div style={{ flex: '1', minWidth: '400px' }}>
<Button wide label="Search" onClick={fetchAbi}></Button>
{!compact && formState.errors.contractAddress && (
<div style={{ opacity: 0 }}>filler</div>
Expand Down