From f24472f3ed320cd499b2395af9e5b1328b4509e5 Mon Sep 17 00:00:00 2001 From: Jernej Pregelj Date: Tue, 12 Feb 2019 10:48:35 +0100 Subject: [PATCH] finished state w redirects --- src/components/Web3message.tsx | 67 ++++++++++++++++++++++------------ src/routes/Publish.tsx | 57 ++++++++++++++++++++++++++--- 2 files changed, 95 insertions(+), 29 deletions(-) diff --git a/src/components/Web3message.tsx b/src/components/Web3message.tsx index 4338b9a..1d19888 100644 --- a/src/components/Web3message.tsx +++ b/src/components/Web3message.tsx @@ -16,36 +16,55 @@ export default class Web3message extends PureComponent { {states => !states.isWeb3 ? ( -
- No Web3 Browser. For - publishing an asset you need to use a Web3-capable plugin or - browser, like{' '} - - MetaMask - - . -
+ this.noWeb3() ) : !states.isLogged ? ( -
- Account - locked. For publishing an asset you need to unlock your Web3 - account. - -
+ this.unlockAccount(states) ) : states.isLogged ? ( -
- Connected with account - - 0xfehz2u89n... - -
+ this.haveAccount() ) : null }
) } + + public noWeb3() { + return ( +
+ No Web3 Browser. For + publishing an asset you need to use a Web3-capable plugin or + browser, like{' '} + + MetaMask + + . +
+ ) + } + + public unlockAccount(states: any) { + return ( +
+ Account + locked. For publishing an asset you need to unlock your Web3 + account. + +
+ ) + } + + public haveAccount() { + return ( +
+ Connected with account + + 0xfehz2u89n... + +
+ ) + } + } diff --git a/src/routes/Publish.tsx b/src/routes/Publish.tsx index 707cf1e..f0708a1 100644 --- a/src/routes/Publish.tsx +++ b/src/routes/Publish.tsx @@ -23,8 +23,10 @@ interface PublishState { license?: string copyrightHolder?: string categories?: string[] - tags?: string[], - isPublishing?: boolean, + tags?: string[] + isPublishing?: boolean + isPublished?: boolean + publishedDid?: string publishingError?: string } @@ -41,6 +43,8 @@ class Publish extends Component<{}, PublishState> { copyrightHolder: '', categories: [''], isPublishing: false, + isPublished: false, + publishedDid: '', publishingError: '' } @@ -89,6 +93,23 @@ class Publish extends Component<{}, PublishState> { this.setState({ publishingError: '' }) } + private toStart = () => { + this.setState({ + name: '', + dateCreated: new Date(), + description: '', + files: [''], + price: 0, + author: '', + type: 'dataset' as AssetType, + license: '', + copyrightHolder: '', + categories: [''], + isPublishing: false, + isPublished: false + }) + } + private registerAsset = async (event: FormEvent) => { event.preventDefault() this.setState({ @@ -123,7 +144,12 @@ class Publish extends Component<{}, PublishState> { ) } try { - await this.context.ocean.registerAsset(newAsset, account[0]) + const asset = await this.context.ocean.registerAsset(newAsset, account[0]) + Logger.log('asset:', asset) + this.setState({ + publishedDid: asset.id, + isPublished: true + }) } catch (e) { // make readable errors Logger.log('error:', e) @@ -144,9 +170,11 @@ class Publish extends Component<{}, PublishState> { {this.state.isPublishing ? ( -
Please sign with ctypto wallet
+ this.publishingState() ) : this.state.publishingError ? ( -
Something went wrong, this.tryAgain()}>try again
+ this.errorState() + ) : this.state.isPublished ? ( + this.publishedState() ) : (
{ ) } + + public publishingState = () => { + return ( +
Please sign with your crypto wallet
+ ) + } + + public errorState = () => { + return ( +
Something went wrong, this.tryAgain()}>try again
+ ) + } + + public publishedState = () => { + return ( +
Your asset is published! See it here, submit another asset by clicking this.toStart()}>here
+ ) + } + } Publish.contextType = User