diff --git a/client/src/App.tsx b/client/src/App.tsx
index f567646..f1e2e1f 100644
--- a/client/src/App.tsx
+++ b/client/src/App.tsx
@@ -39,7 +39,7 @@ interface AppState {
}
network: string
web3: Web3
- ocean: {}
+ ocean: any
startLogin: () => void
message: string
}
@@ -95,7 +95,7 @@ class App extends Component<{}, AppState> {
)
),
account: '',
- ocean: {},
+ ocean: {} as any,
startLogin: this.startLogin,
requestFromFaucet: this.requestFromFaucet,
message: 'Connecting to Ocean...'
@@ -106,73 +106,77 @@ class App extends Component<{}, AppState> {
}
private startLoginProcess = async () => {
- if (window.web3) {
- const web3 = new Web3(window.web3.currentProvider)
- try {
- const accounts = await web3.eth.getAccounts()
+ try {
+ if (this.state.isWeb3 && window.ethereum) {
+ await window.ethereum.enable()
+ const accounts = await this.state.ocean.accounts.list()
if (accounts.length > 0) {
+ const balance = await accounts[0].getBalance()
this.setState({
isLogged: true,
- isWeb3: true,
- account: accounts[0],
- web3
+ balance,
+ account: accounts[0].getId()
})
} else {
- if (accounts.length === 0 && window.ethereum) {
- await window.ethereum.enable()
- const newAccounts = await web3.eth.getAccounts()
- if (newAccounts.length > 0) {
- this.setState({
- isLogged: true,
- isWeb3: true,
- account: newAccounts[0],
- web3
- })
- } else {
- // failed to unlock
- }
- } else {
- // no unlock procedure
- }
+ // not unlocked
}
- } catch (e) {
- // something went wrong, show error?
+ } else {
+ // no metamask/mist, show installation guide!
}
- } else {
- // no metamask/mist, show installation guide!
+ } catch (e) {
+ Logger.log('error logging', e)
+ // error in logging process
+ // show error
+ // rerun bootstrap process?
}
}
private bootstrap = async () => {
- if (window.web3) {
- this.setState({ isWeb3: true })
- const web3 = new Web3(window.web3.currentProvider)
- try {
- const accounts = await web3.eth.getAccounts()
+ try {
+ if (window.web3) {
+ const web3 = new Web3(window.web3.currentProvider)
+ const { ocean } = await provideOcean(web3)
+ const accounts = await ocean.accounts.list()
+ const network = await ocean.keeper.getNetworkName()
+ const isNile = network === 'Nile'
if (accounts.length > 0) {
+ const balance = await accounts[0].getBalance()
this.setState({
+ isWeb3: true,
isLogged: true,
- account: accounts[0],
- web3
+ isNile,
+ ocean,
+ web3,
+ balance,
+ network,
+ account: accounts[0].getId(),
+ isLoading: false,
+ })
+ } else {
+ this.setState({
+ isWeb3: true,
+ isNile,
+ ocean,
+ web3,
+ network,
+ isLoading: false
})
}
- } catch (e) {
- Logger.log('web3 error', e)
+ } else {
+ const { ocean } = await provideOcean(this.state.web3)
+ const network = await ocean.keeper.getNetworkName()
+ const isNile = network === 'Nile'
+ this.setState({
+ isNile,
+ ocean,
+ network,
+ isLoading: false
+ })
}
- }
- try {
- const { ocean } = await provideOcean()
- this.setState({
- isLoading: false,
- ocean
- })
- const accounts = await ocean.accounts.list()
- const balance = await accounts[0].getBalance()
- const network = await ocean.keeper.getNetworkName()
- const isNile = network === 'Nile'
- this.setState({ balance, network, isNile })
} catch (e) {
- Logger.log('ocean/balance error', e)
+ // error in bootstrap process
+ // show error connecting to ocean
+ Logger.log('web3 error', e)
this.setState({
isLoading: false
})
diff --git a/client/src/components/organisms/AssetsUser.tsx b/client/src/components/organisms/AssetsUser.tsx
index cc81ee7..bf868a8 100644
--- a/client/src/components/organisms/AssetsUser.tsx
+++ b/client/src/components/organisms/AssetsUser.tsx
@@ -4,6 +4,7 @@ import { Logger } from '@oceanprotocol/squid'
import { User } from '../../context/User'
import Spinner from '../atoms/Spinner'
import Asset from '../molecules/Asset'
+import Web3message from './Web3message'
import styles from './AssetsUser.module.scss'
export default class AssetsUser extends PureComponent<
@@ -49,7 +50,7 @@ export default class AssetsUser extends PureComponent<
public render() {
return (
this.context.isNile &&
- this.context.account && (
+ this.context.account ? (
{this.props.recent && (
@@ -89,6 +90,8 @@ export default class AssetsUser extends PureComponent<
)}
+ ) : (
+
)
)
}
diff --git a/client/src/components/organisms/Web3message.tsx b/client/src/components/organisms/Web3message.tsx
index 34b8bec..74ed53c 100644
--- a/client/src/components/organisms/Web3message.tsx
+++ b/client/src/components/organisms/Web3message.tsx
@@ -26,9 +26,9 @@ export default class Web3message extends PureComponent {
public noWeb3() {
return (
-
No Web3 Browser. For
- publishing an asset you need to{' '}
-
+ Not a Web3 Browser. For
+ publishing or consuming an asset you need to{' '}
+
setup MetaMask
{' '}
or use any other Web3-capable plugin or browser.
diff --git a/client/src/data/menu.json b/client/src/data/menu.json
index 7f48dd7..bc663f9 100644
--- a/client/src/data/menu.json
+++ b/client/src/data/menu.json
@@ -1,18 +1,15 @@
[
{
"title": "Publish",
- "link": "/publish",
- "web3": true
+ "link": "/publish"
},
{
"title": "History",
- "link": "/history",
- "web3": true
+ "link": "/history"
},
{
"title": "Faucet",
- "link": "/faucet",
- "web3": true
+ "link": "/faucet"
},
{
"title": "About",
diff --git a/client/src/ocean.ts b/client/src/ocean.ts
index f2fc95d..d27e483 100644
--- a/client/src/ocean.ts
+++ b/client/src/ocean.ts
@@ -1,4 +1,5 @@
import { Ocean } from '@oceanprotocol/squid'
+import Web3 from 'web3'
import {
aquariusHost,
@@ -20,7 +21,7 @@ import {
verbose
} from './config/config'
-export async function provideOcean() {
+export async function provideOcean(web3provider: Web3) {
const nodeUri = `${nodeScheme}://${nodeHost}:${nodePort}`
const aquariusUri = `${aquariusScheme}://${aquariusHost}:${aquariusPort}`
const brizoUri = `${brizoScheme}://${brizoHost}:${brizoPort}`
@@ -28,6 +29,7 @@ export async function provideOcean() {
const secretStoreUri = `${secretStoreScheme}://${secretStoreHost}:${secretStorePort}`
const config = {
+ web3provider,
nodeUri,
aquariusUri,
brizoUri,
@@ -37,7 +39,7 @@ export async function provideOcean() {
verbose
}
- const ocean = await Ocean.getInstance(config)
+ const ocean: Ocean = await Ocean.getInstance(config)
return { ocean }
}
diff --git a/client/src/routes/Details/AssetFile.tsx b/client/src/routes/Details/AssetFile.tsx
index 8652cfa..1eeb011 100644
--- a/client/src/routes/Details/AssetFile.tsx
+++ b/client/src/routes/Details/AssetFile.tsx
@@ -1,9 +1,9 @@
import React, { PureComponent } from 'react'
import { Logger } from '@oceanprotocol/squid'
import filesize from 'filesize'
-import { User } from '../../context/User'
import Button from '../../components/atoms/Button'
import Spinner from '../../components/atoms/Spinner'
+import { User } from '../../context/User'
import styles from './AssetFile.module.scss'
interface AssetFileProps {
@@ -79,13 +79,27 @@ export default class AssetFile extends PureComponent<
{this.state.isLoading ? (
) : (
-
+
+ {states =>
+ states.isLogged ? (
+
+ ) :
+ states.isWeb3 && (
+
+ )
+ }
+
)}
{this.state.error !== '' && (
diff --git a/client/src/routes/Details/AssetFilesDetails.tsx b/client/src/routes/Details/AssetFilesDetails.tsx
index 1c7cfe0..d646d77 100644
--- a/client/src/routes/Details/AssetFilesDetails.tsx
+++ b/client/src/routes/Details/AssetFilesDetails.tsx
@@ -1,5 +1,7 @@
import React, { PureComponent } from 'react'
import AssetFile from './AssetFile'
+import { User } from '../../context/User'
+import Web3message from '../../components/organisms/Web3message'
import styles from './AssetFilesDetails.module.scss'
export default class AssetFilesDetails extends PureComponent<{
@@ -16,6 +18,13 @@ export default class AssetFilesDetails extends PureComponent<{
))}
+
+ {states =>
+ (!states.isNile || !states.isLogged) && (
+
+ )
+ }
+
>
) : (
No files attached.
diff --git a/client/src/routes/Faucet.tsx b/client/src/routes/Faucet.tsx
index e091c2a..d7d6c96 100644
--- a/client/src/routes/Faucet.tsx
+++ b/client/src/routes/Faucet.tsx
@@ -47,14 +47,25 @@ export default class Faucet extends PureComponent<{}, FaucetState> {
private RequestMarkup = () => (
- {states => (
-
- )}
+ {states =>
+ states.isLogged ? (
+
+ ) :
+ states.isWeb3 ? (
+
+ ) : (
+
+ )
+ }
)
@@ -93,7 +104,13 @@ export default class Faucet extends PureComponent<{}, FaucetState> {
title="Faucet"
description="Shower yourself with some Ether for the Ocean POA network."
>
-
+
+ {states =>
+ !states.isNile && (
+
+ )
+ }
+
diff --git a/client/src/routes/Publish/Step.tsx b/client/src/routes/Publish/Step.tsx
index b403dbb..42a5022 100644
--- a/client/src/routes/Publish/Step.tsx
+++ b/client/src/routes/Publish/Step.tsx
@@ -158,9 +158,17 @@ export default class Step extends PureComponent {
{states =>
states.isLogged ? (
- ) : (
+ ) :
+ states.isWeb3 ? (
+ ) : (
+
)
}