1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 10:30:04 +01:00
metamask-extension/ui/pages/settings/networks-tab/networks-tab-content/networks-tab-content.js
Mark Stacey f765b8c9b9
Refactor provider config selector (#18905)
The provider configuration selector has been renamed from `getProvider`
to `getProviderConfig`, and it has been moved from the selectors module
into the MetaMask slice. A JSDoc description has been added as well.

This refactor was done to make a future PR simpler, and to make this
selector better aligned with best practices.

This relates to #18902
2023-05-01 21:04:43 -02:30

53 lines
1.6 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import NetworksForm from '../networks-form';
import NetworksList from '../networks-list';
import { getProviderConfig } from '../../../../ducks/metamask/metamask';
import {
DEFAULT_ROUTE,
NETWORKS_ROUTE,
} from '../../../../helpers/constants/routes';
const NetworksTabContent = ({
networkDefaultedToProvider,
networkIsSelected,
networksToRender,
selectedNetwork,
shouldRenderNetworkForm,
}) => {
const providerConfig = useSelector(getProviderConfig);
const history = useHistory();
return (
<>
<NetworksList
networkDefaultedToProvider={networkDefaultedToProvider}
networkIsSelected={networkIsSelected}
networksToRender={networksToRender}
selectedNetworkConfigurationId={selectedNetwork.networkConfigurationId}
/>
{shouldRenderNetworkForm ? (
<NetworksForm
isCurrentRpcTarget={providerConfig.rpcUrl === selectedNetwork.rpcUrl}
networksToRender={networksToRender}
selectedNetwork={selectedNetwork}
submitCallback={() => history.push(DEFAULT_ROUTE)}
cancelCallback={() => history.push(NETWORKS_ROUTE)}
/>
) : null}
</>
);
};
NetworksTabContent.propTypes = {
networkDefaultedToProvider: PropTypes.bool,
networkIsSelected: PropTypes.bool,
networksToRender: PropTypes.arrayOf(PropTypes.object).isRequired,
selectedNetwork: PropTypes.object,
shouldRenderNetworkForm: PropTypes.bool.isRequired,
};
export default NetworksTabContent;