Closed sekaiking closed 2 years ago
This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.
🔍 Inspect: https://vercel.com/curaos/frontend/4GXLmweRT84guYe8kEexhZC1grEy
✅ Preview: https://frontend-git-components-hooks-curaos.vercel.app
RenderIframe
need to be able to fetch the NFT Url and handle its content accordingly instead of using Iframe. So that we have more control over how its being displayed.
I was looking more into this, and there is a simpler solution.
All we get from the blockchain is the media URL, and this URL can be (html, image, video, audio). The metadata from blockchain doesn't tell us the type, so we have to figure it out,
How? We can fetch the HEAD of the Url, to determine the media type, then Render it depending on the type.
For example:
fetch(mediaURI, { method: 'HEAD' }).then((r) => {
const cType = r.headers.get('Content-type')
if (cType.includes('image')) {
// Use img tag
} else if (cType.includes('video')) {
// Use video tag
} else if (cType.includes('audio')) {
// Use audio tag
} else {
// Use iframe tag
}
})
And I think it would be better, if we made a component that handle all types of media. (Like this one: https://github.com/contextart/nfte/blob/main/packages/react/src/components/Media.tsx)
a Media component, which will take (MediaUrl, Size) as props and use the mentioned function above to detect media type and renders the media accordingly.
This would also simplify the frontend example, currently it uses RenderIframe or img hardcoded depending on the project type.
Media
componentRenderIframe
or move it inside MediauseNFTContentType
hook to fetch NFT contentType from provided URI
useViewNFTMethod
hook to use NFT contract view methods without needing user account
MediaObject
component, it take a mediaURI and returns the matching element
frontend now uses MediaObject
to show NFT medias
RenderIframe
component has been removed and replace with MediaObject
new hooks for NFT + simple unit tests + README for the hooks
NFTE
component updated to support NFTs from Mintbase and Paras.id
Some other components have been improved
Currently we can test NFTE component only for contracts on testnet
network, unless you change it manually from the hooks package. If you get an error while testing different contracts that's the reason.
New
Sub Components
Placeholder
component, to be used within others component to improve UX. It's just a component that returns an animated box with custom height, width, and possibility to add additional styles using props.Components
NFTE
is the new component mentioned in #9 , it rely onMetadata
andRenderiframe
components for UI and has a dark mode. And for the NFT data, it's fetching it using near-api-js internally with a function (which need to be replaced with a hook on the future)Changed
Metadata
component changed to display more info, now it can display (title, creator, owner, description). It has also a loading animation while we fetch data from server use 'loading' prop.Issues
NFTE
component need to use a hook for fetching NFTs instead of doing it internally.RenderIframe
component doesn't display images properly when the iframe content is larger than its size.Suggestions
RenderIframe
need to be able to fetch the NFT Url and handle its content accordingly instead of using Iframe. So that we have more control over how its being displayed.