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

simplify consume buttons logic

This commit is contained in:
Matthias Kretschmann 2019-04-08 19:46:53 +02:00
parent 72741f5ae6
commit 18267a1a18
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -39,7 +39,7 @@ export default class AssetFile extends PureComponent<
})
const { ocean } = this.context
try {
const accounts = await ocean.accounts.list()
const service = ddo.findServiceByType('Access')
@ -75,6 +75,8 @@ export default class AssetFile extends PureComponent<
public render() {
const { ddo, file } = this.props
const { isLoading, message, error } = this.state
const { isLogged, startLogin } = this.context
return (
<div className={styles.fileWrap}>
@ -89,39 +91,24 @@ export default class AssetFile extends PureComponent<
{/* <li>{file.compression}</li> */}
</ul>
{this.state.isLoading ? (
<Spinner message={this.state.message} />
{isLoading ? (
<Spinner message={message} />
) : (
<User.Consumer>
{states =>
states.isLogged ? (
<Button
primary
className={styles.buttonMain}
onClick={() =>
this.purchaseAsset(ddo, file.index)
}
>
Get file
</Button>
) : (
states.isWeb3 && (
<Button
primary
className={styles.buttonMain}
onClick={states.startLogin}
>
Get file
</Button>
)
)
<Button
primary
className={styles.buttonMain}
onClick={
isLogged
? () => this.purchaseAsset(ddo, file.index)
: startLogin
}
</User.Consumer>
disabled={!isLogged}
>
Get file
</Button>
)}
{this.state.error !== '' && (
<div className={styles.error}>{this.state.error}</div>
)}
{error !== '' && <div className={styles.error}>{error}</div>}
</div>
)
}