William O'Beirne 371e6e327c Wallet Decrypt Redesign (#677)
* Reorganize files to better match other components.

* Initial UI for wallet buttons.

* Fix leftover rebase conflict.

* Wallet selection, styling, mobile handling.

* Initial work on animations.

* Adjusted animations.

* Adjust wallet unlock forms to be more uniform. Fix view address saying 'unlock'

* Adjust tooltips.

* Fix embedded decrypt components.

* Cover whole sign msg form with decrypt.

* Give deploy contract a better unlock treatment like sign msg.

* Reset decrypt component on hide / show

* Unused var

* Fix tooltip hover.

* Fix hover lift.

* Make spacing better on mobile.

* Back button mobile handling.

* Redesign mobile button icons. Prevent clicking through when clicking on icons.

* TSCheck fixes.

* Attempt to unlock MetaMask onClick, and provide existing flow with notification when unlock fails.

* Get rid of outline.

* Remove decrypt min height. Make view only textarea.

* Add change wallet buttons to deploy contract and sign msg.

* Standardize
2018-01-01 13:46:28 -06:00

124 lines
3.6 KiB
TypeScript

import React, { Component } from 'react';
import { connect } from 'react-redux';
import classnames from 'classnames';
import WalletDecrypt, { DISABLE_WALLETS } from 'components/WalletDecrypt';
import translate from 'translations';
import { showNotification, TShowNotification } from 'actions/notifications';
import { resetWallet, TResetWallet } from 'actions/wallet';
import { ISignedMessage } from 'libs/signing';
import { IFullWallet } from 'libs/wallet';
import { AppState } from 'reducers';
import SignButton from './SignButton';
import { isWalletFullyUnlocked } from 'selectors/wallet';
import './index.scss';
interface Props {
wallet: IFullWallet;
unlocked: boolean;
showNotification: TShowNotification;
resetWallet: TResetWallet;
}
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;
public componentWillUnmount() {
this.props.resetWallet();
}
public render() {
const { wallet, unlocked } = this.props;
const { message, signedMessage } = this.state;
const messageBoxClass = classnames([
'SignMessage-inputBox',
'form-control',
message ? 'is-valid' : 'is-invalid'
]);
return (
<div>
{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>
<SignButton
wallet={wallet}
message={this.state.message}
showNotification={this.props.showNotification}
onSignMessage={this.onSignMessage}
/>
{!!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>
</div>
)}
</div>
) : (
<WalletDecrypt hidden={unlocked} disabledWallets={DISABLE_WALLETS.UNABLE_TO_SIGN} />
)}
</div>
);
}
private handleMessageChange = (e: React.FormEvent<HTMLTextAreaElement>) => {
const message = e.currentTarget.value;
this.setState({ message });
};
private onSignMessage = (signedMessage: ISignedMessage) => {
this.setState({ signedMessage });
};
private changeWallet = () => {
this.props.resetWallet();
};
}
const mapStateToProps = (state: AppState) => ({
wallet: state.wallet.inst,
unlocked: isWalletFullyUnlocked(state)
});
export default connect(mapStateToProps, {
showNotification,
resetWallet
})(SignMessage);