diff --git a/src/App.tsx b/src/App.tsx
index 8446902..a1e3303 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -21,6 +21,7 @@ declare global {
interface AppState {
isLogged: boolean
isLoading: boolean
+ isWeb3: boolean
web3: Web3
ocean: {}
startLogin: () => void
@@ -37,6 +38,7 @@ class App extends Component<{}, AppState> {
public state = {
isLogged: false,
isLoading: true,
+ isWeb3: false,
web3: new Web3(
new Web3.providers.HttpProvider(
`${nodeScheme}://${nodeHost}:${nodePort}`
@@ -51,7 +53,6 @@ class App extends Component<{}, AppState> {
}
private startLoginProcess = async () => {
- this.setState({ isLoading: true })
if (window.web3) {
const web3 = new Web3(window.web3.currentProvider)
try {
@@ -59,6 +60,7 @@ class App extends Component<{}, AppState> {
if (accounts.length > 0) {
this.setState({
isLogged: true,
+ isWeb3: true,
web3
})
} else {
@@ -66,6 +68,7 @@ class App extends Component<{}, AppState> {
await window.ethereum.enable()
this.setState({
isLogged: true,
+ isWeb3: true,
web3
})
}
@@ -76,11 +79,11 @@ class App extends Component<{}, AppState> {
} else {
// no metamask/mist, show installation guide!
}
- this.setState({ isLoading: false })
}
private bootstrap = async () => {
if (window.web3) {
+ this.setState({ isWeb3: true })
const web3 = new Web3(window.web3.currentProvider)
try {
const accounts = await web3.eth.getAccounts()
@@ -94,11 +97,18 @@ class App extends Component<{}, AppState> {
// continue with default
}
}
- const { ocean } = await provideOcean()
- this.setState({
- isLoading: false,
- ocean
- })
+ try {
+ const { ocean } = await provideOcean()
+ this.setState({
+ isLoading: false,
+ ocean
+ })
+ } catch (e) {
+ // show loading error / unable to initialize ocean
+ this.setState({
+ isLoading: false
+ })
+ }
}
public render() {
@@ -109,9 +119,11 @@ class App extends Component<{}, AppState> {
<>
-
-
-
+ {!this.state.isLoading ? (
+
+
+
+ ) : null}
>
diff --git a/src/components/Web3message.tsx b/src/components/Web3message.tsx
index ddb1d7a..4338b9a 100644
--- a/src/components/Web3message.tsx
+++ b/src/components/Web3message.tsx
@@ -1,6 +1,7 @@
import React, { PureComponent } from 'react'
import Button from '../components/atoms/Button'
import styles from './Web3message.module.scss'
+import { User } from '../context/User'
export default class Web3message extends PureComponent {
public render() {
@@ -12,36 +13,38 @@ export default class Web3message extends PureComponent {
return (
<>
- {/* IF no Web3 */}
-
-
No Web3 Browser. For
- publishing an asset you need to use a Web3-capable plugin or
- browser, like{' '}
-
- MetaMask
-
- .
-
-
- {/* IF connected and account locked */}
-
- Account
- locked. For publishing an asset you need to unlock your Web3
- account.
-
-
-
- {/* IF connected and unlocked */}
-
- Connected with
- account
-
- 0xfehz2u89n...
-
-
+
+ {states =>
+ !states.isWeb3 ? (
+
+
No Web3 Browser. For
+ publishing an asset you need to use a Web3-capable plugin or
+ browser, like{' '}
+
+ MetaMask
+
+ .
+
+ ) : !states.isLogged ? (
+
+ Account
+ locked. For publishing an asset you need to unlock your Web3
+ account.
+
+
+ ) : states.isLogged ? (
+
+ Connected with account
+
+ 0xfehz2u89n...
+
+
+ ) : null
+ }
+
>
)
}
diff --git a/src/context/User.ts b/src/context/User.ts
index 9ef0ef2..2ab2816 100644
--- a/src/context/User.ts
+++ b/src/context/User.ts
@@ -3,6 +3,7 @@ import React from 'react'
export const User = React.createContext({
isLogged: false,
isLoading: false,
+ isWeb3: false,
web3: {},
ocean: {},
startLogin: () => {
diff --git a/src/routes/Details.tsx b/src/routes/Details.tsx
index f8d9baf..4a8fcf1 100644
--- a/src/routes/Details.tsx
+++ b/src/routes/Details.tsx
@@ -3,6 +3,7 @@ import React, { Component } from 'react'
import Route from '../components/templates/Route'
import Button from '../components/atoms/Button'
import { User } from '../context/User'
+import quertString from 'query-string'
interface DetailsState {
ddo: any
@@ -26,29 +27,33 @@ export default class Details extends Component {
}
private purchaseAsset = async (ddo: any) => {
- const account = await this.context.ocean.getAccounts()
- const service = ddo.findServiceByType('Access')
- const serviceAgreementSignatureResult: any = await this.context.ocean.signServiceAgreement(
- ddo.id,
- service.serviceDefinitionId,
- account[0]
- )
- Logger.log(
- 'serviceAgreementSignatureResult',
- serviceAgreementSignatureResult
- )
-
- await this.context.ocean.initializeServiceAgreement(
- ddo.id,
- service.serviceDefinitionId,
- serviceAgreementSignatureResult.serviceAgreementId,
- serviceAgreementSignatureResult.serviceAgreementSignature,
- (files: any) =>
- Logger.log(
- `Got files, first files length in bytes: ${files[0].length}`
- ),
- account[0]
- )
+ try {
+ const account = await this.context.ocean.getAccounts()
+ const service = ddo.findServiceByType('Access')
+ const serviceAgreementSignatureResult: any = await this.context.ocean.signServiceAgreement(
+ ddo.id,
+ service.serviceDefinitionId,
+ account[0]
+ )
+ await this.context.ocean.initializeServiceAgreement(
+ ddo.id,
+ service.serviceDefinitionId,
+ serviceAgreementSignatureResult.serviceAgreementId,
+ serviceAgreementSignatureResult.serviceAgreementSignature,
+ (files: any) => {
+ files.forEach((file: any) => {
+ const parsedUrl: any = quertString.parseUrl(file)
+ setTimeout(() => {
+ // eslint-disable-next-line
+ window.open(parsedUrl.query.url)
+ }, 100)
+ })
+ },
+ account[0]
+ )
+ } catch (e) {
+ Logger.log('error', e)
+ }
}
private showDetails = (ddo: any) => {
@@ -56,7 +61,7 @@ export default class Details extends Component {
<>
{JSON.stringify(this.state.metadata)}
-