1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-02-14 21:10:38 +01:00

publish tweaks

This commit is contained in:
Matthias Kretschmann 2020-10-19 13:39:14 +02:00
parent bc62cbc22e
commit 1cd3c6055d
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 10 additions and 14 deletions

View File

@ -57,6 +57,7 @@ function useConsume(): UseConsume {
setConsumeError('Not enough datatokens') setConsumeError('Not enough datatokens')
} else { } else {
setStep(1) setStep(1)
ocean.datatokens.generateDtName()
const tokenTransfer = await ocean.assets.order( const tokenTransfer = await ocean.assets.order(
did as string, did as string,
serviceType, serviceType,

View File

@ -1,6 +1,6 @@
# `usePublish` # `usePublish`
Create datatoken and publish data sets Publish data sets and create datatokens for them.
## Usage ## Usage
@ -10,7 +10,7 @@ import { useOcean, usePublish } from '@oceanprotocol/react'
import { Metadata } from '@oceanprotocol/lib' import { Metadata } from '@oceanprotocol/lib'
export default function MyComponent() { export default function MyComponent() {
const { accountId } = useOcean() const { ocean, accountId } = useOcean()
// Publish helpers // Publish helpers
const { publish, publishStep } = usePublish() const { publish, publishStep } = usePublish()
@ -24,12 +24,10 @@ export default function MyComponent() {
} }
} }
const dataTokenOptions = {
}
async function handlePublish() { async function handlePublish() {
const ddo = await publish(metadata, 'access', dataTokenOptions) const ddo = await publish(metadata, 'access')
// Heads Up! You should now create pricing for your data set
// with the `usePricing()` hook in another step.
} }
return ( return (

View File

@ -14,7 +14,7 @@ interface UsePublish {
publish: ( publish: (
asset: Metadata, asset: Metadata,
serviceConfigs: ServiceType, serviceConfigs: ServiceType,
dataTokenOptions: DataTokenOptions, dataTokenOptions?: DataTokenOptions,
timeout?: number, timeout?: number,
providerUri?: string providerUri?: string
) => Promise<DDO | undefined | null> ) => Promise<DDO | undefined | null>
@ -25,7 +25,7 @@ interface UsePublish {
} }
function usePublish(): UsePublish { function usePublish(): UsePublish {
const { ocean, status, account, accountId, config } = useOcean() const { ocean, status, account } = useOcean()
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const [publishStep, setPublishStep] = useState<number | undefined>() const [publishStep, setPublishStep] = useState<number | undefined>()
const [publishStepText, setPublishStepText] = useState<string | undefined>() const [publishStepText, setPublishStepText] = useState<string | undefined>()
@ -46,7 +46,7 @@ function usePublish(): UsePublish {
async function publish( async function publish(
asset: Metadata, asset: Metadata,
serviceType: ServiceType, serviceType: ServiceType,
dataTokenOptions: DataTokenOptions, dataTokenOptions?: DataTokenOptions,
timeout?: number, timeout?: number,
providerUri?: string providerUri?: string
): Promise<DDO | undefined | null> { ): Promise<DDO | undefined | null> {
@ -57,10 +57,9 @@ function usePublish(): UsePublish {
try { try {
const publishedDate = const publishedDate =
new Date(Date.now()).toISOString().split('.')[0] + 'Z' new Date(Date.now()).toISOString().split('.')[0] + 'Z'
let timeout = 0
const services: Service[] = [] const services: Service[] = []
const price = '1' const price = '1'
switch (serviceType) { switch (serviceType) {
case 'access': { case 'access': {
if (!timeout) timeout = 0 if (!timeout) timeout = 0
@ -142,8 +141,6 @@ function usePublish(): UsePublish {
.next(setStep) .next(setStep)
Logger.log('ddo created', ddo) Logger.log('ddo created', ddo)
setStep(7) setStep(7)
// await createPricing(priceOptions, ddo.dataToken, tokensToMint)
// setStep(8)
return ddo return ddo
} catch (error) { } catch (error) {
setPublishError(error.message) setPublishError(error.message)