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

fix consume flow

This commit is contained in:
Matthias Kretschmann 2019-03-26 13:57:59 +01:00
parent 1585a4a2f9
commit a24a2b983e
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 25 additions and 25 deletions

View File

@ -5,13 +5,14 @@ import styles from './AssetDetails.module.scss'
import AssetFilesDetails from './AssetFilesDetails' import AssetFilesDetails from './AssetFilesDetails'
interface AssetDetailsProps { interface AssetDetailsProps {
ocean: any
metadata: any metadata: any
ddo: any ddo: any
} }
export default class AssetDetails extends PureComponent<AssetDetailsProps> { export default class AssetDetails extends PureComponent<AssetDetailsProps> {
public render() { public render() {
const { metadata, ddo } = this.props const { ocean, metadata, ddo } = this.props
const { base } = metadata const { base } = metadata
return ( return (
@ -71,6 +72,7 @@ export default class AssetDetails extends PureComponent<AssetDetailsProps> {
<AssetFilesDetails <AssetFilesDetails
files={base.files ? base.files : []} files={base.files ? base.files : []}
ddo={ddo} ddo={ddo}
ocean={ocean}
/> />
<pre> <pre>

View File

@ -5,37 +5,31 @@ import Button from '../../components/atoms/Button'
import styles from './AssetDetails.module.scss' import styles from './AssetDetails.module.scss'
interface AssetFilesDetailsProps { interface AssetFilesDetailsProps {
ocean: any
files: any[] files: any[]
ddo: string ddo: any
} }
export default class AssetFilesDetails extends PureComponent< export default class AssetFilesDetails extends PureComponent<
AssetFilesDetailsProps AssetFilesDetailsProps
> { > {
public state = { decryptedFiles: [] }
private purchaseAsset = async (ddo: any) => { private purchaseAsset = async (ddo: any) => {
try { try {
const account = await this.context.ocean.getAccounts() const account = await this.props.ocean.getAccounts()
const service = ddo.findServiceByType('Access') const service = ddo.findServiceByType('Access')
const serviceAgreementSignatureResult = await this.context.ocean.signServiceAgreement( const serviceAgreementSignatureResult = await this.props.ocean.signServiceAgreement(
ddo.id, ddo.id,
service.serviceDefinitionId, service.serviceDefinitionId,
account[0] account[0]
) )
await this.context.ocean.initializeServiceAgreement( await this.props.ocean.initializeServiceAgreement(
ddo.id, ddo.id,
service.serviceDefinitionId, service.serviceDefinitionId,
serviceAgreementSignatureResult.agreementId, serviceAgreementSignatureResult.agreementId,
serviceAgreementSignatureResult.signature, serviceAgreementSignatureResult.signature,
(files: any) => { (files: any) => this.setState({ decryptedFiles: files }),
Logger.log('downloading files', files)
files.forEach((file: any) => {
const parsedUrl: any = queryString.parseUrl(file)
// setTimeout(() => {
// // eslint-disable-next-line
// window.open(parsedUrl.query.url)
// }, 100)
})
},
account[0] account[0]
) )
} catch (e) { } catch (e) {
@ -45,13 +39,14 @@ export default class AssetFilesDetails extends PureComponent<
public render() { public render() {
const { files, ddo } = this.props const { files, ddo } = this.props
const filesArray = this.state.decryptedFiles
? this.state.decryptedFiles
: files
return ( return (
<> <>
{files.forEach(file => { {filesArray.length > 0 &&
const parsedUrl: any = queryString.parseUrl(file) filesArray.forEach(file => (
return (
<> <>
<h2>{file.name}</h2> <h2>{file.name}</h2>
<ul> <ul>
@ -89,12 +84,11 @@ export default class AssetFilesDetails extends PureComponent<
</li> </li>
</ul> </ul>
<Button href={parsedUrl.query.url}> {file.url && (
Download asset <Button href={file.url}>Download asset</Button>
</Button> )}
</> </>
) ))}
})}
<Button onClick={() => this.purchaseAsset(ddo)}> <Button onClick={() => this.purchaseAsset(ddo)}>
Get downloads Get downloads

View File

@ -34,7 +34,11 @@ export default class Details extends Component<DetailsProps, DetailsState> {
title={metadata.base ? metadata.base.name : 'Loading Details'} title={metadata.base ? metadata.base.name : 'Loading Details'}
> >
{metadata && metadata.base.name ? ( {metadata && metadata.base.name ? (
<AssetDetails metadata={metadata} ddo={ddo} /> <AssetDetails
ocean={this.context.ocean}
metadata={metadata}
ddo={ddo}
/>
) : ( ) : (
<div className={stylesApp.loader}> <div className={stylesApp.loader}>
<Spinner message={'Loading asset...'} /> <Spinner message={'Loading asset...'} />