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

[BREAKING] - Create get token standard method / Standardize ERC721/1155/20 method names #667

Merged
merged 11 commits into from
Jan 10, 2022

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Dec 20, 2021

  • CHANGED:

    • BREAKING Renames many methods on the AssetsContractController to include the contract type they are used by in the name. This change is entirely to enhance legibility and maintainability as more contract types are supported.
  • ADDED:

    • Adds a single method getTokenStandardAndDetails to determine whether the input contract confirms to particular known token standard (ERC20, ERC721 or ERC1155) and return the detected standard along with some key values/details about that the contract that pertain to that standard. These additional details may include, in the case of an ERC721, for example, details about a specific tokenId within that contract, or, in the case of ERC20, the balance of the current user in the contract.

@adonesky1 adonesky1 force-pushed the create-getTokenStandard-method branch 3 times, most recently from 5ac4d99 to 93fecae Compare December 24, 2021 23:39
@adonesky1 adonesky1 marked this pull request as ready for review December 26, 2021 20:04
@adonesky1 adonesky1 requested a review from a team as a code owner December 26, 2021 20:04
@wachunei
Copy link
Member

Random ideas:

  • Instead of waterfalling, could we use Promise.allSettled
  • Could we also turn those promises into utils, private methods or members of the standard itself

@adonesky1 adonesky1 force-pushed the create-getTokenStandard-method branch 2 times, most recently from 417171d to 8fd61c5 Compare January 3, 2022 19:47
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

A couple of cleanup things and a question.

src/assets/AssetsContractController.ts Outdated Show resolved Hide resolved
src/assets/Standards/ERC20Standard.ts Outdated Show resolved Hide resolved
src/assets/Standards/ERC20Standard.ts Outdated Show resolved Hide resolved
@adonesky1 adonesky1 force-pushed the create-getTokenStandard-method branch 2 times, most recently from febe905 to e3f606f Compare January 3, 2022 23:20
@wachunei
Copy link
Member

wachunei commented Jan 4, 2022

Another idea for the future: make the standard class extend a base standard class that has web3 in the constructor arguments

@adonesky1 adonesky1 force-pushed the create-getTokenStandard-method branch 2 times, most recently from 5ed0370 to 6f2e400 Compare January 4, 2022 16:41
@adonesky1 adonesky1 changed the title Create get token standard method Create get token standard method / Standardize ERC721/1155/20 method names Jan 4, 2022
wachunei
wachunei previously approved these changes Jan 4, 2022
Comment on lines +829 to +834
getERC721AssetName,
getERC721AssetSymbol,
getERC721TokenURI,
getERC721OwnerOf,
getERC1155BalanceOf,
getERC1155TokenURI,
Copy link
Member

Choose a reason for hiding this comment

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

so much better 👌

@adonesky1 adonesky1 force-pushed the create-getTokenStandard-method branch from 76e1b9c to f5ae2a9 Compare January 5, 2022 19:20
@adonesky1
Copy link
Contributor Author

@wachunei @mcmire rebased and added this commit: f5ae2a9, which mocks all network requests for test files that were added/touched. Take another look when you have a chance.

@adonesky1 adonesky1 force-pushed the create-getTokenStandard-method branch 2 times, most recently from f1825ad to 9591559 Compare January 5, 2022 19:34
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looks better, just a few suggestions.

@gantunesr
Copy link
Member

Can you add "[BREAKING]" to the title of the PR so it's easier to identify?

@adonesky1 adonesky1 changed the title Create get token standard method / Standardize ERC721/1155/20 method names [BREAKING] - Create get token standard method / Standardize ERC721/1155/20 method names Jan 7, 2022
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Did another pass and there were a few things I noticed.

src/assets/AssetsContractController.ts Outdated Show resolved Hide resolved
src/assets/AssetsContractController.ts Outdated Show resolved Hide resolved
src/assets/CollectiblesController.ts Show resolved Hide resolved
private web3: any;

constructor(web3?: any) {
this.web3 = web3;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use a type for this instead of any? And why is web3 optional? It seems that everything in this class relies on web3 being provided.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with you @mcmire, but I think for this we have to upgrade the web3 dependence, which could be done in another PR. But I'm not against this if @adonesky1 wants to upgrade the module in this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, does web3 provide types now? I agree that we probably wouldn't want to upgrade it in this PR, but I was thinking in the meantime we could give this property a type on the spot based on how we end up using it in this class. For instance:

type ERC1155ABI = ...;
type Address = `0x${string}`

type Contract = {
  at: Address
}

type Web3 = {
  eth: {
    contract: (abi: ERC1155ABI): Contract
  }
}

That said, I don't believe that abiERC1155 in @metamask/metamask-eth-abis has the right type on it. My feeling is that all of the objects that that module exports should have as const on them. Right now it's possible to pass an ABI that has the same shape but isn't exactly the ERC-1155 ABI. Maybe we could have a generic ABI type to get around this, but then we'd be repeating work that is probably elsewhere. So maybe this is fine for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be logged somewhere for tech debt purposes, though?

Copy link
Member

Choose a reason for hiding this comment

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

Thats a good point, I think that could work in the meantime for this PR. For future development we should upgrade this module and use the types provided by web3 or start using the ethers dependence. I remember that extension changed from web3 to ethers, would be easier if we all use the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I am definitely a fan of using ethers. It feels a lot more maintained at this point and is fully typed, and I think we can avoid the pain that we've been experiencing with web3. Of course that's a larger change but that'd be my recommendation for new code going forward.

Copy link
Contributor Author

@adonesky1 adonesky1 Jan 7, 2022

Choose a reason for hiding this comment

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

I've made updates here: 8effcaf and here c9abc81, that I believe should address these concerns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mcmire @gantunesr take a look and let me know what you think

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good, thank you!

src/assets/Standards/ERC20Standard.ts Outdated Show resolved Hide resolved
@gantunesr
Copy link
Member

LGTM. I'll wait for the other comments to be resolved before approving.

@adonesky1 adonesky1 force-pushed the create-getTokenStandard-method branch from 8fe5ccc to 086ecdf Compare January 7, 2022 19:29
@adonesky1 adonesky1 force-pushed the create-getTokenStandard-method branch from 086ecdf to c9abc81 Compare January 7, 2022 19:32
@adonesky1 adonesky1 requested a review from mcmire January 7, 2022 19:55
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

This all looks good to me! Thanks for enduring all of the feedback 😅

Copy link
Member

@gantunesr gantunesr left a comment

Choose a reason for hiding this comment

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

LGTM

@gantunesr
Copy link
Member

Hey @adonesky1, I just noticed that you added the method symbol from the ERC20 contract, in the metamask-eth-abis module there are tests to ensure that no one removes the methods we're using from the ABIs. We have to add the test for symbol, I can do it next week.

@adonesky1
Copy link
Contributor Author

We have to add the test for symbol, I can do it next week.

You mean to the metamask-eth-abis repo right?

@gantunesr
Copy link
Member

You mean to the metamask-eth-abis repo right?

Yes

@adonesky1 adonesky1 merged commit c38f798 into main Jan 10, 2022
@adonesky1 adonesky1 deleted the create-getTokenStandard-method branch January 10, 2022 16:19
@adonesky1 adonesky1 mentioned this pull request Jan 10, 2022
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
…55/20 method names (#667)

* add getTokenStandard method

* standardize method name patterns

* improve typing
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
…55/20 method names (#667)

* add getTokenStandard method

* standardize method name patterns

* improve typing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants