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**: Fetch and return token image as part of getDetails calls on ERC721Standard and ERC1155Standard #702

Merged
merged 3 commits into from
Mar 3, 2022

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Mar 2, 2022

  • ADDED:

    • BREAKING Adds functionality to fetch and return token images as part of getDetails calls on ERC721Standard and ERC1155Standard
      • This change is breaking because it requires that the AssetsContractController (on which the ERC721Standard and ERC1155Standard are instantiated) be passed a listener for onPreferencesStateChange from the PreferencesController so that it can use the user's preferred IPFSGateway to fetch any images hosted on IPFS. Consumers will have to pass onPreferencesStateChange in an options object (first arg) to the AssetsContractController constructor when initializing.

Resolves #689

@adonesky1 adonesky1 force-pushed the return-token-image-from-getDetails branch from 386f39f to 529638f Compare March 2, 2022 21:24
@adonesky1 adonesky1 force-pushed the return-token-image-from-getDetails branch 2 times, most recently from 90c459e to fb4fa72 Compare March 2, 2022 23:17
@adonesky1 adonesky1 changed the title BREAKING: Fetch and return token image as part of getDetails` calls on ERC721Standard and ERC1155Standard **BREAKING**: Fetch and return token image as part of getDetails calls on ERC721Standard and ERC1155Standard Mar 2, 2022
@adonesky1 adonesky1 marked this pull request as ready for review March 2, 2022 23:23
@adonesky1 adonesky1 requested a review from a team as a code owner March 2, 2022 23:23
wachunei
wachunei previously approved these changes Mar 3, 2022
Copy link
Member

@wachunei wachunei left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Three questions:

  1. Are the new tests for getDetails actually hitting the IPFS gateway? I see you were trying to use Nock to mock some kind of API, perhaps it would be worth doing this for the IPFS gateway? This raises the question of "how should we handle external APIs in tests?" again.
  2. Perhaps tying into 1, is it possible to test the case in which getDetails returns a non-nullish value for image in the expected set of data?
  3. How are we testing the new change to AssetsContractController where onPreferencesStateChange can update the configuration object?

@adonesky1
Copy link
Contributor Author

Three questions:

All good callouts. Will add/modify tests to address these concerns.

@adonesky1 adonesky1 force-pushed the return-token-image-from-getDetails branch from ad4599c to cec4496 Compare March 3, 2022 19:44
standard: 'ERC721',
symbol: 'BAYC',
tokenURI:
'https://bafybeihpjhkeuiq3k6nqa3fkgeigeri7iebtrsuyuey5y6vy36n345xmbi.ipfs.cloudflare-ipfs.com/3',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

tokenURI hosted on IPFS cc @mcmire @wachunei

image: 'https://card.godsunchained.com/?id=1329&q=4',
};
});

const expectedResult = {
name: 'Gods Unchained',
standard: 'ERC721',
symbol: 'GODS',
tokenURI: 'https://api.godsunchained.com/card/4',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

tokenURI not hosted on IPFS cc @mcmire @wachunei

Comment on lines +36 to +44
it('should update the ipfsGateWay config value when this value is changed in the preferences controller', () => {
expect(assetsContract.config).toStrictEqual({
ipfsGateway: IPFS_DEFAULT_GATEWAY_URL,
provider: undefined,
});

preferences.setIpfsGateway('newIPFSGateWay');
expect(assetsContract.config).toStrictEqual({
ipfsGateway: 'newIPFSGateWay',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

test new preferences listener updates to controller config values cc @mcmire

@adonesky1
Copy link
Contributor Author

@mcmire I accidentally squashed commits but I've addressed your feedback here: cec4496

@wachunei could you take another look too when you have a chance 😄

@adonesky1
Copy link
Contributor Author

adonesky1 commented Mar 3, 2022

Thanks for updating these tests. For these types of tests where you've modified how the controller is instantiated so that you now pass onPreferencesStateChange, does this have any effect on the tests?

For all except the test I added on AssetsContractController.test.ts you could pass

onPreferencesStateChange: (listener) => {
    // do nothing
  }

cc @mcmire
I think we write many unit tests for these controllers where the passed in listeners are not actively used by the test but are required by the constructor.

@adonesky1 adonesky1 merged commit 613c5b9 into main Mar 3, 2022
@adonesky1 adonesky1 deleted the return-token-image-from-getDetails branch March 3, 2022 21:22
@adonesky1 adonesky1 mentioned this pull request Mar 8, 2022
soralit pushed a commit to KeystoneHQ/controllers that referenced this pull request Mar 14, 2022
…lls on ERC721Standard and ERC1155Standard (MetaMask#702)

* Fetch and return token image as part of getDetails call

* adapt tests
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
…lls on ERC721Standard and ERC1155Standard (#702)

* Fetch and return token image as part of getDetails call

* adapt tests
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
…lls on ERC721Standard and ERC1155Standard (#702)

* Fetch and return token image as part of getDetails call

* adapt tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants