1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 16:18:07 +01:00
metamask-extension/ui/components/app/modals/export-private-key-modal/export-private-key-modal.container.js
2021-04-28 14:53:59 -05:00

49 lines
1.6 KiB
JavaScript

import { connect } from 'react-redux';
import {
exportAccount,
hideWarning,
showModal,
hideModal,
clearAccountDetails,
} from '../../../../store/actions';
import { getSelectedIdentity } from '../../../../selectors';
import ExportPrivateKeyModal from './export-private-key-modal.component';
function mapStateToPropsFactory() {
let selectedIdentity = null;
return function mapStateToProps(state) {
// We should **not** change the identity displayed here even if it changes from underneath us.
// If we do, we will be showing the user one private key and a **different** address and name.
// Note that the selected identity **will** change from underneath us when we unlock the keyring
// which is the expected behavior that we are side-stepping.
selectedIdentity = selectedIdentity || getSelectedIdentity(state);
return {
warning: state.appState.warning,
privateKey: state.appState.accountDetail.privateKey,
selectedIdentity,
previousModalState: state.appState.modal.previousModalState.name,
};
};
}
function mapDispatchToProps(dispatch) {
return {
exportAccount: (password, address) => {
return dispatch(exportAccount(password, address)).then((res) => {
dispatch(hideWarning());
return res;
});
},
showAccountDetailModal: () =>
dispatch(showModal({ name: 'ACCOUNT_DETAILS' })),
hideModal: () => dispatch(hideModal()),
hideWarning: () => dispatch(hideWarning()),
clearAccountDetails: () => dispatch(clearAccountDetails()),
};
}
export default connect(
mapStateToPropsFactory,
mapDispatchToProps,
)(ExportPrivateKeyModal);