2019-02-15 15:23:13 +01:00
|
|
|
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'
|
2019-02-15 16:48:43 +01:00
|
|
|
import Asset from '../molecules/Asset'
|
2019-02-15 15:23:13 +01:00
|
|
|
import styles from './AssetsUser.module.scss'
|
2019-03-20 15:27:00 +01:00
|
|
|
import { Logger } from '@oceanprotocol/squid'
|
2019-02-15 15:23:13 +01:00
|
|
|
|
|
|
|
export default class AssetsUser extends PureComponent {
|
2019-02-15 17:26:28 +01:00
|
|
|
public state = { results: [], isLoading: true }
|
2019-02-15 15:23:13 +01:00
|
|
|
|
|
|
|
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-02-15 15:23:13 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-20 15:27:00 +01:00
|
|
|
)
|
2019-02-15 15:23:13 +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 ? (
|
2019-02-15 16:48:43 +01:00
|
|
|
<div className={styles.assets}>
|
2019-03-22 13:38:22 +01:00
|
|
|
{this.state.results
|
|
|
|
.filter(asset => !!asset)
|
2019-03-25 15:25:31 +01:00
|
|
|
.map((asset: any) => (
|
2019-03-25 16:41:23 +01:00
|
|
|
<Asset key={asset.id} asset={asset} list />
|
|
|
|
))}
|
2019-02-15 16:48:43 +01:00
|
|
|
</div>
|
2019-02-15 15:23:13 +01:00
|
|
|
) : (
|
|
|
|
<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
|