Skip to content
This repository was archived by the owner on Aug 3, 2021. It is now read-only.

metadata refactor , example #88

Merged
merged 5 commits into from
Aug 19, 2020
Merged

metadata refactor , example #88

merged 5 commits into from
Aug 19, 2020

Conversation

mihaisc
Copy link
Contributor

@mihaisc mihaisc commented Aug 19, 2020

No description provided.

const { title, isLoaded, getBestPrice } = useMetadata(did)
const [price, setPrice] = useState<string>()

useEffect(() => {
Copy link
Contributor

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?

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'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 add bestPrice and keep getBestPrice in case you don't want to load the whole ddo with useMetadata(did) and you just want to get a price for a data token like const { 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 again
  • useMetadata() : loads nothing, useful for using functions like getBestPrice or getBestPool (maybe more in the future) with minimal calls

Copy link
Contributor

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 :-)

Copy link
Contributor

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

@mihaisc mihaisc merged commit af76d90 into main Aug 19, 2020
@mihaisc mihaisc deleted the feature/metadata branch August 19, 2020 16:08
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants