This repository was archived by the owner on Aug 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
metadata refactor , example #88
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { useMetadata } from '@oceanprotocol/react' | ||
|
||
export function MetadataExample({ did }: { did: string }) { | ||
const { title, isLoaded, getBestPrice } = useMetadata(did) | ||
const [price, setPrice] = useState<string>() | ||
|
||
useEffect(() => { | ||
async function init(): Promise<void> { | ||
if (isLoaded) { | ||
const price = await getBestPrice() | ||
setPrice(price) | ||
} | ||
} | ||
init() | ||
}, [isLoaded]) | ||
|
||
return ( | ||
<> | ||
<div> | ||
{title} - {price} | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we not move this into the hook? So that
const { bestPrice } = useMetadata(did)
would work?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm confused, you say not to move it in the hook but then you want to use it in the hook
const { bestPrice } = useMetadata(did)
? or am i understanding it wrong?I didn't add
bestPrice
to reduce number of calls but if i think more, you would use this in an asset details page were you need all the metadata. So i'll addbestPrice
and keepgetBestPrice
in case you don't want to load the whole ddo withuseMetadata(did)
and you just want to get a price for a data token likeconst { getBestPrice } = useMetadata() ; const price = getBestPrice(dtAddress)
useMetadata
has 3 uses:useMetadata(did)
: it gets the ddo and then loads all the values (title, metadata etc)useMetadata(ddo)
: it uses the passed ddo and the loads all the values, in case you already got a list of ddo, so you don't have to fetch the ddo once againuseMetadata()
: loads nothing, useful for using functions like getBestPrice or getBestPool (maybe more in the future) with minimal callsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry, confusing wording indeed, I meant to move it into the hook and if there is any reason not to do it. So your change is perfect :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and your 3 uses explanation list here is super useful, we should add this to the readme in https://github.com/oceanprotocol/react/tree/main/src/hooks/useMetadata so it doesn't get lost