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 static contextType = User public state = { results: [], isLoading: true } public _isMounted = 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 } = this.context const { recent, list } = this.props const { isLoading, results } = this.state if (!account) return null return (
{this.props.recent && (

Your Latest Published Data Sets

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

No Data Sets Yet.

+ Publish A Data Set
)}
) } }