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

sign messages, check for owner

This commit is contained in:
Jernej Pregelj 2019-04-26 16:46:55 +02:00 committed by Matthias Kretschmann
parent c97b6b5dbb
commit 3ca8fbba6f
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -4,6 +4,7 @@ import Moment from 'react-moment'
import { DDO, MetaData, File, Logger } from '@oceanprotocol/squid' import { DDO, MetaData, File, Logger } from '@oceanprotocol/squid'
import Input from '../../components/atoms/Form/Input' import Input from '../../components/atoms/Form/Input'
import Markdown from '../../components/atoms/Markdown' import Markdown from '../../components/atoms/Markdown'
import { User } from '../../context'
import styles from './AssetDetails.module.scss' import styles from './AssetDetails.module.scss'
import AssetFilesDetails from './AssetFilesDetails' import AssetFilesDetails from './AssetFilesDetails'
import Button from '../../components/atoms/Button' import Button from '../../components/atoms/Button'
@ -96,6 +97,7 @@ export default class AssetDetails extends PureComponent<
private updateAsset = async () => { private updateAsset = async () => {
this.setState({ isLoading: true, feedback: 'Updating asset...' }) this.setState({ isLoading: true, feedback: 'Updating asset...' })
const { id } = this.props.ddo
const { const {
dateCreated, dateCreated,
description, description,
@ -112,9 +114,9 @@ export default class AssetDetails extends PureComponent<
categories categories
} }
}, },
// TODO: generate signature
signature: '' signature: ''
} }
body.signature = await this.context.web3.eth.personal.sign('You are updating '+id, this.context.account)
const response = await this.fetch('PUT', body) const response = await this.fetch('PUT', body)
@ -128,10 +130,12 @@ export default class AssetDetails extends PureComponent<
private retireAsset = async () => { private retireAsset = async () => {
this.setState({ isLoading: true, feedback: 'Retiring asset...' }) this.setState({ isLoading: true, feedback: 'Retiring asset...' })
const { id } = this.props.ddo
const body = { const body = {
// TODO: generate signature
signature: '' signature: ''
} }
body.signature = await this.context.web3.eth.personal.sign('You are retiring '+id, this.context.account)
const response = await this.fetch('DELETE', body) const response = await this.fetch('DELETE', body)
@ -203,9 +207,8 @@ export default class AssetDetails extends PureComponent<
) )
private MetadataActions = () => { private MetadataActions = () => {
// TODO: check for asset owner and return if no match const isOwner = this.context.account === this.props.ddo.proof.creator
// const isOwner = IS OWNER if (!isOwner) { return null }
// if (!isOwner) { return }
return ( return (
<div className={styles.metadataActions}> <div className={styles.metadataActions}>
@ -311,3 +314,4 @@ export default class AssetDetails extends PureComponent<AssetDetailsProps> {
) )
} }
} }
AssetDetails.contextType = User