mirror of
https://github.com/oceanprotocol/react.git
synced 2025-01-05 11:25:18 +01:00
readme update
This commit is contained in:
parent
6809183b5d
commit
7fa93ae5b5
15
README.md
15
README.md
@ -64,7 +64,8 @@ export default function MyComponent() {
|
|||||||
const { ocean, web3, account } = useOcean()
|
const { ocean, web3, account } = useOcean()
|
||||||
|
|
||||||
// Get metadata for this asset
|
// Get metadata for this asset
|
||||||
const { title, metadata } = useMetadata(did)
|
const { title, metadata, isLoaded, getBestPrice } = useMetadata(did)
|
||||||
|
const [price, setPrice] = useState<string>()
|
||||||
|
|
||||||
// publish asset
|
// publish asset
|
||||||
const { publish, publishStep } = usePublish()
|
const { publish, publishStep } = usePublish()
|
||||||
@ -72,6 +73,16 @@ export default function MyComponent() {
|
|||||||
// consume asset
|
// consume asset
|
||||||
const { consume, consumeStep } = useConsume()
|
const { consume, consumeStep } = useConsume()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function init(): Promise<void> {
|
||||||
|
if (isLoaded) {
|
||||||
|
const price = await getBestPrice()
|
||||||
|
setPrice(price)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
init()
|
||||||
|
}, [isLoaded])
|
||||||
|
|
||||||
async function handleDownload() {
|
async function handleDownload() {
|
||||||
await consume(did)
|
await consume(did)
|
||||||
}
|
}
|
||||||
@ -79,7 +90,7 @@ export default function MyComponent() {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>{title}</h1>
|
<h1>{title}</h1>
|
||||||
<p>Price: {web3.utils.fromWei(metadata.main.price)}</p>
|
<p>Price: {price}</p>
|
||||||
|
|
||||||
<p>Your account: {account}</p>
|
<p>Your account: {account}</p>
|
||||||
<button onClick={handleDownload}>
|
<button onClick={handleDownload}>
|
||||||
|
@ -2,18 +2,18 @@ import React, { useEffect, useState } from 'react'
|
|||||||
import { useMetadata } from '@oceanprotocol/react'
|
import { useMetadata } from '@oceanprotocol/react'
|
||||||
|
|
||||||
export function MetadataExample({ did }: { did: string }) {
|
export function MetadataExample({ did }: { did: string }) {
|
||||||
const { title, getBestPrice } = useMetadata(did)
|
const { title, isLoaded, getBestPrice } = useMetadata(did)
|
||||||
const [price, setPrice] = useState<string>()
|
const [price, setPrice] = useState<string>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function init(): Promise<void> {
|
async function init(): Promise<void> {
|
||||||
if (title) {
|
if (isLoaded) {
|
||||||
const price = await getBestPrice()
|
const price = await getBestPrice()
|
||||||
setPrice(price)
|
setPrice(price)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init()
|
init()
|
||||||
}, [title])
|
}, [isLoaded])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
Loading…
Reference in New Issue
Block a user