mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
docs updates
This commit is contained in:
parent
bf689e7c02
commit
bc62cbc22e
@ -9,6 +9,7 @@ import React from 'react'
|
|||||||
import { useOcean, useConsume } from '@oceanprotocol/react'
|
import { useOcean, useConsume } from '@oceanprotocol/react'
|
||||||
|
|
||||||
const did = 'did:op:0x000000000'
|
const did = 'did:op:0x000000000'
|
||||||
|
const dtBalance = 20
|
||||||
|
|
||||||
export default function MyComponent() {
|
export default function MyComponent() {
|
||||||
const { accountId } = useOcean()
|
const { accountId } = useOcean()
|
||||||
@ -16,10 +17,16 @@ export default function MyComponent() {
|
|||||||
// Get metadata for this asset
|
// Get metadata for this asset
|
||||||
const { title, price, ddo } = useMetadata(did)
|
const { title, price, ddo } = useMetadata(did)
|
||||||
|
|
||||||
|
// Pricing helpers
|
||||||
|
const { buyDT } = usePricing(ddo)
|
||||||
|
|
||||||
// Consume helpers
|
// Consume helpers
|
||||||
const { consume, consumeStep } = useConsume()
|
const { consume, consumeStep } = useConsume()
|
||||||
|
|
||||||
|
const hasDatatoken = dtBalance >= 1
|
||||||
|
|
||||||
async function handleDownload() {
|
async function handleDownload() {
|
||||||
|
!hasDatatoken && (await buyDT('1'))
|
||||||
await consume(did, ddo.dataToken, 'access')
|
await consume(did, ddo.dataToken, 'access')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export const consumeFeedback: { [key in number]: string } = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function useConsume(): UseConsume {
|
function useConsume(): UseConsume {
|
||||||
const { ocean, account, accountId, config } = useOcean()
|
const { ocean, account, accountId } = useOcean()
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [consumeStep, setConsumeStep] = useState<number | undefined>()
|
const [consumeStep, setConsumeStep] = useState<number | undefined>()
|
||||||
const [consumeStepText, setConsumeStepText] = useState<string | undefined>()
|
const [consumeStepText, setConsumeStepText] = useState<string | undefined>()
|
||||||
@ -43,6 +43,7 @@ function useConsume(): UseConsume {
|
|||||||
marketFeeAddress: string
|
marketFeeAddress: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!ocean || !account || !accountId) return
|
if (!ocean || !account || !accountId) return
|
||||||
|
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
setConsumeError(undefined)
|
setConsumeError(undefined)
|
||||||
|
|
||||||
|
@ -12,8 +12,14 @@ import { Metadata, DDO } from '@oceanprotocol/lib'
|
|||||||
export default function MyComponent({ ddo }: { ddo: DDO }) {
|
export default function MyComponent({ ddo }: { ddo: DDO }) {
|
||||||
const { accountId } = useOcean()
|
const { accountId } = useOcean()
|
||||||
|
|
||||||
// Publish helpers
|
// Pricing helpers
|
||||||
const { createPricing } = usePricing(ddo)
|
const {
|
||||||
|
createPricing,
|
||||||
|
buyDT,
|
||||||
|
sellDT,
|
||||||
|
pricingStepText,
|
||||||
|
pricingError
|
||||||
|
} = usePricing(ddo)
|
||||||
|
|
||||||
const priceOptions = {
|
const priceOptions = {
|
||||||
price: 10,
|
price: 10,
|
||||||
|
@ -137,7 +137,7 @@ function OceanProvider({
|
|||||||
}
|
}
|
||||||
async function logout() {
|
async function logout() {
|
||||||
// TODO: #67 check how is the proper way to logout
|
// TODO: #67 check how is the proper way to logout
|
||||||
if (web3Modal) web3Modal.clearCachedProvider()
|
web3Modal?.clearCachedProvider()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: #68 Refetch balance periodically, or figure out some event to subscribe to
|
// TODO: #68 Refetch balance periodically, or figure out some event to subscribe to
|
||||||
|
Loading…
Reference in New Issue
Block a user