2017-10-30 19:10:25 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import classnames from 'classnames';
|
2018-01-01 19:46:28 +00:00
|
|
|
import WalletDecrypt, { DISABLE_WALLETS } from 'components/WalletDecrypt';
|
2017-10-30 19:10:25 +00:00
|
|
|
import translate from 'translations';
|
|
|
|
import { showNotification, TShowNotification } from 'actions/notifications';
|
2018-01-01 19:46:28 +00:00
|
|
|
import { resetWallet, TResetWallet } from 'actions/wallet';
|
2017-10-30 19:10:25 +00:00
|
|
|
import { ISignedMessage } from 'libs/signing';
|
2017-11-29 23:14:57 +00:00
|
|
|
import { IFullWallet } from 'libs/wallet';
|
2017-12-11 20:17:44 +00:00
|
|
|
import { AppState } from 'reducers';
|
2017-11-29 23:14:57 +00:00
|
|
|
import SignButton from './SignButton';
|
2017-12-11 20:17:44 +00:00
|
|
|
import { isWalletFullyUnlocked } from 'selectors/wallet';
|
2017-10-30 19:10:25 +00:00
|
|
|
import './index.scss';
|
|
|
|
|
|
|
|
interface Props {
|
2017-12-11 20:17:44 +00:00
|
|
|
wallet: IFullWallet;
|
|
|
|
unlocked: boolean;
|
2018-01-01 19:46:28 +00:00
|
|
|
showNotification: TShowNotification;
|
|
|
|
resetWallet: TResetWallet;
|
2017-10-30 19:10:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
message: string;
|
|
|
|
signedMessage: ISignedMessage | null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const initialState: State = {
|
|
|
|
message: '',
|
|
|
|
signedMessage: null
|
|
|
|
};
|
|
|
|
|
|
|
|
const messagePlaceholder =
|
|
|
|
'This is a sweet message that you are signing to prove that you own the address you say you own.';
|
|
|
|
|
|
|
|
export class SignMessage extends Component<Props, State> {
|
|
|
|
public state: State = initialState;
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
public componentWillUnmount() {
|
|
|
|
this.props.resetWallet();
|
|
|
|
}
|
|
|
|
|
2017-10-30 19:10:25 +00:00
|
|
|
public render() {
|
2017-12-11 20:17:44 +00:00
|
|
|
const { wallet, unlocked } = this.props;
|
2017-10-30 19:10:25 +00:00
|
|
|
const { message, signedMessage } = this.state;
|
|
|
|
const messageBoxClass = classnames([
|
|
|
|
'SignMessage-inputBox',
|
|
|
|
'form-control',
|
|
|
|
message ? 'is-valid' : 'is-invalid'
|
|
|
|
]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2018-01-01 19:46:28 +00:00
|
|
|
{unlocked ? (
|
|
|
|
<div className="Tab-content-pane">
|
|
|
|
<h3 className="SignMessage-label">{translate('MSG_message')}</h3>
|
|
|
|
<button
|
|
|
|
className="SignMessage-reset btn btn-default btn-sm"
|
|
|
|
onClick={this.changeWallet}
|
|
|
|
>
|
|
|
|
<i className="fa fa-refresh" />
|
|
|
|
{translate('Change Wallet')}
|
|
|
|
</button>
|
|
|
|
<div className="form-group">
|
|
|
|
<textarea
|
|
|
|
className={messageBoxClass}
|
|
|
|
placeholder={messagePlaceholder}
|
|
|
|
value={message}
|
|
|
|
onChange={this.handleMessageChange}
|
|
|
|
/>
|
|
|
|
<div className="SignMessage-help">{translate('MSG_info2')}</div>
|
|
|
|
</div>
|
2017-10-30 19:10:25 +00:00
|
|
|
|
2017-12-11 20:17:44 +00:00
|
|
|
<SignButton
|
|
|
|
wallet={wallet}
|
|
|
|
message={this.state.message}
|
|
|
|
showNotification={this.props.showNotification}
|
|
|
|
onSignMessage={this.onSignMessage}
|
|
|
|
/>
|
2017-10-30 19:10:25 +00:00
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
{!!signedMessage && (
|
|
|
|
<div>
|
|
|
|
<h4>{translate('MSG_signature')}</h4>
|
|
|
|
<div className="form-group">
|
|
|
|
<textarea
|
|
|
|
className="SignMessage-inputBox form-control"
|
|
|
|
value={JSON.stringify(signedMessage, null, 2)}
|
|
|
|
disabled={true}
|
|
|
|
onChange={this.handleMessageChange}
|
|
|
|
/>
|
|
|
|
</div>
|
2017-10-30 19:10:25 +00:00
|
|
|
</div>
|
2018-01-01 19:46:28 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<WalletDecrypt hidden={unlocked} disabledWallets={DISABLE_WALLETS.UNABLE_TO_SIGN} />
|
|
|
|
)}
|
2017-10-30 19:10:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleMessageChange = (e: React.FormEvent<HTMLTextAreaElement>) => {
|
|
|
|
const message = e.currentTarget.value;
|
|
|
|
this.setState({ message });
|
|
|
|
};
|
|
|
|
|
2017-11-29 23:14:57 +00:00
|
|
|
private onSignMessage = (signedMessage: ISignedMessage) => {
|
|
|
|
this.setState({ signedMessage });
|
2017-10-30 19:10:25 +00:00
|
|
|
};
|
2018-01-01 19:46:28 +00:00
|
|
|
|
|
|
|
private changeWallet = () => {
|
|
|
|
this.props.resetWallet();
|
|
|
|
};
|
2017-10-30 19:10:25 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 20:17:44 +00:00
|
|
|
const mapStateToProps = (state: AppState) => ({
|
|
|
|
wallet: state.wallet.inst,
|
|
|
|
unlocked: isWalletFullyUnlocked(state)
|
|
|
|
});
|
|
|
|
|
2018-01-01 19:46:28 +00:00
|
|
|
export default connect(mapStateToProps, {
|
|
|
|
showNotification,
|
|
|
|
resetWallet
|
|
|
|
})(SignMessage);
|