-
-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broadcast Tx #304
Broadcast Tx #304
Changes from 18 commits
8fa842a
c11e450
90062e1
5e904fc
3e09520
4bb8bc5
a7ad257
296f697
5ed10c4
42c5e43
4b0d936
c88aa9f
b902792
d70aed9
c9d5589
86a1066
661fa10
904b5c6
8ae85e7
70fe6cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@import "common/sass/variables"; | ||
|
||
.BroadcastTx { | ||
&-title { | ||
margin: $space auto $space * 2.5; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { AppState } from 'reducers'; | ||
import TabSection from 'containers/TabSection'; | ||
import { translateRaw } from 'translations'; | ||
import { broadcastTx as dBroadcastTx, TBroadcastTx } from 'actions/wallet'; | ||
import { QRCode } from 'components/ui'; | ||
import './index.scss'; | ||
import { | ||
BroadcastTransactionStatus, | ||
getTransactionFields | ||
} from 'libs/transaction'; | ||
import EthTx from 'ethereumjs-tx'; | ||
import { ConfirmationModal } from 'containers/Tabs/SendTransaction/components'; | ||
|
||
interface Props { | ||
broadcastTx: TBroadcastTx; | ||
transactions: BroadcastTransactionStatus[]; | ||
} | ||
|
||
interface State { | ||
signedTx: string; | ||
showConfirmationModal: boolean; | ||
disabled: boolean; | ||
} | ||
|
||
const initialState: State = { | ||
showConfirmationModal: false, | ||
signedTx: '', | ||
disabled: true | ||
}; | ||
|
||
class BroadcastTx extends Component<Props, State> { | ||
public state = initialState; | ||
|
||
public ensureValidSignedTxInputOnUpdate() { | ||
try { | ||
const tx = new EthTx(this.state.signedTx); | ||
getTransactionFields(tx); | ||
if (this.state.disabled) { | ||
this.setState({ disabled: false }); | ||
} | ||
} catch (e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TS lets you do |
||
if (!this.state.disabled) { | ||
this.setState({ disabled: true }); | ||
} | ||
} | ||
} | ||
|
||
public componentDidUpdate() { | ||
this.ensureValidSignedTxInputOnUpdate(); | ||
} | ||
|
||
public render() { | ||
const { signedTx, disabled } = this.state; | ||
return ( | ||
<TabSection> | ||
<div className="text-center"> | ||
<div className="Tab-content-pane row block"> | ||
<div className="col-md-6"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can these |
||
<div className="col-md-12 BroadcastTx-title"> | ||
<h2>Broadcast Signed Transaction</h2> | ||
</div> | ||
<p> | ||
Paste a signed transaction and press the "SEND TRANSACTION" | ||
button. | ||
</p> | ||
<label>{translateRaw('SEND_signed')}</label> | ||
<textarea | ||
className={`form-control | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the |
||
${disabled ? 'is-invalid' : 'is-valid'}`} | ||
rows={7} | ||
value={signedTx} | ||
onChange={this.handleChange} | ||
/> | ||
<button | ||
className="btn btn-primary" | ||
disabled={disabled || signedTx === ''} | ||
onClick={this.handleBroadcastTx} | ||
> | ||
{translateRaw('SEND_trans')} | ||
</button> | ||
</div> | ||
|
||
<div className="col-md-6" style={{ marginTop: '70px' }}> | ||
<div | ||
className="qr-code text-center" | ||
style={{ | ||
maxWidth: '15rem', | ||
margin: '1rem auto', | ||
width: '100%' | ||
}} | ||
> | ||
{this.state.signedTx && <QRCode data={this.state.signedTx} />} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the destructured |
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{this.state.showConfirmationModal && ( | ||
<ConfirmationModal | ||
signedTx={this.state.signedTx} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
onClose={this.handleClose} | ||
onConfirm={this.handleConfirm} | ||
/> | ||
)} | ||
</TabSection> | ||
); | ||
} | ||
|
||
public handleClose = () => { | ||
this.setState({ showConfirmationModal: false }); | ||
}; | ||
|
||
public handleBroadcastTx = () => { | ||
this.setState({ showConfirmationModal: true }); | ||
}; | ||
|
||
public handleConfirm = () => { | ||
this.props.broadcastTx(this.state.signedTx); | ||
}; | ||
|
||
protected handleChange = event => { | ||
this.setState({ signedTx: event.target.value }); | ||
}; | ||
} | ||
|
||
function mapStateToProps(state: AppState) { | ||
return { | ||
transactions: state.wallet.transactions | ||
}; | ||
} | ||
|
||
export default connect(mapStateToProps, { broadcastTx: dBroadcastTx })( | ||
BroadcastTx | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason for naming this
pushTx
instead of the format ofbroadcast-tx
like thesend-transaction
route?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, to match etherscan.