2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
2022-09-14 16:55:31 +02:00
|
|
|
import { NETWORK_TYPES } from '../../../../shared/constants/network';
|
2021-02-04 19:15:23 +01:00
|
|
|
import * as actions from '../../../store/actions';
|
2023-05-05 16:02:28 +02:00
|
|
|
import {
|
|
|
|
getAllEnabledNetworks,
|
|
|
|
getNetworkIdentifier,
|
|
|
|
isNetworkLoading,
|
|
|
|
} from '../../../selectors';
|
2023-05-02 14:36:24 +02:00
|
|
|
import { getProviderConfig } from '../../../ducks/metamask/metamask';
|
2021-02-04 19:15:23 +01:00
|
|
|
import LoadingNetworkScreen from './loading-network-screen.component';
|
2018-12-06 20:39:47 +01:00
|
|
|
|
2022-09-29 05:26:01 +02:00
|
|
|
const DEPRECATED_TEST_NET_CHAINIDS = ['0x3', '0x2a', '0x4'];
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapStateToProps = (state) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { loadingMessage } = state.appState;
|
2023-05-02 17:53:20 +02:00
|
|
|
const providerConfig = getProviderConfig(state);
|
|
|
|
const { rpcUrl, chainId, ticker, nickname, type } = providerConfig;
|
2018-12-06 20:39:47 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const setProviderArgs =
|
2023-05-02 14:36:24 +02:00
|
|
|
type === NETWORK_TYPES.RPC ? [rpcUrl, chainId, ticker, nickname] : [type];
|
2018-12-06 20:39:47 +01:00
|
|
|
|
2023-05-02 14:36:24 +02:00
|
|
|
const providerChainId = chainId;
|
2022-09-29 05:26:01 +02:00
|
|
|
const isDeprecatedNetwork =
|
|
|
|
DEPRECATED_TEST_NET_CHAINIDS.includes(providerChainId);
|
2023-05-02 14:36:24 +02:00
|
|
|
const isInfuraRpcUrl = rpcUrl && new URL(rpcUrl).host.endsWith('.infura.io');
|
2022-09-29 05:26:01 +02:00
|
|
|
const showDeprecatedRpcUrlWarning = isDeprecatedNetwork && isInfuraRpcUrl;
|
|
|
|
|
2023-05-05 16:02:28 +02:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 20:39:47 +01:00
|
|
|
return {
|
2021-03-12 23:23:26 +01:00
|
|
|
isNetworkLoading: isNetworkLoading(state),
|
2018-12-06 20:39:47 +01:00
|
|
|
loadingMessage,
|
|
|
|
setProviderArgs,
|
2023-05-05 16:02:28 +02:00
|
|
|
providerConfig: {
|
|
|
|
...providerConfig,
|
|
|
|
nickname: networkName,
|
|
|
|
},
|
2018-12-06 20:39:47 +01:00
|
|
|
providerId: getNetworkIdentifier(state),
|
2022-09-29 05:26:01 +02:00
|
|
|
showDeprecatedRpcUrlWarning,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-12-06 20:39:47 +01:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2018-12-06 20:39:47 +01:00
|
|
|
return {
|
|
|
|
setProviderType: (type) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(actions.setProviderType(type));
|
2018-12-06 20:39:47 +01:00
|
|
|
},
|
2021-01-07 00:31:11 +01:00
|
|
|
rollbackToPreviousProvider: () =>
|
|
|
|
dispatch(actions.rollbackToPreviousProvider()),
|
2023-05-05 16:02:28 +02:00
|
|
|
showNetworkDropdown: () => {
|
2023-06-01 23:14:38 +02:00
|
|
|
return dispatch(actions.toggleNetworkMenu());
|
2023-05-05 16:02:28 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-12-06 20:39:47 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps,
|
2021-02-04 19:15:23 +01:00
|
|
|
)(LoadingNetworkScreen);
|