1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-01-11 13:43:52 +01:00
react/example/src/AllDdos.tsx

44 lines
1007 B
TypeScript
Raw Normal View History

2020-07-15 14:54:20 +02:00
import React from 'react'
import { useOcean, usePublish } from '@oceanprotocol/react'
2020-07-31 11:12:32 +02:00
import { DDO } from '@oceanprotocol/lib'
2020-07-15 14:54:20 +02:00
import { useState } from 'react'
import { useEffect } from 'react'
import shortid from 'shortid'
export function AllDdos() {
2020-08-11 12:15:20 +02:00
const { accountId,chainId, account, ocean } = useOcean()
2020-07-15 14:54:20 +02:00
2020-07-16 11:25:01 +02:00
const [ddos, setDdos] = useState<DDO[] | undefined>()
2020-07-15 14:54:20 +02:00
2020-07-16 11:25:01 +02:00
useEffect(() => {
async function init() {
2020-07-31 11:12:32 +02:00
if (ocean === undefined || account === undefined) return
2020-07-16 11:25:01 +02:00
const assets = await ocean.assets.query({
page: 1,
offset: 10,
query: {},
sort: { created: -1 }
})
2020-07-15 14:54:20 +02:00
2020-07-16 11:25:01 +02:00
setDdos(assets.results)
}
init()
2020-08-11 12:15:20 +02:00
}, [ocean, account,chainId])
2020-07-15 14:54:20 +02:00
2020-07-16 11:25:01 +02:00
return (
<>
<div>Assets</div> <br />
<div style={{ flexDirection: 'column' }}>
{ddos?.map((ddo) => {
return (
<div key={shortid.generate()}>
{ddo.id}
<br />
2020-07-15 14:54:20 +02:00
</div>
2020-07-16 11:25:01 +02:00
)
})}
</div>
</>
)
2020-07-15 14:54:20 +02:00
}