import React, { PureComponent } from 'react' import { Link } from 'react-router-dom' import { Logger } from '@oceanprotocol/squid' import { User } from '../../context' import Spinner from '../atoms/Spinner' import AssetTeaser from '../molecules/AssetTeaser' import styles from './AssetsUser.module.scss' export default class AssetsUser extends PureComponent< { list?: boolean; recent?: number }, { results: any[]; isLoading: boolean } > { public state = { results: [], isLoading: true } public _isMounted: boolean = false public componentDidMount() { this._isMounted = true this._isMounted && this.searchOcean() } public componentWillUnmount() { this._isMounted = false } private async searchOcean() { const { account, ocean } = this.context if (account) { ocean.keeper.didRegistry.contract.getPastEvents( 'DIDAttributeRegistered', { filter: { _owner: account }, fromBlock: 0, toBlock: 'latest' }, async (error: any, events: any) => { if (error) { Logger.log('error retrieving', error) this._isMounted && this.setState({ isLoading: false }) } else { const results = [] for (const event of events) { const ddo = await ocean.assets.resolve( `did:op:${event.returnValues._did.substring(2)}` ) results.push(ddo) } this._isMounted && this.setState({ results, isLoading: false }) } } ) } else { this.setState({ isLoading: false }) } } public render() { const { account, isOceanNetwork } = this.context return ( isOceanNetwork && account && (
{this.props.recent && (

Your Latest Published Data Sets

)} {this.state.isLoading ? ( ) : this.state.results.length ? ( <> {this.state.results .slice( 0, this.props.recent ? this.props.recent : undefined ) .filter(asset => !!asset) .map((asset: any) => ( ))} {this.props.recent && ( All Data Sets )} ) : (

No Data Sets Yet.

+ Publish A Data Set
)}
) ) } } AssetsUser.contextType = User