add postToWhisper

This commit is contained in:
Barry Gitarts 2018-11-23 17:38:15 -05:00
parent f06d4d62ca
commit 4daa01aaf4
1 changed files with 65 additions and 53 deletions

View File

@ -1,7 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { CopyToClipboard } from 'react-copy-to-clipboard'; import { CopyToClipboard } from 'react-copy-to-clipboard';
import translate, { translateRaw } from 'translations'; import translate, { translateRaw } from 'translations';
import { ISignedMessage } from 'libs/signing'; import { ISignedMessage } from 'libs/signing';
import { IFullWallet } from 'libs/wallet'; import { IFullWallet } from 'libs/wallet';
@ -31,6 +30,16 @@ const initialState: State = {
message: Principles message: Principles
}; };
const postToWhisper = signedMessage => {
const msg = JSON.stringify(signedMessage, null, 2);
window.opener.postMessage(
{type: 'whisperMsg', msg, channel: 'mytest' },
'*'
);
}
const messagePlaceholder = translateRaw('SIGN_MSG_PLACEHOLDER'); const messagePlaceholder = translateRaw('SIGN_MSG_PLACEHOLDER');
export class SignMessage extends Component<Props, State> { export class SignMessage extends Component<Props, State> {
@ -48,63 +57,66 @@ export class SignMessage extends Component<Props, State> {
return ( return (
<div> <div>
{unlocked ? ( {unlocked ? (
<div className="Tab-content-pane"> <div className="Tab-content-pane">
<button <button
className="SignMessage-reset btn btn-default btn-sm" className="SignMessage-reset btn btn-default btn-sm"
onClick={this.changeWallet} onClick={this.changeWallet}
> >
<i className="fa fa-refresh" /> <i className="fa fa-refresh" />
{translate('CHANGE_WALLET')} {translate('CHANGE_WALLET')}
</button> </button>
<div className="input-group-wrapper Deploy-field"> <div className="input-group-wrapper Deploy-field">
<label className="input-group"> <label className="input-group">
<div className="input-group-header">{translate('MSG_MESSAGE')}</div> <div className="input-group-header">{translate('MSG_MESSAGE')}</div>
<TextArea <TextArea
isValid={!!message} isValid={!!message}
className="SignMessage-inputBox" className="SignMessage-inputBox"
placeholder={messagePlaceholder} placeholder={messagePlaceholder}
value={message} value={message}
onChange={this.handleMessageChange} onChange={this.handleMessageChange}
/> />
</label> </label>
<div className="SignMessage-help">{translate('MSG_INFO2')}</div> <div className="SignMessage-help">{translate('MSG_INFO2')}</div>
</div> </div>
<div> <div>
<SignButton <SignButton
message={this.state.message} message={this.state.message}
signMessageRequested={this.props.signMessageRequested} signMessageRequested={this.props.signMessageRequested}
/> />
</div> </div>
{signedMessage && ( {signedMessage && (
<div className="input-group-wrapper SignMessage-inputBox"> <div className="input-group-wrapper SignMessage-inputBox">
<CopyToClipboard <CopyToClipboard
text={JSON.stringify(signedMessage, null, 2)} text={JSON.stringify(signedMessage, null, 2)}
onCopy={() => { onCopy={() => {
this.setState({ copied: true }); this.setState({ copied: true });
}} }}
>
<label
className="input-group"
style={{ color: this.state.copied ? 'green' : null }}
> >
<div className="input-group-header"> <label
{translate('MSG_SIGNATURE')} (Click or touch to copy to clipboard) className="input-group"
</div> style={{ color: this.state.copied ? 'green' : null }}
<CodeBlock
className="SignMessage-inputBox"
color={this.state.copied ? 'green' : null}
> >
{JSON.stringify(signedMessage, null, 2)} <div className="input-group-header">
</CodeBlock> {translate('MSG_SIGNATURE')} (Click or touch to copy to clipboard)
</label> </div>
</CopyToClipboard> <CodeBlock
</div> className="SignMessage-inputBox"
)} color={this.state.copied ? 'green' : null}
</div> >
{JSON.stringify(signedMessage, null, 2)}
</CodeBlock>
</label>
</CopyToClipboard>
<button onClick={() => { postToWhisper(signedMessage) }}>
Broadcast to Status
</button>
</div>
)}
</div>
) : ( ) : (
<WalletDecrypt hidden={unlocked} disabledWallets={DISABLE_WALLETS.UNABLE_TO_SIGN} /> <WalletDecrypt hidden={unlocked} disabledWallets={DISABLE_WALLETS.UNABLE_TO_SIGN} />
)} )}
</div> </div>
); );