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';
|
2021-03-12 23:23:26 +01:00
|
|
|
import { getNetworkIdentifier, isNetworkLoading } from '../../../selectors';
|
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;
|
2021-03-12 23:23:26 +01:00
|
|
|
const { provider } = state.metamask;
|
2021-02-04 19:15:23 +01:00
|
|
|
const { rpcUrl, chainId, ticker, nickname, type } = provider;
|
2018-12-06 20:39:47 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const setProviderArgs =
|
2022-09-14 16:55:31 +02:00
|
|
|
type === NETWORK_TYPES.RPC
|
2021-01-20 17:49:05 +01:00
|
|
|
? [rpcUrl, chainId, ticker, nickname]
|
2021-02-04 19:15:23 +01:00
|
|
|
: [provider.type];
|
2018-12-06 20:39:47 +01:00
|
|
|
|
2022-09-29 05:26:01 +02:00
|
|
|
const providerChainId = provider?.chainId;
|
|
|
|
const isDeprecatedNetwork =
|
|
|
|
DEPRECATED_TEST_NET_CHAINIDS.includes(providerChainId);
|
2022-11-23 22:30:45 +01:00
|
|
|
const isInfuraRpcUrl =
|
|
|
|
provider?.rpcUrl && new URL(provider.rpcUrl).host.endsWith('.infura.io');
|
2022-09-29 05:26:01 +02:00
|
|
|
const showDeprecatedRpcUrlWarning = isDeprecatedNetwork && isInfuraRpcUrl;
|
|
|
|
|
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,
|
|
|
|
provider,
|
|
|
|
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()),
|
2018-12-06 20:39:47 +01:00
|
|
|
showNetworkDropdown: () => dispatch(actions.showNetworkDropdown()),
|
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);
|