Disable swaps based on chainId, instead of network id (#10155)

feature/default_network_editable
Dan J Miller 4 years ago committed by Dan Miller
parent 10afdcce3f
commit 3539885ec2
  1. 12
      ui/app/components/app/wallet-overview/eth-overview.js
  2. 12
      ui/app/components/app/wallet-overview/token-overview.js
  3. 7
      ui/app/pages/swaps/index.js

@ -23,7 +23,7 @@ import {
isBalanceCached, isBalanceCached,
getSelectedAccount, getSelectedAccount,
getShouldShowFiat, getShouldShowFiat,
getCurrentNetworkId, getCurrentChainId,
getCurrentKeyring, getCurrentKeyring,
} from '../../../selectors/selectors' } from '../../../selectors/selectors'
import SwapIcon from '../../ui/icon/swap-icon.component' import SwapIcon from '../../ui/icon/swap-icon.component'
@ -34,7 +34,7 @@ import {
setSwapsFromToken, setSwapsFromToken,
} from '../../../ducks/swaps/swaps' } from '../../../ducks/swaps/swaps'
import IconButton from '../../ui/icon-button' import IconButton from '../../ui/icon-button'
import { MAINNET_NETWORK_ID } from '../../../../../app/scripts/controllers/network/enums' import { MAINNET_CHAIN_ID } from '../../../../../app/scripts/controllers/network/enums'
import WalletOverview from './wallet-overview' import WalletOverview from './wallet-overview'
const EthOverview = ({ className }) => { const EthOverview = ({ className }) => {
@ -61,7 +61,7 @@ const EthOverview = ({ className }) => {
const showFiat = useSelector(getShouldShowFiat) const showFiat = useSelector(getShouldShowFiat)
const selectedAccount = useSelector(getSelectedAccount) const selectedAccount = useSelector(getSelectedAccount)
const { balance } = selectedAccount const { balance } = selectedAccount
const networkId = useSelector(getCurrentNetworkId) const chainId = useSelector(getCurrentChainId)
const enteredSwapsEvent = useNewMetricEvent({ const enteredSwapsEvent = useNewMetricEvent({
event: 'Swaps Opened', event: 'Swaps Opened',
properties: { source: 'Main View', active_currency: 'ETH' }, properties: { source: 'Main View', active_currency: 'ETH' },
@ -134,10 +134,10 @@ const EthOverview = ({ className }) => {
{swapsEnabled ? ( {swapsEnabled ? (
<IconButton <IconButton
className="eth-overview__button" className="eth-overview__button"
disabled={networkId !== MAINNET_NETWORK_ID} disabled={chainId !== MAINNET_CHAIN_ID}
Icon={SwapIcon} Icon={SwapIcon}
onClick={() => { onClick={() => {
if (networkId === MAINNET_NETWORK_ID) { if (chainId === MAINNET_CHAIN_ID) {
enteredSwapsEvent() enteredSwapsEvent()
dispatch(setSwapsFromToken(swapsEthToken)) dispatch(setSwapsFromToken(swapsEthToken))
if (usingHardwareWallet) { if (usingHardwareWallet) {
@ -152,7 +152,7 @@ const EthOverview = ({ className }) => {
<Tooltip <Tooltip
title={t('onlyAvailableOnMainnet')} title={t('onlyAvailableOnMainnet')}
position="bottom" position="bottom"
disabled={networkId === '1'} disabled={chainId === MAINNET_CHAIN_ID}
> >
{contents} {contents}
</Tooltip> </Tooltip>

@ -25,9 +25,9 @@ import {
import { import {
getAssetImages, getAssetImages,
getCurrentKeyring, getCurrentKeyring,
getCurrentNetworkId, getCurrentChainId,
} from '../../../selectors/selectors' } from '../../../selectors/selectors'
import { MAINNET_NETWORK_ID } from '../../../../../app/scripts/controllers/network/enums' import { MAINNET_CHAIN_ID } from '../../../../../app/scripts/controllers/network/enums'
import SwapIcon from '../../ui/icon/swap-icon.component' import SwapIcon from '../../ui/icon/swap-icon.component'
import SendIcon from '../../ui/icon/overview-send-icon.component' import SendIcon from '../../ui/icon/overview-send-icon.component'
@ -58,7 +58,7 @@ const TokenOverview = ({ className, token }) => {
balanceToRender, balanceToRender,
token.symbol, token.symbol,
) )
const networkId = useSelector(getCurrentNetworkId) const chainId = useSelector(getCurrentChainId)
const enteredSwapsEvent = useNewMetricEvent({ const enteredSwapsEvent = useNewMetricEvent({
event: 'Swaps Opened', event: 'Swaps Opened',
properties: { source: 'Token View', active_currency: token.symbol }, properties: { source: 'Token View', active_currency: token.symbol },
@ -100,10 +100,10 @@ const TokenOverview = ({ className, token }) => {
{swapsEnabled ? ( {swapsEnabled ? (
<IconButton <IconButton
className="token-overview__button" className="token-overview__button"
disabled={networkId !== MAINNET_NETWORK_ID} disabled={chainId !== MAINNET_CHAIN_ID}
Icon={SwapIcon} Icon={SwapIcon}
onClick={() => { onClick={() => {
if (networkId === MAINNET_NETWORK_ID) { if (chainId === MAINNET_CHAIN_ID) {
enteredSwapsEvent() enteredSwapsEvent()
dispatch( dispatch(
setSwapsFromToken({ setSwapsFromToken({
@ -125,7 +125,7 @@ const TokenOverview = ({ className, token }) => {
<Tooltip <Tooltip
title={t('onlyAvailableOnMainnet')} title={t('onlyAvailableOnMainnet')}
position="bottom" position="bottom"
disabled={networkId === '1'} disabled={chainId === MAINNET_CHAIN_ID}
> >
{contents} {contents}
</Tooltip> </Tooltip>

@ -12,6 +12,7 @@ import { I18nContext } from '../../contexts/i18n'
import { import {
getSelectedAccount, getSelectedAccount,
getCurrentNetworkId, getCurrentNetworkId,
getCurrentChainId,
} from '../../selectors/selectors' } from '../../selectors/selectors'
import { import {
getFromToken, getFromToken,
@ -47,6 +48,7 @@ import {
SWAP_FAILED_ERROR, SWAP_FAILED_ERROR,
OFFLINE_FOR_MAINTENANCE, OFFLINE_FOR_MAINTENANCE,
} from '../../helpers/constants/swaps' } from '../../helpers/constants/swaps'
import { MAINNET_CHAIN_ID } from '../../../../app/scripts/controllers/network/enums'
import { import {
resetBackgroundSwapsState, resetBackgroundSwapsState,
@ -245,6 +247,11 @@ export default function Swap() {
return () => window.removeEventListener('beforeunload', fn) return () => window.removeEventListener('beforeunload', fn)
}, [dispatch, isLoadingQuotesRoute]) }, [dispatch, isLoadingQuotesRoute])
const chainId = useSelector(getCurrentChainId)
if (chainId !== MAINNET_CHAIN_ID) {
return <Redirect to={{ pathname: DEFAULT_ROUTE }} />
}
return ( return (
<div className="swaps"> <div className="swaps">
<div className="swaps__container"> <div className="swaps__container">

Loading…
Cancel
Save