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:
parent
ffd290ad3f
commit
fe695009ff
@ -13,32 +13,42 @@ export default class AssetsUser extends PureComponent<
|
|||||||
> {
|
> {
|
||||||
public state = { results: [], isLoading: true }
|
public state = { results: [], isLoading: true }
|
||||||
|
|
||||||
|
public _isMounted: boolean = false
|
||||||
|
|
||||||
public componentDidMount() {
|
public componentDidMount() {
|
||||||
this.searchOcean()
|
this._isMounted = true
|
||||||
|
this._isMounted && this.searchOcean()
|
||||||
|
}
|
||||||
|
|
||||||
|
public componentWillUnmount() {
|
||||||
|
this._isMounted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private async searchOcean() {
|
private async searchOcean() {
|
||||||
if (this.context.account) {
|
const { account, ocean } = this.context
|
||||||
this.context.ocean.keeper.didRegistry.contract.getPastEvents(
|
|
||||||
|
if (account) {
|
||||||
|
ocean.keeper.didRegistry.contract.getPastEvents(
|
||||||
'DIDAttributeRegistered',
|
'DIDAttributeRegistered',
|
||||||
{
|
{
|
||||||
filter: { _owner: this.context.account },
|
filter: { _owner: account },
|
||||||
fromBlock: 0,
|
fromBlock: 0,
|
||||||
toBlock: 'latest'
|
toBlock: 'latest'
|
||||||
},
|
},
|
||||||
async (error: any, events: any) => {
|
async (error: any, events: any) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
Logger.log('error retrieving', error)
|
Logger.log('error retrieving', error)
|
||||||
this.setState({ isLoading: false })
|
this._isMounted && this.setState({ isLoading: false })
|
||||||
} else {
|
} else {
|
||||||
const results = []
|
const results = []
|
||||||
for (const event of events) {
|
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)}`
|
`did:op:${event.returnValues._did.substring(2)}`
|
||||||
)
|
)
|
||||||
results.push(ddo)
|
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() {
|
public render() {
|
||||||
return this.context.isNile && this.context.account ? (
|
const { account, isNile } = this.context
|
||||||
|
|
||||||
|
return isNile && account ? (
|
||||||
<div className={styles.assetsUser}>
|
<div className={styles.assetsUser}>
|
||||||
{this.props.recent && (
|
{this.props.recent && (
|
||||||
<h2 className={styles.subTitle}>
|
<h2 className={styles.subTitle}>
|
||||||
|
Loading…
Reference in New Issue
Block a user