on master help sign in
- Refactor CreateGalaxy view
commit953b8575b60ab32d7ad3de6b44af45ea842f2e70 authorChris Johnson <chris@cjohnson.io> dateThu 4 Apr 2019, 12:22 (8 years ago) parentcb0709d
1 file changed+17−87
src/bridge/views/CreateGalaxy.js+17−87
src/bridge/views/CreateGalaxy.js+17−87
@@ -61,54 +61,23 @@ class CreateGalaxy extends React.Component {
6161 galaxyOwner: galaxyOwner,
6262 galaxyName: '',
6363 isAvailable: null,
64− txApproval: false,
65− nonce: '',
66− gasPrice: '5',
67− showGasDetails: false,
68− chainId: '',
69− txInfo: '',
70− gasLimit: '600000',
71− txn: Maybe.Nothing(),
72− stx: Maybe.Nothing(),
7364 }
7465
7566 this.handleAddressInput = this.handleAddressInput.bind(this)
7667 this.handleGalaxyNameInput = this.handleGalaxyNameInput.bind(this)
7768 this.confirmAvailability = this.confirmAvailability.bind(this)
78− this.handleSubmit = this.handleSubmit.bind(this)
79− this.toggleGasDetails = this.toggleGasDetails.bind(this)
69+ this.createUnsignedTxn = this.createUnsignedTxn.bind(this)
70+ this.statelessRef = React.createRef();
8071 }
8172
82− toggleGasDetails() {
83− this.setState({
84− showGasDetails: !this.state.showGasDetails
85− })
86− }
87−
88− componentDidMount() {
89− const { props } = this
90− const addr = props.wallet.matchWith({
91− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
92− Nothing: () => {
93− throw BRIDGE_ERROR.MISSING_WALLET
94− }
95− })
96−
97− // getTxnInfo(props.web3.value, addr).then(txInfo => this.setState(txInfo))
98− props.web3.map(w3 => getTxnInfo(w3, addr)
99− .then(txInfo => this.setState(txInfo))
100− )
101− }
102−
103−
10473 handleGalaxyNameInput = (galaxyName) => {
10574 this.setState({ galaxyName, isAvailable: null })
106− this.clearTransaction()
75+ this.statelessRef.current.clearTxn()
10776 }
10877
10978 handleAddressInput = (galaxyOwner) => {
11079 this.setState({ galaxyOwner })
111− this.clearTransaction()
80+ this.statelessRef.current.clearTxn()
11281 }
11382
11483 createUnsignedTxn = () => {
@@ -133,18 +102,7 @@ class CreateGalaxy extends React.Component {
133102 state.galaxyOwner
134103 )
135104
136− this.setState({ txn: Maybe.Just(txn) })
137− }
138−
139−
140− handleSubmit = () => {
141− const { props, state } = this
142− sendSignedTransaction(props.web3.value, state.stx)
143− .then(sent => {
144− props.setTxnHashCursor(sent)
145− props.popRoute()
146− props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
147− })
105+ return Maybe.Just(txn)
148106 }
149107
150108 confirmAvailability = async () => {
@@ -174,21 +132,16 @@ class CreateGalaxy extends React.Component {
174132 this.setState({ isAvailable: available })
175133 }
176134
177−
178− clearTransaction = () => {
179− this.setState({
180− txApproval: false,
181− txn: Maybe.Nothing(),
182− stx: Maybe.Nothing(),
183− })
184− }
185−
186135 render() {
187136 const { props, state } = this
188137
189138 const validAddress = isValidAddress(state.galaxyOwner)
190139 const validGalaxy = isValidGalaxy(state.galaxyName)
191140
141+ const canGenerate = validAddress === true &&
142+ validGalaxy === true &&
143+ state.isAvailable === true
144+
192145 const esvisible =
193146 props.networkType === NETWORK_NAMES.ROPSTEN ||
194147 props.networkType === NETWORK_NAMES.MAINNET
@@ -259,43 +212,20 @@ class CreateGalaxy extends React.Component {
259212 </Button>
260213
261214 <StatelessTransaction
262− address={state.galaxyOwner}
263− shipName={state.galaxyName}
264− isAvailable={state.isAvailable}
215+ // Upper scope
265216 web3={props.web3}
266217 contracts={props.contracts}
267218 wallet={props.wallet}
268219 walletType={props.walletType}
269220 walletHdPath={props.walletHdPath}
270221 networkType={props.networkType}
271− // Tx
272− txApproval={state.txApproval}
273− txn={state.txn}
274− stx={state.stx}
275− nonce={state.nonce}
276− gasPrice={state.gasPrice}
277− showGasDetails={state.showGasDetails}
278− toggleGasDetails={this.toggleGasDetails}
279− chainId={state.chainId}
280− gasLimit={state.gasLimit}
281− canGenerate={
282− validAddress === true &&
283− validGalaxy === true &&
284− state.isAvailable === true
285− }
286− canSign={Maybe.Just.hasInstance(state.txn)}
287− canSend={Maybe.Just.hasInstance(state.stx)}
288− // Methods
289− createUnsignedTxn={() => this.createUnsignedTxn()}
290− clearTransaction={() => this.clearTransaction()}
291− setApproval={() => this.setState({txApproval: !state.txApproval})}
292− setTxn={txn => this.setState({txn})}
293− setStx={stx => this.setState({stx})}
294− setNonce={nonce => this.setState({nonce})}
295− setChainId={chainId => this.setState({chainId})}
296− setGasPrice={gasPrice => this.setState({gasPrice})}
297− setGasLimit={gasLimit => this.setState({gasLimit})}
298− handleSubmit={this.handleSubmit} />
222+ setTxnHashCursor={props.setTxnHashCursor}
223+ popRoute={props.popRoute}
224+ pushRoute={props.pushRoute}
225+ // Other
226+ ref={this.statelessRef}
227+ canGenerate={canGenerate}
228+ createUnsignedTxn={this.createUnsignedTxn} />
299229
300230 </Col>
301231 </Row>