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';
|
2017-09-24 19:06:28 -07:00
|
|
|
import { AppState } from 'reducers';
|
2017-12-14 23:52:59 -05:00
|
|
|
import translate from 'translations';
|
|
|
|
import WalletDecrypt from 'components/WalletDecrypt';
|
|
|
|
import { IWallet } from 'libs/wallet/IWallet';
|
|
|
|
import './UnlockHeader.scss';
|
2017-06-27 02:27:55 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
interface Props {
|
2017-10-10 22:04:49 -07:00
|
|
|
title: React.ReactElement<any>;
|
2017-09-24 19:06:28 -07:00
|
|
|
wallet: IWallet;
|
2018-01-01 14:46:28 -05:00
|
|
|
disabledWallets?: string[];
|
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
|
|
|
}
|
|
|
|
export class UnlockHeader extends React.Component<Props, State> {
|
|
|
|
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) {
|
2017-07-03 22:21:19 -05:00
|
|
|
if (this.props.wallet && this.props.wallet !== prevProps.wallet) {
|
2017-12-14 23:52:59 -05:00
|
|
|
this.setState({ isExpanded: !this.state.isExpanded });
|
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-01 14:46:28 -05:00
|
|
|
const { title, wallet, disabledWallets } = 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">
|
|
|
|
<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-01 14:46:28 -05:00
|
|
|
<WalletDecrypt hidden={!this.state.isExpanded} disabledWallets={disabledWallets} />
|
2017-07-02 00:49:06 -05:00
|
|
|
</article>
|
|
|
|
);
|
|
|
|
}
|
2017-06-27 02:27:55 +04:00
|
|
|
|
2017-12-14 23:52:59 -05:00
|
|
|
public toggleisExpanded = () => {
|
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);
|