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

fix #518: added switch to allow manual ABI specification #520

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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 @@ -12,6 +12,7 @@ import {
SPACING,
Info,
} from '@aragon/ui';
import Switch from '@material-ui/core/Switch';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know how to use components/Switchs/BlueSwitch.tsx and didn't find an example.

import { Controller, useForm } from 'react-hook-form';
import { validateContract, validateAbi } from 'utils/validations';
import { useWallet } from 'providers/AugmentedWallet';
Expand All @@ -21,6 +22,7 @@ import { constants } from 'ethers';

type FormInput = {
contractAddress: string;
manualAbi: boolean;
abi: string;
};

Expand All @@ -38,6 +40,7 @@ export const AbiForm: React.FC = () => {

const { gotoFunctionSelector } = useActionBuilderState();
const [showAbi, setShowAbi] = useState(false);
const [verified, setVerified] = useState(false);

const gotoNextScreen = useCallback(() => {
const formData = getValues();
Expand All @@ -51,15 +54,22 @@ export const AbiForm: React.FC = () => {
return;
}

const manualAbi = getValues('manualAbi');
const address = getValues('contractAddress');
const abiHandler = new AbiHandler(networkName);
const abi = await abiHandler.get(address);

if (abi) {
gotoFunctionSelector(address, abi);
setVerified(true);
if (manualAbi) {
setShowAbi(true);
} else {
gotoFunctionSelector(address, abi);
}
} else {
setShowAbi(true);
}
}, [networkName, trigger, getValues, gotoFunctionSelector, setShowAbi]);
}, [networkName, trigger, getValues, gotoFunctionSelector, setShowAbi, setVerified]);

return (
<Grid>
Expand Down Expand Up @@ -109,25 +119,43 @@ export const AbiForm: React.FC = () => {
</div>
</div>
</GridItem>
<GridItem>
<Controller
name="manualAbi"
control={control}
defaultValue={false}
render={({ field: { onChange, value } }) => (
<div
style={{
display: 'flex',
alignItems: 'baseline',
}}
>
<div>Specify ABI manually:</div>
<Switch checked={value} onChange={onChange} />
<Help hint="What is an ABI?">
An ABI is the specification used to interact with Ethereum smart contracts
</Help>
</div>
)}
/>
</GridItem>
{showAbi && (
<Grid>
<GridItem>
<Info mode="warning" borderColor={`${theme.warningSurface}`}>
<div style={{ display: 'flex', alignItems: 'center', columnGap: '5px' }}>
<IconWarning></IconWarning>
<span>Contract not verified, please insert the input function ABI</span>
</div>
</Info>
</GridItem>
{!verified && (
<GridItem>
<Info mode="warning" borderColor={`${theme.warningSurface}`}>
<div style={{ display: 'flex', alignItems: 'center', columnGap: '5px' }}>
<IconWarning></IconWarning>
<span>Contract not verified, please insert the input function ABI</span>
</div>
</Info>
</GridItem>
)}
<GridItem>
<StyledText name="title2">
<div style={{ display: 'flex', columnGap: `${spacing}px`, alignItems: 'center' }}>
<div>Input function ABI </div>
<div>
<Help hint="What is an ABI?">
An ABI is the specification used to interact with Ethereum smart contracts
</Help>
</div>
</div>
</StyledText>
<Controller
Expand Down