mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
refactor ddo,did with asset
This commit is contained in:
parent
34a485b930
commit
15ded202ae
@ -33,7 +33,7 @@ export function AllDdos() {
|
|||||||
{ddos?.map((ddo) => {
|
{ddos?.map((ddo) => {
|
||||||
return (
|
return (
|
||||||
<div key={shortid.generate()}>
|
<div key={shortid.generate()}>
|
||||||
<MetadataExample did={ddo.id} />
|
<MetadataExample ddo={ddo} />
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { useMetadata } from '@oceanprotocol/react'
|
import { useMetadata } from '@oceanprotocol/react'
|
||||||
|
import { DDO } from '@oceanprotocol/lib'
|
||||||
|
|
||||||
export function MetadataExample({ did }: { did: string }) {
|
export function MetadataExample({ ddo }: { ddo: DDO }) {
|
||||||
const { title, pool } = useMetadata(did)
|
const { title, poolAddress, price } = useMetadata(ddo)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
{title} - {pool && pool.price + ' - ' + pool.address}
|
{title} - price = {price} // pool = {poolAddress}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
@ -4,6 +4,7 @@ import { useOcean } from '../../providers'
|
|||||||
import ProviderStatus from '../../providers/OceanProvider/ProviderStatus'
|
import ProviderStatus from '../../providers/OceanProvider/ProviderStatus'
|
||||||
import { getBestDataTokenPrice, getCheapestPool } from '../../utils/dtUtils'
|
import { getBestDataTokenPrice, getCheapestPool } from '../../utils/dtUtils'
|
||||||
import Pool from './Pool'
|
import Pool from './Pool'
|
||||||
|
import { isDDO } from '../../utils'
|
||||||
|
|
||||||
interface UseMetadata {
|
interface UseMetadata {
|
||||||
ddo: DDO
|
ddo: DDO
|
||||||
@ -17,7 +18,7 @@ interface UseMetadata {
|
|||||||
getPool: (dataTokenAddress?: string) => Promise<Pool>
|
getPool: (dataTokenAddress?: string) => Promise<Pool>
|
||||||
}
|
}
|
||||||
|
|
||||||
function useMetadata(did?: DID | string, ddo?: DDO): UseMetadata {
|
function useMetadata(asset?: DID | string | DDO): UseMetadata {
|
||||||
const { ocean, status, config, accountId } = useOcean()
|
const { ocean, status, config, accountId } = useOcean()
|
||||||
const [internalDdo, setDDO] = useState<DDO | undefined>()
|
const [internalDdo, setDDO] = useState<DDO | undefined>()
|
||||||
const [internalDid, setDID] = useState<DID | string | undefined>()
|
const [internalDid, setDID] = useState<DID | string | undefined>()
|
||||||
@ -58,16 +59,16 @@ function useMetadata(did?: DID | string, ddo?: DDO): UseMetadata {
|
|||||||
async function init(): Promise<void> {
|
async function init(): Promise<void> {
|
||||||
Logger.debug('meta init', status)
|
Logger.debug('meta init', status)
|
||||||
if (ocean && status === ProviderStatus.CONNECTED) {
|
if (ocean && status === ProviderStatus.CONNECTED) {
|
||||||
if (ddo) {
|
if (!asset) return
|
||||||
setDDO(ddo)
|
|
||||||
setDID(ddo.id)
|
if (isDDO(asset)) {
|
||||||
}
|
setDDO(asset)
|
||||||
Logger.debug('meta init', did)
|
setDID(asset.id)
|
||||||
if (did && !ddo) {
|
} else {
|
||||||
const ddo = await getDDO(did)
|
const ddo = await getDDO(asset)
|
||||||
Logger.debug('DDO', ddo)
|
Logger.debug('DDO', ddo)
|
||||||
setDDO(ddo)
|
setDDO(ddo)
|
||||||
setDID(did)
|
setDID(asset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { DDO, DID } from '@oceanprotocol/lib'
|
||||||
|
|
||||||
export function readFileContent(file: File): Promise<string> {
|
export function readFileContent(file: File): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
@ -12,6 +14,13 @@ export function readFileContent(file: File): Promise<string> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isDDO(toBeDetermined): toBeDetermined is DDO {
|
||||||
|
if ((toBeDetermined as DDO).id) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
export const feedback: { [key in number]: string } = {
|
export const feedback: { [key in number]: string } = {
|
||||||
99: 'Decrypting file URL...',
|
99: 'Decrypting file URL...',
|
||||||
0: '1/3 Looking for data token. Buying if none found...',
|
0: '1/3 Looking for data token. Buying if none found...',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user