1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00
commons/client/src/components/molecules/AssetsUser.tsx

69 lines
2.3 KiB
TypeScript
Raw Normal View History

import React, { PureComponent } from 'react'
import { Link } from 'react-router-dom'
2019-03-20 15:27:00 +01:00
import { User } from '../../context/User'
2019-02-15 17:26:28 +01:00
import Spinner from '../atoms/Spinner'
import Asset from '../molecules/Asset'
import styles from './AssetsUser.module.scss'
2019-03-20 15:27:00 +01:00
import { Logger } from '@oceanprotocol/squid'
export default class AssetsUser extends PureComponent {
2019-02-15 17:26:28 +01:00
public state = { results: [], isLoading: true }
public componentDidMount() {
this.searchOcean()
}
private async searchOcean() {
2019-03-20 15:27:00 +01:00
this.context.ocean.keeper.didRegistry.contract.getPastEvents(
'DIDAttributeRegistered',
{
filter: { _owner: this.context.account },
fromBlock: 0,
toBlock: 'latest'
},
async (error: any, events: any) => {
if (error) {
Logger.log('error retrieving', error)
this.setState({ isLoading: false })
} else {
const results = []
for (const event of events) {
2019-03-25 15:22:45 +01:00
const ddo = await this.context.ocean.assets.resolve(
2019-03-20 15:27:00 +01:00
`did:op:${event.returnValues._did.substring(2)}`
)
results.push(ddo)
}
this.setState({ results, isLoading: false })
}
}
2019-03-20 15:27:00 +01:00
)
}
public render() {
return (
<div className={styles.assetsUser}>
<h2 className={styles.subTitle}>Your Data Sets</h2>
2019-02-15 17:26:28 +01:00
{this.state.isLoading ? (
<Spinner />
) : this.state.results.length ? (
<div className={styles.assets}>
{this.state.results
.filter(asset => !!asset)
.map((asset: any) => (
2019-03-25 16:41:23 +01:00
<Asset key={asset.id} asset={asset} list />
))}
</div>
) : (
<div>
<p>None yet.</p>
<Link to="/publish">+ Publish A Data Set</Link>
</div>
)}
</div>
)
}
}
2019-03-20 15:27:00 +01:00
AssetsUser.contextType = User