mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
Merge pull request #139 from oceanprotocol/fix/marketplace-fee
pass through mpAddress
This commit is contained in:
commit
d9c6a9db74
@ -9,7 +9,7 @@ import { useState } from 'react'
|
|||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
export function ConsumeDdo() {
|
export function ConsumeDdo() {
|
||||||
const { ocean } = useOcean()
|
const { ocean, accountId } = useOcean()
|
||||||
const { consumeStepText, consume, consumeError } = useConsume()
|
const { consumeStepText, consume, consumeError } = useConsume()
|
||||||
const { compute, computeStepText } = useCompute()
|
const { compute, computeStepText } = useCompute()
|
||||||
const [did, setDid] = useState<string | undefined>()
|
const [did, setDid] = useState<string | undefined>()
|
||||||
@ -22,7 +22,8 @@ export function ConsumeDdo() {
|
|||||||
if (!did) return
|
if (!did) return
|
||||||
const ddo = await ocean.assets.resolve(did)
|
const ddo = await ocean.assets.resolve(did)
|
||||||
|
|
||||||
await consume(did, ddo.dataToken, 'access')
|
// use own accountId for marketFeeAddress for testing purposes
|
||||||
|
await consume(did, ddo.dataToken, 'access', accountId)
|
||||||
}
|
}
|
||||||
|
|
||||||
const computeDid = async () => {
|
const computeDid = async () => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useOcean } from 'providers'
|
import { useOcean } from 'providers'
|
||||||
import { ComputeValue } from './ComputeOptions'
|
import { ComputeValue } from './ComputeOptions'
|
||||||
import { Logger } from '@oceanprotocol/lib'
|
import { Logger, ServiceCompute } from '@oceanprotocol/lib'
|
||||||
import { MetadataAlgorithm } from '@oceanprotocol/lib/dist/node/ddo/interfaces/MetadataAlgorithm'
|
import { MetadataAlgorithm } from '@oceanprotocol/lib/dist/node/ddo/interfaces/MetadataAlgorithm'
|
||||||
import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/ComputeJob'
|
import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/ComputeJob'
|
||||||
import { checkAndBuyDT } from 'utils/dtUtils'
|
import { checkAndBuyDT } from 'utils/dtUtils'
|
||||||
@ -9,10 +9,11 @@ import { checkAndBuyDT } from 'utils/dtUtils'
|
|||||||
interface UseCompute {
|
interface UseCompute {
|
||||||
compute: (
|
compute: (
|
||||||
did: string,
|
did: string,
|
||||||
computeService: any,
|
computeService: ServiceCompute,
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
algorithmRawCode: string,
|
algorithmRawCode: string,
|
||||||
computeContainer: ComputeValue
|
computeContainer: ComputeValue,
|
||||||
|
marketFeeAddress: string
|
||||||
) => Promise<ComputeJob | void>
|
) => Promise<ComputeJob | void>
|
||||||
computeStep?: number
|
computeStep?: number
|
||||||
computeStepText?: string
|
computeStepText?: string
|
||||||
@ -57,10 +58,11 @@ function useCompute(): UseCompute {
|
|||||||
|
|
||||||
async function compute(
|
async function compute(
|
||||||
did: string,
|
did: string,
|
||||||
computeService: any,
|
computeService: ServiceCompute,
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
algorithmRawCode: string,
|
algorithmRawCode: string,
|
||||||
computeContainer: ComputeValue
|
computeContainer: ComputeValue,
|
||||||
|
marketFeeAddress: string
|
||||||
): Promise<ComputeJob | void> {
|
): Promise<ComputeJob | void> {
|
||||||
if (!ocean || !account) return
|
if (!ocean || !account) return
|
||||||
|
|
||||||
@ -80,14 +82,16 @@ function useCompute(): UseCompute {
|
|||||||
accountId,
|
accountId,
|
||||||
did,
|
did,
|
||||||
computeService,
|
computeService,
|
||||||
rawAlgorithmMeta
|
rawAlgorithmMeta,
|
||||||
|
marketFeeAddress
|
||||||
)
|
)
|
||||||
const tokenTransfer = await ocean.compute.order(
|
const tokenTransfer = await ocean.compute.order(
|
||||||
accountId,
|
accountId,
|
||||||
did,
|
did,
|
||||||
computeService.index,
|
computeService.index,
|
||||||
undefined,
|
undefined,
|
||||||
rawAlgorithmMeta
|
rawAlgorithmMeta,
|
||||||
|
marketFeeAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
setStep(1)
|
setStep(1)
|
||||||
@ -108,7 +112,7 @@ function useCompute(): UseCompute {
|
|||||||
undefined,
|
undefined,
|
||||||
rawAlgorithmMeta,
|
rawAlgorithmMeta,
|
||||||
output,
|
output,
|
||||||
computeService.index,
|
`${computeService.index}`,
|
||||||
computeService.type
|
computeService.type
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
@ -14,13 +14,13 @@ export default function MyComponent() {
|
|||||||
const { accountId } = useOcean()
|
const { accountId } = useOcean()
|
||||||
|
|
||||||
// Get metadata for this asset
|
// Get metadata for this asset
|
||||||
const { title, price } = useMetadata(did)
|
const { title, price, ddo } = useMetadata(did)
|
||||||
|
|
||||||
// Consume helpers
|
// Consume helpers
|
||||||
const { consume, consumeStep } = useConsume()
|
const { consume, consumeStep } = useConsume()
|
||||||
|
|
||||||
async function handleDownload() {
|
async function handleDownload() {
|
||||||
await consume(did)
|
await consume(did, ddo.dataToken, 'access')
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -8,7 +8,8 @@ interface UseConsume {
|
|||||||
consume: (
|
consume: (
|
||||||
did: DID | string,
|
did: DID | string,
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
serviceType: ServiceType
|
serviceType: ServiceType,
|
||||||
|
marketFeeAddress: string
|
||||||
) => Promise<void>
|
) => Promise<void>
|
||||||
consumeStep?: number
|
consumeStep?: number
|
||||||
consumeStepText?: string
|
consumeStepText?: string
|
||||||
@ -39,7 +40,8 @@ function useConsume(): UseConsume {
|
|||||||
async function consume(
|
async function consume(
|
||||||
did: DID | string,
|
did: DID | string,
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
serviceType: ServiceType = 'access'
|
serviceType: ServiceType = 'access',
|
||||||
|
marketFeeAddress: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!ocean || !account || !accountId) return
|
if (!ocean || !account || !accountId) return
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
@ -53,7 +55,9 @@ function useConsume(): UseConsume {
|
|||||||
const tokenTransfer = await ocean.assets.order(
|
const tokenTransfer = await ocean.assets.order(
|
||||||
did as string,
|
did as string,
|
||||||
serviceType,
|
serviceType,
|
||||||
accountId
|
accountId,
|
||||||
|
undefined,
|
||||||
|
marketFeeAddress
|
||||||
)
|
)
|
||||||
Logger.log('order created', tokenTransfer)
|
Logger.log('order created', tokenTransfer)
|
||||||
setStep(2)
|
setStep(2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user