Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

(Fix) Contract interaction ABI resets#1394

Merged
fernandomg merged 6 commits intodevelopmentfrom
fix/#1328-contract-interaction-abi-resets
Oct 5, 2020
Merged

(Fix) Contract interaction ABI resets#1394
fernandomg merged 6 commits intodevelopmentfrom
fix/#1328-contract-interaction-abi-resets

Conversation

@fernandomg
Copy link
Contributor

This PR closes #1328, by replacing the decorator that requests the ABI information with a field mutator triggered within ContractABI component's lifecycle.

For some reason (form constantly re-rendered?), the decorator lost the status between renders. So I wasn't able to evaluate current vs previous state, to take the decisions that I'm now able to take in the ContractABI's useEffect.

This PR also comes with a plus: the user can paste the MasterCopy address of a Proxy-based contract, load the ABI and then replace the address with the Proxy address, and the ABI won't be replaced (if the Proxy has no read/write methods).

preserve-masterCopyAbi

@github-actions
Copy link

CLA Assistant Lite All Contributors have signed the CLA.

@github-actions
Copy link

github-actions bot commented Sep 23, 2020

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@ghost
Copy link

ghost commented Sep 23, 2020

Travis automatic deployment:
https://pr1394--safereact.review.gnosisdev.com/app

@ghost
Copy link

ghost commented Sep 24, 2020

Travis automatic deployment:
https://pr1394--safereact.review.gnosisdev.com/app


React.useEffect(() => {
const validateAndSetAbi = async () => {
if (!mustBeEthereumAddress(contractAddress) && !(await mustBeEthereumContractAddress(contractAddress))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm the only one having real troubles with this naming convention?

Each time I find this mustBe... with the negation I have to think twice that double negation in semantic is necessary to understand this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're not alone.

But, for the record, they are inherited from final-form validator definitions.

You can see in the documentation itself https://final-form.org/docs/react-final-form/examples/field-level-validation

If the function returns undefined, it's a valid value, if not it should return a string with the error message.

Maybe we should wrap those in another function that returns a boolean if we're going to use those validators outside the form. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes Fer, I'm with you on that wrapper. Should be handled this in this PR? or create a new one and replace all the occurrences for these cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

At least I would consider adding a conversion like this before the if clause. But if we use them in many places this for sure needs a wrapper

// Undefined is returned when no error found
const isEthereumAddress = mustBeEthereumAddress(contractAddress) === undefined
const isEthereumContractAddress = mustBeEthereumContractAddress(contractAddress) === undefined


// this check may help in scenarios where the user first pastes the ABI,
// and then sets a Proxy contract that has no useful methods
if (hasUsefulMethods(abi) === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

hasUsefulMethods should return a boolean no be consistent, otherwise, it should be getUsefulMethods.

Copy link
Contributor Author

@fernandomg fernandomg Oct 2, 2020

Choose a reason for hiding this comment

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

yes, totally... but this is a validator function. If it returns a string, there's an error with the argument, if the returned value is undefined then the argument was valid.

Once again, the same discussion as above.

const source = getConfiguredSource()
const abi = await source.getContractABI(contractAddress, network)

// this check may help in scenarios where the user first pastes the ABI,
Copy link
Contributor

Choose a reason for hiding this comment

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

should we notify the users of this functionality in the UI? Perhaps if we detect that the ABI it's a proxy, we can show a label saying that he can replace the address and the ABI won't be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure about this, I have no certainty that all the proxy contracts won't have a callable method

@fernandomg fernandomg requested a review from dasanra October 2, 2020 20:55
@ghost
Copy link

ghost commented Oct 2, 2020

Travis automatic deployment:
https://pr1394--safereact.review.gnosisdev.com/app

@francovenica
Copy link
Contributor

The issue of the ABI field cleaning itself was fixed. I tried with the ABI an address that Richard gave in the issue and it works fine in this PR
I checked as well that a contract that has no read/write methods will not replace the current ABI.

Test:

  • Copy an random address. Copy/paste and ABI, wait 15 seconds. The ABI field remains with the pasted data.
  • Copy a valid address that fills the ABI field, like the mastercopy. Replaced it with an safe's address. The ABI field is not cleaned
  • Paste a valid address that fills the ABI field. Delete and paste another valid address. The ABI field is replaced properly.

Looks good to me

@ghost
Copy link

ghost commented Oct 5, 2020

Travis automatic deployment:
https://pr1394--safereact.review.gnosisdev.com/app

@fernandomg fernandomg merged commit 5a41c38 into development Oct 5, 2020
@fernandomg fernandomg deleted the fix/#1328-contract-interaction-abi-resets branch October 5, 2020 15:13
@github-actions github-actions bot locked and limited conversation to collaborators Oct 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Abi field in contract interaction dialog resets every couple seconds

6 participants