2017-09-24 19:06:28 -07:00
|
|
|
import React from 'react';
|
2017-06-30 03:03:11 +04:00
|
|
|
import { connect } from 'react-redux';
|
2018-06-17 20:53:00 -05:00
|
|
|
|
2018-03-21 23:50:25 -04:00
|
|
|
import translate from 'translations';
|
2017-12-14 23:52:59 -05:00
|
|
|
import { IWallet } from 'libs/wallet/IWallet';
|
2018-06-17 20:53:00 -05:00
|
|
|
import { AppState } from 'features/reducers';
|
2018-02-06 23:39:24 -05:00
|
|
|
import closeIcon from 'assets/images/close.svg';
|
2018-06-17 20:53:00 -05:00
|
|
|
import WalletDecrypt, { DisabledWallets } from 'components/WalletDecrypt';
|
2017-12-14 23:52:59 -05:00
|
|
|
import './UnlockHeader.scss';
|
2017-06-27 02:27:55 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
interface Props {
|
2018-03-22 14:30:51 -04:00
|
|
|
title?: string;
|
2017-09-24 19:06:28 -07:00
|
|
|
wallet: IWallet;
|
2018-01-26 15:08:39 -05:00
|
|
|
disabledWallets?: DisabledWallets;
|
2018-01-24 17:23:20 -05:00
|
|
|
showGenerateLink?: boolean;
|
2017-09-24 19:06:28 -07:00
|
|
|
}
|
2018-01-20 14:06:28 -06:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
interface State {
|
2017-12-14 23:52:59 -05:00
|
|
|
isExpanded: boolean;
|
2017-09-24 19:06:28 -07:00
|
|
|
}
|
2018-01-20 14:06:28 -06:00
|
|
|
|
|
|
|
export class UnlockHeader extends React.PureComponent<Props, State> {
|
2017-09-24 19:06:28 -07:00
|
|
|
public state = {
|
2017-12-14 23:52:59 -05:00
|
|
|
isExpanded: !this.props.wallet
|
2017-07-02 00:49:06 -05:00
|
|
|
};
|
2017-06-27 02:27:55 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public componentDidUpdate(prevProps: Props) {
|
2018-01-15 00:27:26 -06:00
|
|
|
if (this.props.wallet !== prevProps.wallet) {
|
2018-04-05 17:23:15 -04:00
|
|
|
this.setState({ isExpanded: !this.props.wallet });
|
2017-06-30 03:03:11 +04:00
|
|
|
}
|
2017-07-03 22:21:19 -05:00
|
|
|
}
|
2017-06-30 03:03:11 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public render() {
|
2018-01-24 17:23:20 -05:00
|
|
|
const { title, wallet, disabledWallets, showGenerateLink } = this.props;
|
2017-12-14 23:52:59 -05:00
|
|
|
const { isExpanded } = this.state;
|
|
|
|
|
2017-07-02 00:49:06 -05:00
|
|
|
return (
|
2017-12-14 23:52:59 -05:00
|
|
|
<article className="UnlockHeader">
|
2018-03-22 14:30:51 -04:00
|
|
|
{title && <h1 className="UnlockHeader-title">{title}</h1>}
|
2017-12-14 23:52:59 -05:00
|
|
|
{wallet &&
|
|
|
|
!isExpanded && (
|
|
|
|
<button
|
|
|
|
className="UnlockHeader-open btn btn-default btn-smr"
|
|
|
|
onClick={this.toggleisExpanded}
|
|
|
|
>
|
|
|
|
<span>
|
|
|
|
<span className="hidden-xs UnlockHeader-open-text">
|
2018-03-21 23:50:25 -04:00
|
|
|
{translate('CHANGE_WALLET')}
|
2017-12-14 23:52:59 -05:00
|
|
|
</span>
|
|
|
|
<i className="fa fa-refresh" />
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{wallet &&
|
|
|
|
isExpanded && (
|
|
|
|
<button className="UnlockHeader-close" onClick={this.toggleisExpanded}>
|
2018-02-06 23:39:24 -05:00
|
|
|
<img src={closeIcon} alt="close" />
|
2017-12-14 23:52:59 -05:00
|
|
|
</button>
|
|
|
|
)}
|
2018-01-24 17:23:20 -05:00
|
|
|
<WalletDecrypt
|
|
|
|
hidden={!this.state.isExpanded}
|
|
|
|
disabledWallets={disabledWallets}
|
|
|
|
showGenerateLink={showGenerateLink}
|
|
|
|
/>
|
2017-07-02 00:49:06 -05:00
|
|
|
</article>
|
|
|
|
);
|
|
|
|
}
|
2017-06-27 02:27:55 +04:00
|
|
|
|
2018-01-20 14:06:28 -06:00
|
|
|
public toggleisExpanded = (_: React.FormEvent<HTMLButtonElement>) => {
|
2017-07-02 00:49:06 -05:00
|
|
|
this.setState(state => {
|
2017-12-14 23:52:59 -05:00
|
|
|
return { isExpanded: !state.isExpanded };
|
2017-07-02 00:49:06 -05:00
|
|
|
});
|
|
|
|
};
|
2017-06-27 02:27:55 +04:00
|
|
|
}
|
2017-06-30 03:03:11 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
function mapStateToProps(state: AppState) {
|
2017-07-03 22:21:19 -05:00
|
|
|
return {
|
2017-07-14 01:02:39 +04:00
|
|
|
wallet: state.wallet.inst
|
2017-07-03 22:21:19 -05:00
|
|
|
};
|
2017-06-30 03:03:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(UnlockHeader);
|