2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
exportAccount,
|
|
|
|
hideWarning,
|
|
|
|
showModal,
|
|
|
|
hideModal,
|
|
|
|
clearAccountDetails,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../../store/actions';
|
|
|
|
import { getSelectedIdentity } from '../../../../selectors';
|
|
|
|
import ExportPrivateKeyModal from './export-private-key-modal.component';
|
2019-11-27 16:06:31 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapStateToPropsFactory() {
|
2021-02-04 19:15:23 +01:00
|
|
|
let selectedIdentity = null;
|
2020-11-03 00:41:28 +01:00
|
|
|
return function mapStateToProps(state) {
|
2019-11-27 16:06:31 +01:00
|
|
|
// 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.
|
2021-02-04 19:15:23 +01:00
|
|
|
selectedIdentity = selectedIdentity || getSelectedIdentity(state);
|
2019-11-27 16:06:31 +01:00
|
|
|
return {
|
|
|
|
warning: state.appState.warning,
|
|
|
|
privateKey: state.appState.accountDetail.privateKey,
|
|
|
|
selectedIdentity,
|
|
|
|
previousModalState: state.appState.modal.previousModalState.name,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2019-11-27 16:06:31 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapDispatchToProps(dispatch) {
|
2019-11-27 16:06:31 +01:00
|
|
|
return {
|
|
|
|
exportAccount: (password, address) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
return dispatch(exportAccount(password, address)).then((res) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideWarning());
|
|
|
|
return res;
|
|
|
|
});
|
2019-11-27 16:06:31 +01:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
showAccountDetailModal: () =>
|
|
|
|
dispatch(showModal({ name: 'ACCOUNT_DETAILS' })),
|
2019-11-27 16:06:31 +01:00
|
|
|
hideModal: () => dispatch(hideModal()),
|
2020-08-27 01:19:41 +02:00
|
|
|
hideWarning: () => dispatch(hideWarning()),
|
2020-08-15 01:08:26 +02:00
|
|
|
clearAccountDetails: () => dispatch(clearAccountDetails()),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-27 16:06:31 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default connect(
|
|
|
|
mapStateToPropsFactory,
|
|
|
|
mapDispatchToProps,
|
2021-02-04 19:15:23 +01:00
|
|
|
)(ExportPrivateKeyModal);
|