1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 06:07:06 +01:00
metamask-extension/ui/components/app/loading-network-screen/loading-network-screen.container.js

74 lines
2.2 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
import { NETWORK_TYPES } from '../../../../shared/constants/network';
import * as actions from '../../../store/actions';
import {
getAllEnabledNetworks,
getNetworkIdentifier,
isNetworkLoading,
} from '../../../selectors';
import { getProviderConfig } from '../../../ducks/metamask/metamask';
import LoadingNetworkScreen from './loading-network-screen.component';
const DEPRECATED_TEST_NET_CHAINIDS = ['0x3', '0x2a', '0x4'];
2020-02-15 21:34:12 +01:00
const mapStateToProps = (state) => {
const { loadingMessage } = state.appState;
const providerConfig = getProviderConfig(state);
const { rpcUrl, chainId, ticker, nickname, type } = providerConfig;
2020-11-03 00:41:28 +01:00
const setProviderArgs =
type === NETWORK_TYPES.RPC ? [rpcUrl, chainId, ticker, nickname] : [type];
const providerChainId = chainId;
const isDeprecatedNetwork =
DEPRECATED_TEST_NET_CHAINIDS.includes(providerChainId);
const isInfuraRpcUrl = rpcUrl && new URL(rpcUrl).host.endsWith('.infura.io');
const showDeprecatedRpcUrlWarning = isDeprecatedNetwork && isInfuraRpcUrl;
// Ensure we have a nickname to provide the user
// in case of connection error
let networkName = nickname;
if (networkName === undefined) {
const networks = getAllEnabledNetworks(state);
const desiredNetwork = networks.find(
(network) => network.chainId === chainId,
);
if (desiredNetwork) {
networkName = desiredNetwork.nickname;
}
}
return {
isNetworkLoading: isNetworkLoading(state),
loadingMessage,
setProviderArgs,
providerConfig: {
...providerConfig,
nickname: networkName,
},
providerId: getNetworkIdentifier(state),
showDeprecatedRpcUrlWarning,
};
};
2020-02-15 21:34:12 +01:00
const mapDispatchToProps = (dispatch) => {
return {
setProviderType: (type) => {
dispatch(actions.setProviderType(type));
},
rollbackToPreviousProvider: () =>
dispatch(actions.rollbackToPreviousProvider()),
showNetworkDropdown: () => {
if (process.env.MULTICHAIN) {
return dispatch(actions.toggleNetworkMenu());
}
return dispatch(actions.showNetworkDropdown());
},
};
};
2020-11-03 00:41:28 +01:00
export default connect(
mapStateToProps,
mapDispatchToProps,
)(LoadingNetworkScreen);