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

Add NFT Gallery and NFT components #46

Merged

Conversation

etr2460
Copy link
Contributor

@etr2460 etr2460 commented Dec 1, 2021

This PR adds 2 new components to web3-ui: NFTGallery and NFT

NFTGallery calls the opensea API to fetch all the assets owned by a given wallet. It then uses the NFT component to render these in a grid.

A couple limitations:

  • Requires on the opensea API (sooo web2) because there isn't a decent way of getting all tokens owned by a wallet
  • Only works with image NFTs
  • Shows minimal metadata about the NFT

Obviously theres a bunch of future work that can be done here, but this was me getting to learn how to use Chakra-UI mainly. Some future enhancements:

  • Add a wrapper around NFT (and make the current implementation private) that uses a tokenId and contract address to fetch metadata about it
  • Support other NFT types (audio, video, etc.)
  • add more metadata about the nfts

Test Plan

Added new stories and unit tests. This included the introduction of msw for mocking API responses (thanks Kent C. Dodds).

Screen Shot 2021-11-30 at 11 38 23 PM
Screen Shot 2021-11-30 at 11 38 29 PM

to: @Dhaiwat10 @crondinini @with-heart

@etr2460 etr2460 force-pushed the erik-ritter--add-nft-components branch 2 times, most recently from 0663c8c to d239e94 Compare December 1, 2021 07:53
fetch(`https://api.opensea.io/api/v1/assets?owner=${address}`)
.then((res) => res.json())
.then((data) => setNfts(data.assets));
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't address be inside the dependencies-array? In case someone switches his active account on metamask for example.

Could be I'm wrong, not quite that familar on how it works yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're 100% right. thanks for catching this

@etr2460 etr2460 force-pushed the erik-ritter--add-nft-components branch from d239e94 to 6837848 Compare December 1, 2021 16:25
@etr2460 etr2460 mentioned this pull request Dec 1, 2021
10 tasks
Copy link
Contributor

@crondinini crondinini left a comment

Choose a reason for hiding this comment

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

Can't comment on the Chakra bit but everything else looks great! Added just some comments for discussion

useEffect(() => {
fetch(`https://api.opensea.io/api/v1/assets?owner=${address}`)
.then((res) => res.json())
.then((data) => setNfts(data.assets));
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to proactively catch any error that might occur from opensea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yeah, error handling is a good idea :P i'll add it in (along with a unit test for it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

basic error handing added, this could be improved in the future, but will work for now

// File with API handlers shared across all tests.
// See https://kentcdodds.com/blog/stop-mocking-fetch for more details

import { rest } from "msw";
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes 🎸

* TODO: Add a component that fetchs the NFT data from the blockchain and uses this component to
* display it
*/
export const NFT = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it would make sense to add a link to see it in etherscan?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll iterate more on this in a future PR. i wanna look into more nft types, more metadata/attributes, link in etherscan, etc.

@Dhaiwat10 Dhaiwat10 self-requested a review December 2, 2021 00:48
@Dhaiwat10
Copy link
Member

Thanks for this @etr2460! Feel free to merge this in since I might not be able to review until much later today. :)

@Dhaiwat10
Copy link
Member

@allcontributors add @etr2460 for code, review

@allcontributors
Copy link
Contributor

@Dhaiwat10

I've put up a pull request to add @etr2460! 🎉

@Dhaiwat10
Copy link
Member

@allcontributors add @crondinini for code, review

@allcontributors
Copy link
Contributor

@Dhaiwat10

I've put up a pull request to add @crondinini! 🎉

@Dhaiwat10
Copy link
Member

sorry for the spam <3

@etr2460 etr2460 force-pushed the erik-ritter--add-nft-components branch from 6837848 to 34631de Compare December 2, 2021 18:58
@etr2460 etr2460 merged commit 47832dd into Developer-DAO:master Dec 2, 2021
@etr2460 etr2460 mentioned this pull request Dec 3, 2021
6 tasks
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.

4 participants