-
-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create MVP of broadcast TX component * add broadcastTx to routes and tab options * Update BroadcastTx path to /pushTx * - add sanitizeHex and padLeftEven functions from V3 * - Move decodeTransaction logic out of ConfirmationModal. - Add from key to getTransactionFields * Simplify ConfirmationModal: 1. Move business logic out of component (decodeTransaction). 2. Don't pass node props when Component is already smart. Map from state instead. 3. Pass walletAddress instead of the entire wallet object to component as prop. 4. Handle * - Don't map node state (child component grabs from state) - implement and call setWalletAddressOnUpdate * correct tab to path. * 1. Integrate Confirmation Modal 2. Validate signedTx input and disable Send Transaction button when invalid * disable tslint error. EthTx expect a Data type object, but a string is passed. However, tx object is created as expected. Need to investigate * adjust type definition to match allowed string input. Remove tslint disable * fix tslint errors * add textarea valid/invalid stlying based on disabled status * remove unused imports * cleanup / address PR comments * Address PR comments
- Loading branch information
Showing
9 changed files
with
252 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
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'; | ||
import classnames from 'classnames'; | ||
|
||
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) { | ||
if (!this.state.disabled) { | ||
this.setState({ disabled: true }); | ||
} | ||
} | ||
} | ||
|
||
public componentDidUpdate() { | ||
this.ensureValidSignedTxInputOnUpdate(); | ||
} | ||
|
||
public render() { | ||
const { signedTx, disabled, showConfirmationModal } = this.state; | ||
|
||
const inputClasses = classnames({ | ||
'form-control': true, | ||
'is-valid': !disabled, | ||
'is-invalid': disabled | ||
}); | ||
|
||
return ( | ||
<TabSection> | ||
<div className="Tab-content-pane row block text-center"> | ||
<div className="col-md-6"> | ||
<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={inputClasses} | ||
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%' | ||
}} | ||
> | ||
{signedTx && <QRCode data={signedTx} />} | ||
</div> | ||
</div> | ||
</div> | ||
{showConfirmationModal && ( | ||
<ConfirmationModal | ||
signedTx={signedTx} | ||
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 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.