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