1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

cancel AssetsUser component fetching when unmounted

This commit is contained in:
Matthias Kretschmann 2019-04-12 18:19:55 +02:00
parent ffd290ad3f
commit fe695009ff
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -13,32 +13,42 @@ export default class AssetsUser extends PureComponent<
> {
public state = { results: [], isLoading: true }
public _isMounted: boolean = false
public componentDidMount() {
this.searchOcean()
this._isMounted = true
this._isMounted && this.searchOcean()
}
public componentWillUnmount() {
this._isMounted = false
}
private async searchOcean() {
if (this.context.account) {
this.context.ocean.keeper.didRegistry.contract.getPastEvents(
const { account, ocean } = this.context
if (account) {
ocean.keeper.didRegistry.contract.getPastEvents(
'DIDAttributeRegistered',
{
filter: { _owner: this.context.account },
filter: { _owner: account },
fromBlock: 0,
toBlock: 'latest'
},
async (error: any, events: any) => {
if (error) {
Logger.log('error retrieving', error)
this.setState({ isLoading: false })
this._isMounted && this.setState({ isLoading: false })
} else {
const results = []
for (const event of events) {
const ddo = await this.context.ocean.assets.resolve(
const ddo = await ocean.assets.resolve(
`did:op:${event.returnValues._did.substring(2)}`
)
results.push(ddo)
}
this.setState({ results, isLoading: false })
this._isMounted &&
this.setState({ results, isLoading: false })
}
}
)
@ -48,7 +58,9 @@ export default class AssetsUser extends PureComponent<
}
public render() {
return this.context.isNile && this.context.account ? (
const { account, isNile } = this.context
return isNile && account ? (
<div className={styles.assetsUser}>
{this.props.recent && (
<h2 className={styles.subTitle}>