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

add duero to network detection

This commit is contained in:
Matthias Kretschmann 2019-05-13 15:55:36 +02:00
parent 70deb126b8
commit f636170e3c
Signed by: m
GPG Key ID: 606EEEF3C479A91F
17 changed files with 58 additions and 33 deletions

View File

@ -2,7 +2,7 @@ const userMock = {
isLogged: false,
isLoading: false,
isWeb3: false,
isNile: false,
isCorrectNetwork: false,
account: '',
web3: {},
ocean: {},
@ -17,7 +17,7 @@ const userMockConnected = {
isLogged: true,
isLoading: false,
isWeb3: true,
isNile: true,
isCorrectNetwork: true,
account: '0xxxxxx',
web3: {},
ocean: {},

View File

@ -22,7 +22,7 @@ const Indicator = ({
{states =>
!states.isWeb3 ? (
<span className={styles.statusIndicator} />
) : !states.isLogged || !states.isNile ? (
) : !states.isLogged || !states.isCorrectNetwork ? (
<span className={styles.statusIndicatorCloseEnough} />
) : states.isLogged ? (
<span className={styles.statusIndicatorActive} />

View File

@ -36,7 +36,11 @@ describe('Popover', () => {
it('renders with wrong network', () => {
const { container } = render(
<User.Provider
value={{ ...userMockConnected, isNile: false, network: '1' }}
value={{
...userMockConnected,
isCorrectNetwork: false,
network: '1'
}}
>
<Popover forwardedRef={() => null} style={{}} />
</User.Provider>

View File

@ -8,7 +8,13 @@ export default class Popover extends PureComponent<{
style: React.CSSProperties
}> {
public render() {
const { account, balance, network, isWeb3, isNile } = this.context
const {
account,
balance,
network,
isWeb3,
isCorrectNetwork
} = this.context
return (
<div
@ -47,7 +53,7 @@ export default class Popover extends PureComponent<{
)}
<div className={styles.popoverInfoline}>
{network && !isNile
{network && !isCorrectNetwork
? 'Please connect to Custom RPC\n https://nile.dev-ocean.com'
: network && `Connected to ${network} network`}
</div>

View File

@ -57,10 +57,10 @@ export default class AssetsUser extends PureComponent<
}
public render() {
const { account, isNile } = this.context
const { account, isCorrectNetwork } = this.context
return (
isNile &&
isCorrectNetwork &&
account && (
<div className={styles.assetsUser}>
{this.props.recent && (

View File

@ -27,7 +27,9 @@ describe('Web3message', () => {
it('renders with noAccount message', () => {
const { container } = render(
<User.Provider value={{ ...userMock, isWeb3: true, isNile: true }}>
<User.Provider
value={{ ...userMock, isWeb3: true, isCorrectNetwork: true }}
>
<Web3message />
</User.Provider>
)
@ -49,7 +51,7 @@ describe('Web3message', () => {
value={{
...userMock,
isWeb3: true,
isNile: true
isCorrectNetwork: true
}}
>
<Web3message />

View File

@ -32,7 +32,7 @@ export default class Web3message extends PureComponent {
public render() {
const {
isWeb3,
isNile,
isCorrectNetwork,
isLogged,
account,
unlockAccounts
@ -40,7 +40,7 @@ export default class Web3message extends PureComponent {
return !isWeb3
? this.message(content.noweb3)
: !isNile
: !isCorrectNetwork
? this.message(content.wrongNetwork)
: !isLogged
? this.message(content.noAccount, '', unlockAccounts)

View File

@ -46,7 +46,7 @@ interface UserProviderState {
isLogged: boolean
isLoading: boolean
isWeb3: boolean
isNile: boolean
isCorrectNetwork: boolean
account: string
balance: {
eth: number
@ -74,7 +74,7 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
isLogged: false,
isLoading: true,
isWeb3: false,
isNile: false,
isCorrectNetwork: false,
balance: {
eth: 0,
ocn: 0
@ -151,23 +151,31 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
//
// Detecting network with window.web3
//
let isNile
let isCorrectNetwork
await window.web3.eth.net.getId((err, netId) => {
if (err) return
isNile = netId === 8995
const network = isNile ? 'Nile' : netId.toString()
const isNile = netId === 8995
const isDuero = netId === 2199
isCorrectNetwork = isNile || isDuero
const network = isNile
? 'Nile'
: isDuero
? 'Duero'
: netId.toString()
if (
isNile !== this.state.isNile ||
isCorrectNetwork !== this.state.isCorrectNetwork ||
network !== this.state.network
) {
this.setState({ isNile, network })
this.setState({ isCorrectNetwork, network })
}
})
if (!isNile) {
if (!isCorrectNetwork) {
web3 = this.state.web3 // eslint-disable-line
}
@ -201,13 +209,13 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
}
private fetchAccounts = async () => {
const { ocean, isWeb3, isLogged, isNile } = this.state
const { ocean, isWeb3, isLogged, isCorrectNetwork } = this.state
if (isWeb3) {
let accounts
// Modern dapp browsers
if (window.ethereum && !isLogged && isNile) {
if (window.ethereum && !isLogged && isCorrectNetwork) {
// simply set to empty, and have user click a button somewhere
// to initiate account unlocking
accounts = []
@ -250,8 +258,11 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
if (isWeb3) {
const network = await ocean.keeper.getNetworkName()
const isNile = network === 'Nile'
const isDuero = network === 'Duero'
const isCorrectNetwork = isNile || isDuero
network !== this.state.network && this.setState({ isNile, network })
network !== this.state.network &&
this.setState({ isCorrectNetwork, network })
}
}

View File

@ -4,7 +4,7 @@ export const User = React.createContext({
isLogged: false,
isLoading: false,
isWeb3: false,
isNile: false,
isCorrectNetwork: false,
account: '',
web3: {},
ocean: {},

View File

@ -20,7 +20,7 @@ const contextConnectedMock = {
isLogged: true,
isLoading: false,
isWeb3: true,
isNile: true,
isCorrectNetwork: true,
account: '',
web3: {},
ocean: {},

View File

@ -76,7 +76,7 @@ export default class AssetFile extends PureComponent<
public render() {
const { ddo, file } = this.props
const { isLoading, message, error } = this.state
const { isLogged, isNile } = this.context
const { isLogged, isCorrectNetwork } = this.context
const { index } = file
return (
@ -102,7 +102,7 @@ export default class AssetFile extends PureComponent<
// https://github.com/oceanprotocol/squid-js/pull/221
// is released
onClick={() => this.purchaseAsset(ddo, index || 0)}
disabled={!isLogged || !isNile}
disabled={!isLogged || !isCorrectNetwork}
>
Get file
</Button>

View File

@ -19,7 +19,7 @@ export default class AssetFilesDetails extends PureComponent<{
<AssetFile key={file.index} ddo={ddo} file={file} />
))}
</div>
{(!this.context.isNile || !this.context.isLogged) && (
{(!this.context.isCorrectNetwork || !this.context.isLogged) && (
<Web3message />
)}
</>

View File

@ -80,7 +80,9 @@ export default class Faucet extends PureComponent<{}, FaucetState> {
<Button
primary
onClick={() => this.getTokens(this.context.requestFromFaucet)}
disabled={!this.context.isLogged || !this.context.isNile}
disabled={
!this.context.isLogged || !this.context.isCorrectNetwork
}
>
Request Ether
</Button>

View File

@ -14,7 +14,7 @@ describe('History', () => {
isLogged: false,
isLoading: false,
isWeb3: false,
isNile: false,
isCorrectNetwork: false,
account: '',
web3: {},
ocean: {},

View File

@ -8,7 +8,7 @@ export default class History extends Component {
public render() {
return (
<Route title="History">
{(!this.context.isLogged || !this.context.isNile) && (
{(!this.context.isLogged || !this.context.isCorrectNetwork) && (
<Web3message />
)}

View File

@ -319,7 +319,7 @@ class Publish extends Component<{}, PublishState> {
title="Publish"
description="Publish a new data set into the Ocean Protocol Network."
>
{(!this.context.isLogged || !this.context.isNile) && (
{(!this.context.isLogged || !this.context.isCorrectNetwork) && (
<Web3message />
)}

View File

@ -14,7 +14,7 @@ describe('Search', () => {
isLogged: false,
isLoading: false,
isWeb3: false,
isNile: false,
isCorrectNetwork: false,
account: '',
web3: {},
ocean: {