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';
|
2017-09-25 02:06:28 +00:00
|
|
|
import { AppState } from 'reducers';
|
2018-01-20 20:06:28 +00:00
|
|
|
import translate, { TranslateType } from 'translations';
|
2018-01-26 20:08:39 +00:00
|
|
|
import WalletDecrypt, { DisabledWallets } from 'components/WalletDecrypt';
|
2017-12-15 04:52:59 +00:00
|
|
|
import { IWallet } from 'libs/wallet/IWallet';
|
|
|
|
import './UnlockHeader.scss';
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
interface Props {
|
2018-01-20 20:06:28 +00:00
|
|
|
title: TranslateType;
|
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) {
|
2017-12-15 04:52:59 +00:00
|
|
|
this.setState({ isExpanded: !this.state.isExpanded });
|
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">
|
|
|
|
<h1 className="UnlockHeader-title">{title}</h1>
|
|
|
|
{wallet &&
|
|
|
|
!isExpanded && (
|
|
|
|
<button
|
|
|
|
className="UnlockHeader-open btn btn-default btn-smr"
|
|
|
|
onClick={this.toggleisExpanded}
|
|
|
|
>
|
|
|
|
<span>
|
|
|
|
<span className="hidden-xs UnlockHeader-open-text">
|
|
|
|
{translate('Change Wallet')}
|
|
|
|
</span>
|
|
|
|
<i className="fa fa-refresh" />
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{wallet &&
|
|
|
|
isExpanded && (
|
|
|
|
<button className="UnlockHeader-close" onClick={this.toggleisExpanded}>
|
|
|
|
<i className="fa fa-times" />
|
|
|
|
</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);
|