2019-02-15 15:23:13 +01:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import { Link } from 'react-router-dom'
|
2019-03-25 17:31:32 +01:00
|
|
|
import { Logger } from '@oceanprotocol/squid'
|
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-03-25 18:03:49 +01:00
|
|
|
import Asset from '../molecules/Asset'
|
2019-02-15 15:23:13 +01:00
|
|
|
import styles from './AssetsUser.module.scss'
|
|
|
|
|
2019-03-25 17:31:32 +01:00
|
|
|
export default class AssetsUser extends PureComponent<
|
|
|
|
{ list?: boolean; recent?: boolean },
|
|
|
|
{ results: any[]; isLoading: boolean }
|
|
|
|
> {
|
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-26 11:46:57 +01:00
|
|
|
if (this.context.account) {
|
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)
|
2019-03-26 11:46:57 +01:00
|
|
|
}
|
|
|
|
this.setState({ results, isLoading: false })
|
2019-03-20 15:27:00 +01:00
|
|
|
}
|
2019-02-15 15:23:13 +01:00
|
|
|
}
|
2019-03-26 11:46:57 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ isLoading: false })
|
2019-02-15 15:23:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
return (
|
2019-03-26 11:46:57 +01:00
|
|
|
this.context.account && (
|
|
|
|
<div className={styles.assetsUser}>
|
|
|
|
{this.props.recent && (
|
|
|
|
<h2 className={styles.subTitle}>
|
|
|
|
Your Latest Data Sets
|
|
|
|
</h2>
|
|
|
|
)}
|
2019-02-15 15:23:13 +01:00
|
|
|
|
2019-02-15 17:26:28 +01:00
|
|
|
{this.state.isLoading ? (
|
|
|
|
<Spinner />
|
|
|
|
) : this.state.results.length ? (
|
2019-03-25 17:31:32 +01:00
|
|
|
<>
|
2019-03-22 13:38:22 +01:00
|
|
|
{this.state.results
|
2019-03-25 17:31:32 +01:00
|
|
|
.slice(0, this.props.recent ? 5 : undefined)
|
2019-03-22 13:38:22 +01:00
|
|
|
.filter(asset => !!asset)
|
2019-03-25 15:25:31 +01:00
|
|
|
.map((asset: any) => (
|
2019-03-25 17:31:32 +01:00
|
|
|
<Asset
|
|
|
|
list={this.props.list}
|
|
|
|
key={asset.id}
|
|
|
|
asset={asset}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
{this.props.recent && (
|
|
|
|
<Link className={styles.link} to={'/history'}>
|
|
|
|
All Data Sets
|
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
</>
|
2019-02-15 15:23:13 +01:00
|
|
|
) : (
|
|
|
|
<div>
|
2019-03-25 17:31:32 +01:00
|
|
|
<p>No Data Sets Yet.</p>
|
2019-02-15 15:23:13 +01:00
|
|
|
<Link to="/publish">+ Publish A Data Set</Link>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2019-03-20 15:27:00 +01:00
|
|
|
|
|
|
|
AssetsUser.contextType = User
|