mirror of
https://github.com/oceanprotocol/react.git
synced 2024-11-23 02:00:27 +01:00
Merge pull request #90 from oceanprotocol/feature/meta-asset
refactor ddo,did with asset
This commit is contained in:
commit
205a07d9d9
@ -33,7 +33,7 @@ export function AllDdos() {
|
||||
{ddos?.map((ddo) => {
|
||||
return (
|
||||
<div key={shortid.generate()}>
|
||||
<MetadataExample did={ddo.id} />
|
||||
<MetadataExample ddo={ddo} />
|
||||
<br />
|
||||
</div>
|
||||
)
|
||||
|
@ -1,13 +1,14 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { useMetadata } from '@oceanprotocol/react'
|
||||
import { DDO } from '@oceanprotocol/lib'
|
||||
|
||||
export function MetadataExample({ did }: { did: string }) {
|
||||
const { title, pool } = useMetadata(did)
|
||||
export function MetadataExample({ ddo }: { ddo: DDO }) {
|
||||
const { title, poolAddress, price } = useMetadata(ddo)
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
{title} - {pool && pool.price + ' - ' + pool.address}
|
||||
{title} - price = {price} // pool = {poolAddress}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
|
@ -4,6 +4,7 @@ import { useOcean } from '../../providers'
|
||||
import ProviderStatus from '../../providers/OceanProvider/ProviderStatus'
|
||||
import { getBestDataTokenPrice, getCheapestPool } from '../../utils/dtUtils'
|
||||
import Pool from './Pool'
|
||||
import { isDDO } from '../../utils'
|
||||
|
||||
interface UseMetadata {
|
||||
ddo: DDO
|
||||
@ -17,7 +18,7 @@ interface UseMetadata {
|
||||
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 [internalDdo, setDDO] = useState<DDO | 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> {
|
||||
Logger.debug('meta init', status)
|
||||
if (ocean && status === ProviderStatus.CONNECTED) {
|
||||
if (ddo) {
|
||||
setDDO(ddo)
|
||||
setDID(ddo.id)
|
||||
}
|
||||
Logger.debug('meta init', did)
|
||||
if (did && !ddo) {
|
||||
const ddo = await getDDO(did)
|
||||
if (!asset) return
|
||||
|
||||
if (isDDO(asset)) {
|
||||
setDDO(asset)
|
||||
setDID(asset.id)
|
||||
} else {
|
||||
const ddo = await getDDO(asset)
|
||||
Logger.debug('DDO', ddo)
|
||||
setDDO(ddo)
|
||||
setDID(did)
|
||||
setDID(asset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { DDO, DID } from '@oceanprotocol/lib'
|
||||
|
||||
export function readFileContent(file: File): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
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 } = {
|
||||
99: 'Decrypting file URL...',
|
||||
0: '1/3 Looking for data token. Buying if none found...',
|
||||
|
Loading…
Reference in New Issue
Block a user