mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
Merge pull request #121 from oceanprotocol/fix/duero-detection
add Duero to network detection
This commit is contained in:
commit
124db083e9
@ -2,7 +2,7 @@ const userMock = {
|
|||||||
isLogged: false,
|
isLogged: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isWeb3: false,
|
isWeb3: false,
|
||||||
isNile: false,
|
isCorrectNetwork: false,
|
||||||
account: '',
|
account: '',
|
||||||
web3: {},
|
web3: {},
|
||||||
ocean: {},
|
ocean: {},
|
||||||
@ -17,7 +17,7 @@ const userMockConnected = {
|
|||||||
isLogged: true,
|
isLogged: true,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isWeb3: true,
|
isWeb3: true,
|
||||||
isNile: true,
|
isCorrectNetwork: true,
|
||||||
account: '0xxxxxx',
|
account: '0xxxxxx',
|
||||||
web3: {},
|
web3: {},
|
||||||
ocean: {},
|
ocean: {},
|
||||||
|
@ -22,7 +22,7 @@ const Indicator = ({
|
|||||||
{states =>
|
{states =>
|
||||||
!states.isWeb3 ? (
|
!states.isWeb3 ? (
|
||||||
<span className={styles.statusIndicator} />
|
<span className={styles.statusIndicator} />
|
||||||
) : !states.isLogged || !states.isNile ? (
|
) : !states.isLogged || !states.isCorrectNetwork ? (
|
||||||
<span className={styles.statusIndicatorCloseEnough} />
|
<span className={styles.statusIndicatorCloseEnough} />
|
||||||
) : states.isLogged ? (
|
) : states.isLogged ? (
|
||||||
<span className={styles.statusIndicatorActive} />
|
<span className={styles.statusIndicatorActive} />
|
||||||
|
@ -36,7 +36,11 @@ describe('Popover', () => {
|
|||||||
it('renders with wrong network', () => {
|
it('renders with wrong network', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<User.Provider
|
<User.Provider
|
||||||
value={{ ...userMockConnected, isNile: false, network: '1' }}
|
value={{
|
||||||
|
...userMockConnected,
|
||||||
|
isCorrectNetwork: false,
|
||||||
|
network: '1'
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Popover forwardedRef={() => null} style={{}} />
|
<Popover forwardedRef={() => null} style={{}} />
|
||||||
</User.Provider>
|
</User.Provider>
|
||||||
|
@ -8,7 +8,13 @@ export default class Popover extends PureComponent<{
|
|||||||
style: React.CSSProperties
|
style: React.CSSProperties
|
||||||
}> {
|
}> {
|
||||||
public render() {
|
public render() {
|
||||||
const { account, balance, network, isWeb3, isNile } = this.context
|
const {
|
||||||
|
account,
|
||||||
|
balance,
|
||||||
|
network,
|
||||||
|
isWeb3,
|
||||||
|
isCorrectNetwork
|
||||||
|
} = this.context
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -47,7 +53,7 @@ export default class Popover extends PureComponent<{
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<div className={styles.popoverInfoline}>
|
<div className={styles.popoverInfoline}>
|
||||||
{network && !isNile
|
{network && !isCorrectNetwork
|
||||||
? 'Please connect to Custom RPC\n https://nile.dev-ocean.com'
|
? 'Please connect to Custom RPC\n https://nile.dev-ocean.com'
|
||||||
: network && `Connected to ${network} network`}
|
: network && `Connected to ${network} network`}
|
||||||
</div>
|
</div>
|
||||||
|
@ -57,10 +57,10 @@ export default class AssetsUser extends PureComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const { account, isNile } = this.context
|
const { account, isCorrectNetwork } = this.context
|
||||||
|
|
||||||
return (
|
return (
|
||||||
isNile &&
|
isCorrectNetwork &&
|
||||||
account && (
|
account && (
|
||||||
<div className={styles.assetsUser}>
|
<div className={styles.assetsUser}>
|
||||||
{this.props.recent && (
|
{this.props.recent && (
|
||||||
|
@ -27,7 +27,9 @@ describe('Web3message', () => {
|
|||||||
|
|
||||||
it('renders with noAccount message', () => {
|
it('renders with noAccount message', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<User.Provider value={{ ...userMock, isWeb3: true, isNile: true }}>
|
<User.Provider
|
||||||
|
value={{ ...userMock, isWeb3: true, isCorrectNetwork: true }}
|
||||||
|
>
|
||||||
<Web3message />
|
<Web3message />
|
||||||
</User.Provider>
|
</User.Provider>
|
||||||
)
|
)
|
||||||
@ -49,7 +51,7 @@ describe('Web3message', () => {
|
|||||||
value={{
|
value={{
|
||||||
...userMock,
|
...userMock,
|
||||||
isWeb3: true,
|
isWeb3: true,
|
||||||
isNile: true
|
isCorrectNetwork: true
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Web3message />
|
<Web3message />
|
||||||
|
@ -32,7 +32,7 @@ export default class Web3message extends PureComponent {
|
|||||||
public render() {
|
public render() {
|
||||||
const {
|
const {
|
||||||
isWeb3,
|
isWeb3,
|
||||||
isNile,
|
isCorrectNetwork,
|
||||||
isLogged,
|
isLogged,
|
||||||
account,
|
account,
|
||||||
unlockAccounts
|
unlockAccounts
|
||||||
@ -40,7 +40,7 @@ export default class Web3message extends PureComponent {
|
|||||||
|
|
||||||
return !isWeb3
|
return !isWeb3
|
||||||
? this.message(content.noweb3)
|
? this.message(content.noweb3)
|
||||||
: !isNile
|
: !isCorrectNetwork
|
||||||
? this.message(content.wrongNetwork)
|
? this.message(content.wrongNetwork)
|
||||||
: !isLogged
|
: !isLogged
|
||||||
? this.message(content.noAccount, '', unlockAccounts)
|
? this.message(content.noAccount, '', unlockAccounts)
|
||||||
|
@ -46,7 +46,7 @@ interface UserProviderState {
|
|||||||
isLogged: boolean
|
isLogged: boolean
|
||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
isWeb3: boolean
|
isWeb3: boolean
|
||||||
isNile: boolean
|
isCorrectNetwork: boolean
|
||||||
account: string
|
account: string
|
||||||
balance: {
|
balance: {
|
||||||
eth: number
|
eth: number
|
||||||
@ -74,7 +74,7 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
|||||||
isLogged: false,
|
isLogged: false,
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
isWeb3: false,
|
isWeb3: false,
|
||||||
isNile: false,
|
isCorrectNetwork: false,
|
||||||
balance: {
|
balance: {
|
||||||
eth: 0,
|
eth: 0,
|
||||||
ocn: 0
|
ocn: 0
|
||||||
@ -151,23 +151,31 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
|||||||
//
|
//
|
||||||
// Detecting network with window.web3
|
// Detecting network with window.web3
|
||||||
//
|
//
|
||||||
let isNile
|
let isCorrectNetwork
|
||||||
|
|
||||||
await window.web3.eth.net.getId((err, netId) => {
|
await window.web3.eth.net.getId((err, netId) => {
|
||||||
if (err) return
|
if (err) return
|
||||||
|
|
||||||
isNile = netId === 8995
|
const isNile = netId === 8995
|
||||||
const network = isNile ? 'Nile' : netId.toString()
|
const isDuero = netId === 2199
|
||||||
|
|
||||||
|
isCorrectNetwork = isNile || isDuero
|
||||||
|
|
||||||
|
const network = isNile
|
||||||
|
? 'Nile'
|
||||||
|
: isDuero
|
||||||
|
? 'Duero'
|
||||||
|
: netId.toString()
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isNile !== this.state.isNile ||
|
isCorrectNetwork !== this.state.isCorrectNetwork ||
|
||||||
network !== this.state.network
|
network !== this.state.network
|
||||||
) {
|
) {
|
||||||
this.setState({ isNile, network })
|
this.setState({ isCorrectNetwork, network })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!isNile) {
|
if (!isCorrectNetwork) {
|
||||||
web3 = this.state.web3 // eslint-disable-line
|
web3 = this.state.web3 // eslint-disable-line
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,13 +209,13 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fetchAccounts = async () => {
|
private fetchAccounts = async () => {
|
||||||
const { ocean, isWeb3, isLogged, isNile } = this.state
|
const { ocean, isWeb3, isLogged, isCorrectNetwork } = this.state
|
||||||
|
|
||||||
if (isWeb3) {
|
if (isWeb3) {
|
||||||
let accounts
|
let accounts
|
||||||
|
|
||||||
// Modern dapp browsers
|
// Modern dapp browsers
|
||||||
if (window.ethereum && !isLogged && isNile) {
|
if (window.ethereum && !isLogged && isCorrectNetwork) {
|
||||||
// simply set to empty, and have user click a button somewhere
|
// simply set to empty, and have user click a button somewhere
|
||||||
// to initiate account unlocking
|
// to initiate account unlocking
|
||||||
accounts = []
|
accounts = []
|
||||||
@ -250,8 +258,11 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
|
|||||||
if (isWeb3) {
|
if (isWeb3) {
|
||||||
const network = await ocean.keeper.getNetworkName()
|
const network = await ocean.keeper.getNetworkName()
|
||||||
const isNile = network === 'Nile'
|
const isNile = network === 'Nile'
|
||||||
|
const isDuero = network === 'Development'
|
||||||
|
const isCorrectNetwork = isNile || isDuero
|
||||||
|
|
||||||
network !== this.state.network && this.setState({ isNile, network })
|
network !== this.state.network &&
|
||||||
|
this.setState({ isCorrectNetwork, network })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ export const User = React.createContext({
|
|||||||
isLogged: false,
|
isLogged: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isWeb3: false,
|
isWeb3: false,
|
||||||
isNile: false,
|
isCorrectNetwork: false,
|
||||||
account: '',
|
account: '',
|
||||||
web3: {},
|
web3: {},
|
||||||
ocean: {},
|
ocean: {},
|
||||||
|
@ -20,7 +20,7 @@ const contextConnectedMock = {
|
|||||||
isLogged: true,
|
isLogged: true,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isWeb3: true,
|
isWeb3: true,
|
||||||
isNile: true,
|
isCorrectNetwork: true,
|
||||||
account: '',
|
account: '',
|
||||||
web3: {},
|
web3: {},
|
||||||
ocean: {},
|
ocean: {},
|
||||||
|
@ -76,7 +76,7 @@ export default class AssetFile extends PureComponent<
|
|||||||
public render() {
|
public render() {
|
||||||
const { ddo, file } = this.props
|
const { ddo, file } = this.props
|
||||||
const { isLoading, message, error } = this.state
|
const { isLoading, message, error } = this.state
|
||||||
const { isLogged, isNile } = this.context
|
const { isLogged, isCorrectNetwork } = this.context
|
||||||
const { index } = file
|
const { index } = file
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -102,7 +102,7 @@ export default class AssetFile extends PureComponent<
|
|||||||
// https://github.com/oceanprotocol/squid-js/pull/221
|
// https://github.com/oceanprotocol/squid-js/pull/221
|
||||||
// is released
|
// is released
|
||||||
onClick={() => this.purchaseAsset(ddo, index || 0)}
|
onClick={() => this.purchaseAsset(ddo, index || 0)}
|
||||||
disabled={!isLogged || !isNile}
|
disabled={!isLogged || !isCorrectNetwork}
|
||||||
>
|
>
|
||||||
Get file
|
Get file
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -19,7 +19,7 @@ export default class AssetFilesDetails extends PureComponent<{
|
|||||||
<AssetFile key={file.index} ddo={ddo} file={file} />
|
<AssetFile key={file.index} ddo={ddo} file={file} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
{(!this.context.isNile || !this.context.isLogged) && (
|
{(!this.context.isCorrectNetwork || !this.context.isLogged) && (
|
||||||
<Web3message />
|
<Web3message />
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
@ -80,7 +80,9 @@ export default class Faucet extends PureComponent<{}, FaucetState> {
|
|||||||
<Button
|
<Button
|
||||||
primary
|
primary
|
||||||
onClick={() => this.getTokens(this.context.requestFromFaucet)}
|
onClick={() => this.getTokens(this.context.requestFromFaucet)}
|
||||||
disabled={!this.context.isLogged || !this.context.isNile}
|
disabled={
|
||||||
|
!this.context.isLogged || !this.context.isCorrectNetwork
|
||||||
|
}
|
||||||
>
|
>
|
||||||
Request Ether
|
Request Ether
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -14,7 +14,7 @@ describe('History', () => {
|
|||||||
isLogged: false,
|
isLogged: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isWeb3: false,
|
isWeb3: false,
|
||||||
isNile: false,
|
isCorrectNetwork: false,
|
||||||
account: '',
|
account: '',
|
||||||
web3: {},
|
web3: {},
|
||||||
ocean: {},
|
ocean: {},
|
||||||
|
@ -8,7 +8,7 @@ export default class History extends Component {
|
|||||||
public render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<Route title="History">
|
<Route title="History">
|
||||||
{(!this.context.isLogged || !this.context.isNile) && (
|
{(!this.context.isLogged || !this.context.isCorrectNetwork) && (
|
||||||
<Web3message />
|
<Web3message />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -319,7 +319,7 @@ class Publish extends Component<{}, PublishState> {
|
|||||||
title="Publish"
|
title="Publish"
|
||||||
description="Publish a new data set into the Ocean Protocol Network."
|
description="Publish a new data set into the Ocean Protocol Network."
|
||||||
>
|
>
|
||||||
{(!this.context.isLogged || !this.context.isNile) && (
|
{(!this.context.isLogged || !this.context.isCorrectNetwork) && (
|
||||||
<Web3message />
|
<Web3message />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ describe('Search', () => {
|
|||||||
isLogged: false,
|
isLogged: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isWeb3: false,
|
isWeb3: false,
|
||||||
isNile: false,
|
isCorrectNetwork: false,
|
||||||
account: '',
|
account: '',
|
||||||
web3: {},
|
web3: {},
|
||||||
ocean: {
|
ocean: {
|
||||||
|
Loading…
Reference in New Issue
Block a user