Skip to content

Commit

Permalink
fix: APP-3069 - Fix "all fields must have valid input" invalid error …
Browse files Browse the repository at this point in the history
…for all SCC proxy contracts (#1335)

* fix SCC ABI validaiton

* fix lint errors

* resolve comments
  • Loading branch information
sepehr2github authored and Barukimang committed May 2, 2024
1 parent 7f50508 commit 32bb1d5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 31 deletions.
3 changes: 1 addition & 2 deletions src/containers/actionBuilder/scc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ const SCCAction: React.FC<ActionIndex & {allowRemove?: boolean}> = ({

useEffect(() => {
const validateAction = async () => {
const isValid = await validateSCCAction(actionData, network);
const isValid = await validateSCCAction(actionData);
setIsValid(isValid);
};

validateAction();
}, [actionData, network]);

Expand Down
7 changes: 1 addition & 6 deletions src/containers/proposalStepper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ const ProposalStepper: React.FC = () => {
*************************************************/
useEffect(() => {
const validateActions = async () => {
const isValid = await actionsAreValid(
formActions,
actions,
errors,
network
);
const isValid = await actionsAreValid(formActions, actions, errors);
setAreActionsValid(isValid);
};

Expand Down
2 changes: 2 additions & 0 deletions src/containers/smartContractComposer/components/inputForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const InputForm: React.FC<InputFormProps> = ({
setValue(`actions.${actionIndex}.contractName`, selectedSC.name);
setValue(`actions.${actionIndex}.functionName`, selectedAction.name);
setValue(`actions.${actionIndex}.notice`, selectedAction.notice);
setValue(`actions.${actionIndex}.actions`, selectedSC.actions);

// loop through all the inputs so we pick up the payable one as well
// and keep it on the form
Expand Down Expand Up @@ -153,6 +154,7 @@ const InputForm: React.FC<InputFormProps> = ({
sccActions,
selectedAction.name,
selectedAction.notice,
selectedSC.actions,
selectedSC.address,
selectedSC.name,
setValue,
Expand Down
3 changes: 1 addition & 2 deletions src/containers/withdrawStepper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ const WithdrawStepper: React.FC<WithdrawStepperProps> = ({
wizardTitle={t('newWithdraw.configureWithdraw.title')}
wizardDescription={t('newWithdraw.configureWithdraw.subtitle')}
isNextButtonDisabled={
!actions.length ||
!actionsAreValid(formActions, actions, errors, network)
!actions.length || !actionsAreValid(formActions, actions, errors)
}
onNextButtonClicked={next => {
trackEvent('newWithdraw_continueBtn_clicked', {
Expand Down
1 change: 1 addition & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ export type ActionSCC = {
functionName: string;
inputs?: Array<ExternalActionInput>;
value?: string;
actions?: Array<SmartContractAction>;
};

// Alias
Expand Down
32 changes: 11 additions & 21 deletions src/utils/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {TFunction} from 'i18next';
import {TokenVotingClient} from '@aragon/sdk-client';

import {i18n} from '../../i18n.config';
import {ALPHA_NUMERIC_PATTERN, SupportedNetworks} from './constants';
import {ALPHA_NUMERIC_PATTERN} from './constants';
import {
Web3Address,
getDefaultPayableAmountInputName,
Expand All @@ -24,7 +24,6 @@ import {
ActionWithdraw,
Nullable,
} from './types';
import {getEtherscanVerifiedContract} from 'services/etherscanAPI';
import {ensRegistryABI} from 'abis/ensRegistryABI';

export type TokenType =
Expand Down Expand Up @@ -198,8 +197,7 @@ export const alphaNumericValidator = (
export async function actionsAreValid(
formActions: Nullable<Action[]>,
contextActions: ActionItem[],
errors: FieldErrors,
network: SupportedNetworks
errors: FieldErrors
) {
// proposals can go through without any actions
if (contextActions?.length === 0) return true;
Expand Down Expand Up @@ -245,7 +243,7 @@ export async function actionsAreValid(
);
case 'external_contract_action': {
const SCCAction = formActions?.[index] as ActionSCC;
const result = await validateSCCAction(SCCAction, network);
const result = await validateSCCAction(SCCAction);
return result;
}
default:
Expand All @@ -263,22 +261,13 @@ export async function actionsAreValid(
return isValid;
}

export async function validateSCCAction(
SCCAction: ActionSCC,
network: SupportedNetworks
) {
const etherscanData = await getEtherscanVerifiedContract(
SCCAction.contractAddress,
network
);
export async function validateSCCAction(SCCAction: ActionSCC) {
// looping through selectedAction.inputs instead of the actionInputs
// will allow us to ignore the payable input so that encoding using
// The ABI is coming from the selected action distinguishing between
// proxy or implementation ABI

if (
etherscanData.status === '1' &&
etherscanData.result[0].ABI !== 'Contract source code not verified'
) {
// looping through selectedAction.inputs instead of the actionInputs
// will allow us to ignore the payable input so that encoding using
// the ABI does not complain
if (SCCAction?.actions) {
const functionParams = SCCAction.inputs
?.filter(input => input.name !== getDefaultPayableAmountInputName(i18n.t))
.map(input => {
Expand All @@ -290,7 +279,7 @@ export async function validateSCCAction(
return param;
});

const iface = new ethers.utils.Interface(etherscanData.result[0].ABI);
const iface = new ethers.utils.Interface(SCCAction.actions);

try {
iface.encodeFunctionData(SCCAction.functionName, functionParams);
Expand All @@ -299,6 +288,7 @@ export async function validateSCCAction(
return false;
}
}

return false;
}

Expand Down

0 comments on commit 32bb1d5

Please sign in to comment.