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