2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
2020-05-15 20:53:52 +02:00
|
|
|
import {
|
|
|
|
getAccountToConnectToActiveTab,
|
|
|
|
getOrderedConnectedAccountsForActiveTab,
|
|
|
|
getPermissionsForActiveTab,
|
|
|
|
getSelectedAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../selectors';
|
|
|
|
import { isExtensionUrl } from '../../helpers/utils/util';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
addPermittedAccount,
|
|
|
|
removePermittedAccount,
|
|
|
|
setSelectedAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../store/actions';
|
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
|
|
|
import ConnectedAccounts from './connected-accounts.component';
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { activeTab } = state;
|
|
|
|
const accountToConnect = getAccountToConnectToActiveTab(state);
|
|
|
|
const connectedAccounts = getOrderedConnectedAccountsForActiveTab(state);
|
|
|
|
const permissions = getPermissionsForActiveTab(state);
|
|
|
|
const selectedAddress = getSelectedAddress(state);
|
2020-05-15 20:53:52 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const isActiveTabExtension = isExtensionUrl(activeTab);
|
2020-05-15 20:53:52 +02:00
|
|
|
return {
|
|
|
|
accountToConnect,
|
2020-05-29 19:12:14 +02:00
|
|
|
isActiveTabExtension,
|
2020-05-15 20:53:52 +02:00
|
|
|
activeTabOrigin: activeTab.origin,
|
|
|
|
connectedAccounts,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2020-05-15 20:53:52 +02:00
|
|
|
permissions,
|
|
|
|
selectedAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
return {
|
2020-11-03 00:41:28 +01:00
|
|
|
addPermittedAccount: (origin, address) =>
|
|
|
|
dispatch(addPermittedAccount(origin, address)),
|
|
|
|
removePermittedAccount: (origin, address) =>
|
|
|
|
dispatch(removePermittedAccount(origin, address)),
|
2020-05-15 20:53:52 +02:00
|
|
|
setSelectedAddress: (address) => dispatch(setSelectedAddress(address)),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { activeTabOrigin } = stateProps;
|
2020-05-15 20:53:52 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
...ownProps,
|
|
|
|
...stateProps,
|
|
|
|
...dispatchProps,
|
2020-11-03 00:41:28 +01:00
|
|
|
connectAccount: (address) =>
|
|
|
|
dispatchProps.addPermittedAccount(activeTabOrigin, address),
|
|
|
|
removePermittedAccount: (address) =>
|
|
|
|
dispatchProps.removePermittedAccount(activeTabOrigin, address),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2020-05-15 20:53:52 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps,
|
|
|
|
mergeProps,
|
2021-02-04 19:15:23 +01:00
|
|
|
)(ConnectedAccounts);
|