mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Disable BUY button from home screen when not on main network (#10453)
This commit is contained in:
parent
2e9c66efc7
commit
ffeaeea4b1
@ -31,6 +31,13 @@ export const GOERLI_DISPLAY_NAME = 'Goerli';
|
|||||||
|
|
||||||
export const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET, GOERLI];
|
export const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET, GOERLI];
|
||||||
|
|
||||||
|
export const TEST_CHAINS = [
|
||||||
|
ROPSTEN_CHAIN_ID,
|
||||||
|
RINKEBY_CHAIN_ID,
|
||||||
|
GOERLI_CHAIN_ID,
|
||||||
|
KOVAN_CHAIN_ID,
|
||||||
|
];
|
||||||
|
|
||||||
export const NETWORK_TYPE_TO_ID_MAP = {
|
export const NETWORK_TYPE_TO_ID_MAP = {
|
||||||
[ROPSTEN]: { networkId: ROPSTEN_NETWORK_ID, chainId: ROPSTEN_CHAIN_ID },
|
[ROPSTEN]: { networkId: ROPSTEN_NETWORK_ID, chainId: ROPSTEN_CHAIN_ID },
|
||||||
[RINKEBY]: { networkId: RINKEBY_NETWORK_ID, chainId: RINKEBY_CHAIN_ID },
|
[RINKEBY]: { networkId: RINKEBY_NETWORK_ID, chainId: RINKEBY_CHAIN_ID },
|
||||||
|
@ -11,6 +11,8 @@ export default class DepositEtherModal extends Component {
|
|||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
network: PropTypes.string.isRequired,
|
network: PropTypes.string.isRequired,
|
||||||
|
isTestnet: PropTypes.bool.isRequired,
|
||||||
|
isMainnet: PropTypes.bool.isRequired,
|
||||||
toWyre: PropTypes.func.isRequired,
|
toWyre: PropTypes.func.isRequired,
|
||||||
address: PropTypes.string.isRequired,
|
address: PropTypes.string.isRequired,
|
||||||
toFaucet: PropTypes.func.isRequired,
|
toFaucet: PropTypes.func.isRequired,
|
||||||
@ -86,9 +88,14 @@ export default class DepositEtherModal extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { network, toWyre, address, toFaucet } = this.props;
|
const {
|
||||||
|
network,
|
||||||
const isTestNetwork = ['3', '4', '5', '42'].find((n) => n === network);
|
toWyre,
|
||||||
|
address,
|
||||||
|
toFaucet,
|
||||||
|
isTestnet,
|
||||||
|
isMainnet,
|
||||||
|
} = this.props;
|
||||||
const networkName = getNetworkDisplayName(network);
|
const networkName = getNetworkDisplayName(network);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -133,7 +140,7 @@ export default class DepositEtherModal extends Component {
|
|||||||
});
|
});
|
||||||
toWyre(address);
|
toWyre(address);
|
||||||
},
|
},
|
||||||
hide: isTestNetwork,
|
hide: !isMainnet,
|
||||||
})}
|
})}
|
||||||
{this.renderRow({
|
{this.renderRow({
|
||||||
logo: (
|
logo: (
|
||||||
@ -158,7 +165,7 @@ export default class DepositEtherModal extends Component {
|
|||||||
text: this.faucetRowText(networkName),
|
text: this.faucetRowText(networkName),
|
||||||
buttonLabel: this.context.t('getEther'),
|
buttonLabel: this.context.t('getEther'),
|
||||||
onButtonClick: () => toFaucet(network),
|
onButtonClick: () => toFaucet(network),
|
||||||
hide: !isTestNetwork,
|
hide: !isTestnet,
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -5,11 +5,14 @@ import {
|
|||||||
showModal,
|
showModal,
|
||||||
hideWarning,
|
hideWarning,
|
||||||
} from '../../../../store/actions';
|
} from '../../../../store/actions';
|
||||||
|
import { getIsTestnet, getIsMainnet } from '../../../../selectors/selectors';
|
||||||
import DepositEtherModal from './deposit-ether-modal.component';
|
import DepositEtherModal from './deposit-ether-modal.component';
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
network: state.metamask.network,
|
network: state.metamask.network,
|
||||||
|
isTestnet: getIsTestnet(state),
|
||||||
|
isMainnet: getIsMainnet(state),
|
||||||
address: state.metamask.selectedAddress,
|
address: state.metamask.selectedAddress,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,8 @@ import {
|
|||||||
isBalanceCached,
|
isBalanceCached,
|
||||||
getSelectedAccount,
|
getSelectedAccount,
|
||||||
getShouldShowFiat,
|
getShouldShowFiat,
|
||||||
getCurrentChainId,
|
getIsMainnet,
|
||||||
|
getIsTestnet,
|
||||||
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 +35,6 @@ 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_CHAIN_ID } from '../../../../../shared/constants/network';
|
|
||||||
import WalletOverview from './wallet-overview';
|
import WalletOverview from './wallet-overview';
|
||||||
|
|
||||||
const EthOverview = ({ className }) => {
|
const EthOverview = ({ className }) => {
|
||||||
@ -61,7 +61,8 @@ 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 chainId = useSelector(getCurrentChainId);
|
const isMainnetChain = useSelector(getIsMainnet);
|
||||||
|
const isTestnetChain = useSelector(getIsTestnet);
|
||||||
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' },
|
||||||
@ -115,6 +116,7 @@ const EthOverview = ({ className }) => {
|
|||||||
<IconButton
|
<IconButton
|
||||||
className="eth-overview__button"
|
className="eth-overview__button"
|
||||||
Icon={BuyIcon}
|
Icon={BuyIcon}
|
||||||
|
disabled={!(isMainnetChain || isTestnetChain)}
|
||||||
label={t('buy')}
|
label={t('buy')}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
depositEvent();
|
depositEvent();
|
||||||
@ -134,10 +136,10 @@ const EthOverview = ({ className }) => {
|
|||||||
{swapsEnabled ? (
|
{swapsEnabled ? (
|
||||||
<IconButton
|
<IconButton
|
||||||
className="eth-overview__button"
|
className="eth-overview__button"
|
||||||
disabled={chainId !== MAINNET_CHAIN_ID}
|
disabled={!isMainnetChain}
|
||||||
Icon={SwapIcon}
|
Icon={SwapIcon}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (chainId === MAINNET_CHAIN_ID) {
|
if (isMainnetChain) {
|
||||||
enteredSwapsEvent();
|
enteredSwapsEvent();
|
||||||
dispatch(setSwapsFromToken(swapsEthToken));
|
dispatch(setSwapsFromToken(swapsEthToken));
|
||||||
if (usingHardwareWallet) {
|
if (usingHardwareWallet) {
|
||||||
@ -152,7 +154,7 @@ const EthOverview = ({ className }) => {
|
|||||||
<Tooltip
|
<Tooltip
|
||||||
title={t('onlyAvailableOnMainnet')}
|
title={t('onlyAvailableOnMainnet')}
|
||||||
position="bottom"
|
position="bottom"
|
||||||
disabled={chainId === MAINNET_CHAIN_ID}
|
disabled={isMainnetChain}
|
||||||
>
|
>
|
||||||
{contents}
|
{contents}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
import { stripHexPrefix } from 'ethereumjs-util';
|
import { stripHexPrefix } from 'ethereumjs-util';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { addHexPrefix } from '../../../app/scripts/lib/util';
|
import { addHexPrefix } from '../../../app/scripts/lib/util';
|
||||||
import { MAINNET, NETWORK_TYPE_RPC } from '../../../shared/constants/network';
|
import {
|
||||||
|
MAINNET,
|
||||||
|
TEST_CHAINS,
|
||||||
|
NETWORK_TYPE_RPC,
|
||||||
|
} from '../../../shared/constants/network';
|
||||||
import {
|
import {
|
||||||
shortenAddress,
|
shortenAddress,
|
||||||
checksumAddress,
|
checksumAddress,
|
||||||
@ -284,6 +288,11 @@ export function getIsMainnet(state) {
|
|||||||
return networkType === MAINNET;
|
return networkType === MAINNET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getIsTestnet(state) {
|
||||||
|
const chainId = getCurrentChainId(state);
|
||||||
|
return TEST_CHAINS.includes(chainId);
|
||||||
|
}
|
||||||
|
|
||||||
export function getPreferences({ metamask }) {
|
export function getPreferences({ metamask }) {
|
||||||
return metamask.preferences;
|
return metamask.preferences;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user