mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
adapt network message based on configured networks
This commit is contained in:
parent
0d1b69ed79
commit
1afcd45882
@ -4,11 +4,11 @@ import styles from './Details.module.css'
|
|||||||
import { useOcean } from '@oceanprotocol/react'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
import Web3Feedback from './Feedback'
|
import Web3Feedback from './Feedback'
|
||||||
import { formatNumber } from '../../../utils'
|
import { formatNumber } from '../../../utils'
|
||||||
import { connectWallet } from '../../../utils/wallet'
|
import { connectWallet, getNetworkName } from '../../../utils/wallet'
|
||||||
import { getInjectedProviderName } from 'web3modal'
|
import { getInjectedProviderName } from 'web3modal'
|
||||||
|
|
||||||
export default function Details({ attrs }: { attrs: any }): ReactElement {
|
export default function Details({ attrs }: { attrs: any }): ReactElement {
|
||||||
const { ocean, balance, connect, logout } = useOcean()
|
const { ocean, balance, connect, logout, chainId } = useOcean()
|
||||||
const [balanceOcean, setBalanceOcean] = useState('0')
|
const [balanceOcean, setBalanceOcean] = useState('0')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -32,7 +32,11 @@ export default function Details({ attrs }: { attrs: any }): ReactElement {
|
|||||||
<span>ETH</span> {formatNumber(Number(balance))}
|
<span>ETH</span> {formatNumber(Number(balance))}
|
||||||
</li>
|
</li>
|
||||||
<li className={styles.actions}>
|
<li className={styles.actions}>
|
||||||
<span title="Connected provider">{getInjectedProviderName()}</span>
|
<span title="Connected provider">
|
||||||
|
{getInjectedProviderName()}
|
||||||
|
<br />
|
||||||
|
{getNetworkName(chainId)}
|
||||||
|
</span>
|
||||||
<Button
|
<Button
|
||||||
style="text"
|
style="text"
|
||||||
size="small"
|
size="small"
|
||||||
|
@ -2,7 +2,8 @@ import React, { ReactElement } from 'react'
|
|||||||
import Status from '../../atoms/Status'
|
import Status from '../../atoms/Status'
|
||||||
import styles from './Feedback.module.css'
|
import styles from './Feedback.module.css'
|
||||||
import { useOcean } from '@oceanprotocol/react'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
import { isCorrectNetwork } from '../../../utils/wallet'
|
import { isCorrectNetwork, getNetworkName } from '../../../utils/wallet'
|
||||||
|
import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
|
||||||
|
|
||||||
export declare type Web3Error = {
|
export declare type Web3Error = {
|
||||||
status: 'error' | 'warning' | 'success'
|
status: 'error' | 'warning' | 'success'
|
||||||
@ -15,10 +16,14 @@ export default function Web3Feedback({
|
|||||||
}: {
|
}: {
|
||||||
isBalanceInsufficient?: boolean
|
isBalanceInsufficient?: boolean
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
|
const { appConfig } = useSiteMetadata()
|
||||||
const { account, status, chainId } = useOcean()
|
const { account, status, chainId } = useOcean()
|
||||||
const isOceanConnectionError = status === -1
|
const isOceanConnectionError = status === -1
|
||||||
const correctNetwork = isCorrectNetwork(chainId)
|
const correctNetwork = isCorrectNetwork(chainId)
|
||||||
const showFeedback = !account || isOceanConnectionError || !correctNetwork
|
const showFeedback = !account || isOceanConnectionError || !correctNetwork
|
||||||
|
const allowedNetworkNames = appConfig.networks.map((network: number) =>
|
||||||
|
getNetworkName(network)
|
||||||
|
)
|
||||||
|
|
||||||
const state = !account
|
const state = !account
|
||||||
? 'error'
|
? 'error'
|
||||||
@ -45,7 +50,7 @@ export default function Web3Feedback({
|
|||||||
: isOceanConnectionError
|
: isOceanConnectionError
|
||||||
? 'Please try again.'
|
? 'Please try again.'
|
||||||
: !correctNetwork
|
: !correctNetwork
|
||||||
? 'Please connect to Main, Rinkeby, or Kovan.'
|
? `Please connect to ${allowedNetworkNames}.`
|
||||||
: isBalanceInsufficient === true
|
: isBalanceInsufficient === true
|
||||||
? 'You do not have enough OCEAN in your wallet to purchase this asset.'
|
? 'You do not have enough OCEAN in your wallet to purchase this asset.'
|
||||||
: 'Something went wrong.'
|
: 'Something went wrong.'
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { OceanProviderValue } from '@oceanprotocol/react'
|
import { OceanProviderValue } from '@oceanprotocol/react'
|
||||||
|
import atlas from '@ethereum-navigator/atlas'
|
||||||
import { networks, infuraProjectId } from '../../app.config'
|
import { networks, infuraProjectId } from '../../app.config'
|
||||||
|
|
||||||
const web3ModalTheme = {
|
const web3ModalTheme = {
|
||||||
@ -39,3 +40,16 @@ export function accountTruncate(account: string): string {
|
|||||||
const truncated = account.replace(middle, '…')
|
const truncated = account.replace(middle, '…')
|
||||||
return truncated
|
return truncated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getNetworkName(chainId: number): string {
|
||||||
|
switch (chainId) {
|
||||||
|
case 1:
|
||||||
|
return 'Main'
|
||||||
|
case 4:
|
||||||
|
return 'Rinkeby'
|
||||||
|
case 42:
|
||||||
|
return 'Kovan'
|
||||||
|
default:
|
||||||
|
return 'Unknown'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user