You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.4 KiB
114 lines
3.4 KiB
4 years ago
|
import { compose } from 'redux';
|
||
|
import { connect } from 'react-redux';
|
||
|
import { withRouter } from 'react-router-dom';
|
||
6 years ago
|
import {
|
||
|
setSelectedSettingsRpcUrl,
|
||
|
updateAndSetCustomRpc,
|
||
|
displayWarning,
|
||
|
setNetworksTabAddMode,
|
||
|
editRpc,
|
||
5 years ago
|
showModal,
|
||
4 years ago
|
} from '../../../store/actions';
|
||
|
import { NETWORKS_FORM_ROUTE } from '../../../helpers/constants/routes';
|
||
4 years ago
|
import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app';
|
||
|
import { NETWORK_TYPE_RPC } from '../../../../shared/constants/network';
|
||
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
|
||
4 years ago
|
import NetworksTab from './networks-tab.component';
|
||
|
import { defaultNetworksData } from './networks-tab.constants';
|
||
5 years ago
|
|
||
4 years ago
|
const defaultNetworks = defaultNetworksData.map((network) => ({
|
||
|
...network,
|
||
|
viewOnly: true,
|
||
4 years ago
|
}));
|
||
6 years ago
|
|
||
4 years ago
|
const mapStateToProps = (state, ownProps) => {
|
||
4 years ago
|
const {
|
||
|
location: { pathname },
|
||
4 years ago
|
} = ownProps;
|
||
4 years ago
|
|
||
4 years ago
|
const environmentType = getEnvironmentType();
|
||
|
const isFullScreen = environmentType === ENVIRONMENT_TYPE_FULLSCREEN;
|
||
4 years ago
|
const shouldRenderNetworkForm =
|
||
4 years ago
|
isFullScreen || Boolean(pathname.match(NETWORKS_FORM_ROUTE));
|
||
4 years ago
|
|
||
4 years ago
|
const { frequentRpcListDetail, provider } = state.metamask;
|
||
|
const { networksTabSelectedRpcUrl, networksTabIsInAddMode } = state.appState;
|
||
6 years ago
|
|
||
5 years ago
|
const frequentRpcNetworkListDetails = frequentRpcListDetail.map((rpc) => {
|
||
6 years ago
|
return {
|
||
|
label: rpc.nickname,
|
||
|
iconColor: '#6A737D',
|
||
4 years ago
|
providerType: NETWORK_TYPE_RPC,
|
||
6 years ago
|
rpcUrl: rpc.rpcUrl,
|
||
|
chainId: rpc.chainId,
|
||
|
ticker: rpc.ticker,
|
||
4 years ago
|
blockExplorerUrl: rpc.rpcPrefs?.blockExplorerUrl || '',
|
||
4 years ago
|
};
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
const networksToRender = [
|
||
|
...defaultNetworks,
|
||
|
...frequentRpcNetworkListDetails,
|
||
4 years ago
|
];
|
||
4 years ago
|
let selectedNetwork =
|
||
|
networksToRender.find(
|
||
|
(network) => network.rpcUrl === networksTabSelectedRpcUrl,
|
||
4 years ago
|
) || {};
|
||
|
const networkIsSelected = Boolean(selectedNetwork.rpcUrl);
|
||
6 years ago
|
|
||
4 years ago
|
let networkDefaultedToProvider = false;
|
||
6 years ago
|
if (!networkIsSelected && !networksTabIsInAddMode) {
|
||
4 years ago
|
selectedNetwork =
|
||
|
networksToRender.find((network) => {
|
||
|
return (
|
||
|
network.rpcUrl === provider.rpcUrl ||
|
||
4 years ago
|
(network.providerType !== NETWORK_TYPE_RPC &&
|
||
4 years ago
|
network.providerType === provider.type)
|
||
4 years ago
|
);
|
||
|
}) || {};
|
||
|
networkDefaultedToProvider = true;
|
||
6 years ago
|
}
|
||
|
|
||
|
return {
|
||
|
selectedNetwork,
|
||
|
networksToRender,
|
||
|
networkIsSelected,
|
||
|
networksTabIsInAddMode,
|
||
|
providerType: provider.type,
|
||
4 years ago
|
providerUrl: provider.rpcUrl,
|
||
6 years ago
|
networkDefaultedToProvider,
|
||
4 years ago
|
isFullScreen,
|
||
|
shouldRenderNetworkForm,
|
||
4 years ago
|
};
|
||
|
};
|
||
6 years ago
|
|
||
5 years ago
|
const mapDispatchToProps = (dispatch) => {
|
||
6 years ago
|
return {
|
||
4 years ago
|
setSelectedSettingsRpcUrl: (newRpcUrl) =>
|
||
|
dispatch(setSelectedSettingsRpcUrl(newRpcUrl)),
|
||
6 years ago
|
setRpcTarget: (newRpc, chainId, ticker, nickname, rpcPrefs) => {
|
||
4 years ago
|
return dispatch(
|
||
|
updateAndSetCustomRpc(newRpc, chainId, ticker, nickname, rpcPrefs),
|
||
4 years ago
|
);
|
||
6 years ago
|
},
|
||
5 years ago
|
showConfirmDeleteNetworkModal: ({ target, onConfirm }) => {
|
||
4 years ago
|
return dispatch(
|
||
|
showModal({ name: 'CONFIRM_DELETE_NETWORK', target, onConfirm }),
|
||
4 years ago
|
);
|
||
6 years ago
|
},
|
||
5 years ago
|
displayWarning: (warning) => dispatch(displayWarning(warning)),
|
||
4 years ago
|
setNetworksTabAddMode: (isInAddMode) =>
|
||
|
dispatch(setNetworksTabAddMode(isInAddMode)),
|
||
6 years ago
|
editRpc: (oldRpc, newRpc, chainId, ticker, nickname, rpcPrefs) => {
|
||
4 years ago
|
return dispatch(
|
||
|
editRpc(oldRpc, newRpc, chainId, ticker, nickname, rpcPrefs),
|
||
4 years ago
|
);
|
||
6 years ago
|
},
|
||
4 years ago
|
};
|
||
|
};
|
||
6 years ago
|
|
||
|
export default compose(
|
||
|
withRouter,
|
||
4 years ago
|
connect(mapStateToProps, mapDispatchToProps),
|
||
4 years ago
|
)(NetworksTab);
|