From b66dbcdef9ae96ee807b46a4e88b3386d9df6dae Mon Sep 17 00:00:00 2001 From: andytudhope Date: Sat, 10 Aug 2019 21:57:22 +0200 Subject: [PATCH] Fixes Edit metadata issues, adds email verification --- .../discover-service/discover-service.js | 5 +-- src/common/utils/email-utils.js | 4 +++ src/modules/Submit/Submit.jsx | 35 ++++++++++--------- src/modules/Submit/Submit.reducer.js | 15 ++++++-- 4 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 src/common/utils/email-utils.js diff --git a/src/common/blockchain/services/discover-service/discover-service.js b/src/common/blockchain/services/discover-service/discover-service.js index c353f3d..0e32cda 100644 --- a/src/common/blockchain/services/discover-service/discover-service.js +++ b/src/common/blockchain/services/discover-service/discover-service.js @@ -265,7 +265,7 @@ class DiscoverService extends BlockchainService { } } - async setMetadata(id, metadata) { + async setMetadata(id, metadata, email) { const ConnectedDiscoverContract = await super.__unlockServiceAccount( DiscoverContract, ) @@ -274,7 +274,7 @@ class DiscoverService extends BlockchainService { const dappMetadata = JSON.parse(JSON.stringify(metadata)) dappMetadata.uploader = this.sharedContext.account - const uploadedMetadata = await MetadataClient.upload(dappMetadata) + const uploadedMetadata = await MetadataClient.upload(dappMetadata, email) try { const tx = await broadcastContractFn( @@ -283,6 +283,7 @@ class DiscoverService extends BlockchainService { this.sharedContext.account, ) + // TODO: This results in endless "Waiting for confirmation... errors, though the tx is successful" await MetadataClient.update(id, tx) return tx diff --git a/src/common/utils/email-utils.js b/src/common/utils/email-utils.js new file mode 100644 index 0000000..91fe393 --- /dev/null +++ b/src/common/utils/email-utils.js @@ -0,0 +1,4 @@ +// eslint-disable-next-line import/prefer-default-export +export const emailValidation = email => { + return new RegExp(/[\w-]+@([\w-]+\.)+[\w-]+/gm).test(email) +} diff --git a/src/modules/Submit/Submit.jsx b/src/modules/Submit/Submit.jsx index 348187b..1df9734 100644 --- a/src/modules/Submit/Submit.jsx +++ b/src/modules/Submit/Submit.jsx @@ -15,6 +15,7 @@ import 'rc-slider/assets/index.css' import 'rc-tooltip/assets/bootstrap.css' import { DappState } from '../../common/data/dapp' import validator from 'validator' +import { emailValidation } from '../../common/utils/email-utils' const getCategoryName = category => Categories.find(x => x.key === category).value @@ -224,13 +225,12 @@ class Submit extends React.Component { visible_submit, visible_rating, onClickClose, - email, - id, name, desc, url, img, category, + email, imgControl, imgControlZoom, onImgCancel, @@ -239,7 +239,12 @@ class Submit extends React.Component { } = this.props const canSubmit = - name !== '' && desc !== '' && url !== '' && img !== '' && category !== '' + name !== '' && + desc !== '' && + url !== '' && + img !== '' && + category !== '' && + emailValidation(email) const visible = visible_submit || visible_rating @@ -277,19 +282,6 @@ class Submit extends React.Component { {visible_submit && (
- {id === '' && ( -
-
- Your email -
- -
- )}
Name of your Ðapp @@ -358,6 +350,17 @@ class Submit extends React.Component { }`} />
+
+
+ Your email +
+ +
By continuing you agree to our diff --git a/src/modules/Submit/Submit.reducer.js b/src/modules/Submit/Submit.reducer.js index 1f8f753..5b74327 100644 --- a/src/modules/Submit/Submit.reducer.js +++ b/src/modules/Submit/Submit.reducer.js @@ -175,7 +175,7 @@ export const submitAction = (dapp, sntValue) => { } } -export const updateAction = (dappId, metadata) => { +export const updateAction = (dappId, metadata, email) => { return async dispatch => { dispatch(closeSubmitAction()) dispatch( @@ -188,7 +188,18 @@ export const updateAction = (dappId, metadata) => { ) try { const blockchain = await BlockchainSDK.getInstance() - const tx = await blockchain.DiscoverService.setMetadata(dappId, metadata) + const tx = await blockchain.DiscoverService.setMetadata( + dappId, + { + name: metadata.name, + url: metadata.url, + description: metadata.description, + category: metadata.category, + image: metadata.image, + dateAdded: metadata.dateAdded, + }, + metadata.email, + ) dispatch(onReceiveTransactionInfoAction(dappId, tx)) dispatch(checkTransactionStatusAction(tx)) } catch (e) {