2017-06-29 16:03:11 -07:00
|
|
|
import WalletDecrypt from 'components/WalletDecrypt';
|
2017-09-24 19:06:28 -07:00
|
|
|
import { IWallet } from 'libs/wallet/IWallet';
|
|
|
|
import React from 'react';
|
2017-06-29 16:03:11 -07:00
|
|
|
import { connect } from 'react-redux';
|
2017-09-24 19:06:28 -07:00
|
|
|
import { AppState } from 'reducers';
|
2017-06-26 15:27:55 -07: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;
|
2017-11-29 15:14:57 -08:00
|
|
|
allowReadOnly?: boolean;
|
2017-09-24 19:06:28 -07:00
|
|
|
}
|
|
|
|
interface State {
|
|
|
|
expanded: boolean;
|
|
|
|
}
|
|
|
|
export class UnlockHeader extends React.Component<Props, State> {
|
|
|
|
public state = {
|
2017-12-11 12:17:44 -08:00
|
|
|
expanded: !!this.props.wallet
|
2017-07-01 22:49:06 -07:00
|
|
|
};
|
2017-06-26 15:27:55 -07:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public componentDidUpdate(prevProps: Props) {
|
2017-07-03 20:21:19 -07:00
|
|
|
if (this.props.wallet && this.props.wallet !== prevProps.wallet) {
|
2017-12-11 12:17:44 -08:00
|
|
|
this.setState({ expanded: !this.state.expanded });
|
2017-06-29 16:03:11 -07:00
|
|
|
}
|
2017-07-03 20:21:19 -07:00
|
|
|
}
|
2017-06-29 16:03:11 -07:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public render() {
|
2017-11-29 15:14:57 -08:00
|
|
|
const { title, allowReadOnly } = this.props;
|
2017-07-01 22:49:06 -07:00
|
|
|
return (
|
|
|
|
<article className="collapse-container">
|
2017-10-10 22:04:49 -07:00
|
|
|
<div>
|
|
|
|
<a className="collapse-button" onClick={this.toggleExpanded}>
|
|
|
|
<span>{this.state.expanded ? '-' : '+'}</span>
|
2017-07-01 22:49:06 -07:00
|
|
|
</a>
|
2017-10-10 22:04:49 -07:00
|
|
|
<h1>{title}</h1>
|
2017-07-01 22:49:06 -07:00
|
|
|
</div>
|
2017-12-11 12:17:44 -08:00
|
|
|
<WalletDecrypt hidden={this.state.expanded} allowReadOnly={allowReadOnly} />
|
2017-07-01 22:49:06 -07:00
|
|
|
</article>
|
|
|
|
);
|
|
|
|
}
|
2017-06-26 15:27:55 -07:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public toggleExpanded = () => {
|
2017-07-01 22:49:06 -07:00
|
|
|
this.setState(state => {
|
|
|
|
return { expanded: !state.expanded };
|
|
|
|
});
|
|
|
|
};
|
2017-06-26 15:27:55 -07:00
|
|
|
}
|
2017-06-29 16:03:11 -07:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
function mapStateToProps(state: AppState) {
|
2017-07-03 20:21:19 -07:00
|
|
|
return {
|
2017-07-13 14:02:39 -07:00
|
|
|
wallet: state.wallet.inst
|
2017-07-03 20:21:19 -07:00
|
|
|
};
|
2017-06-29 16:03:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(UnlockHeader);
|