on master help sign in
- Refactor CreateGalaxy view
953b857Chris Johnson
src/bridge/views/CreateGalaxy.js+17−87
@@ -61,54 +61,23 @@ class CreateGalaxy extends React.Component {
61 galaxyOwner: galaxyOwner,
61 galaxyOwner: galaxyOwner,
62 galaxyName: '',
62 galaxyName: '',
63 isAvailable: null,
63 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(),
73 }
64 }
74
65
75 this.handleAddressInput = this.handleAddressInput.bind(this)
66 this.handleAddressInput = this.handleAddressInput.bind(this)
76 this.handleGalaxyNameInput = this.handleGalaxyNameInput.bind(this)
67 this.handleGalaxyNameInput = this.handleGalaxyNameInput.bind(this)
77 this.confirmAvailability = this.confirmAvailability.bind(this)
68 this.confirmAvailability = this.confirmAvailability.bind(this)
78− this.handleSubmit = this.handleSubmit.bind(this)
69+ this.createUnsignedTxn = this.createUnsignedTxn.bind(this)
79− this.toggleGasDetails = this.toggleGasDetails.bind(this)
70+ this.statelessRef = React.createRef();
80 }
71 }
81
72
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−
104 handleGalaxyNameInput = (galaxyName) => {
73 handleGalaxyNameInput = (galaxyName) => {
105 this.setState({ galaxyName, isAvailable: null })
74 this.setState({ galaxyName, isAvailable: null })
106− this.clearTransaction()
75+ this.statelessRef.current.clearTxn()
107 }
76 }
108
77
109 handleAddressInput = (galaxyOwner) => {
78 handleAddressInput = (galaxyOwner) => {
110 this.setState({ galaxyOwner })
79 this.setState({ galaxyOwner })
111− this.clearTransaction()
80+ this.statelessRef.current.clearTxn()
112 }
81 }
113
82
114 createUnsignedTxn = () => {
83 createUnsignedTxn = () => {
@@ -133,18 +102,7 @@ class CreateGalaxy extends React.Component {
133 state.galaxyOwner
102 state.galaxyOwner
134 )
103 )
135
104
136− this.setState({ txn: Maybe.Just(txn) })
105+ return 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− })
148 }
106 }
149
107
150 confirmAvailability = async () => {
108 confirmAvailability = async () => {
@@ -174,21 +132,16 @@ class CreateGalaxy extends React.Component {
174 this.setState({ isAvailable: available })
132 this.setState({ isAvailable: available })
175 }
133 }
176
134
177−
178− clearTransaction = () => {
179− this.setState({
180− txApproval: false,
181− txn: Maybe.Nothing(),
182− stx: Maybe.Nothing(),
183− })
184− }
185−
186 render() {
135 render() {
187 const { props, state } = this
136 const { props, state } = this
188
137
189 const validAddress = isValidAddress(state.galaxyOwner)
138 const validAddress = isValidAddress(state.galaxyOwner)
190 const validGalaxy = isValidGalaxy(state.galaxyName)
139 const validGalaxy = isValidGalaxy(state.galaxyName)
191
140
141+ const canGenerate = validAddress === true &&
142+ validGalaxy === true &&
143+ state.isAvailable === true
144+
192 const esvisible =
145 const esvisible =
193 props.networkType === NETWORK_NAMES.ROPSTEN ||
146 props.networkType === NETWORK_NAMES.ROPSTEN ||
194 props.networkType === NETWORK_NAMES.MAINNET
147 props.networkType === NETWORK_NAMES.MAINNET
@@ -259,43 +212,20 @@ class CreateGalaxy extends React.Component {
259 </Button>
212 </Button>
260
213
261 <StatelessTransaction
214 <StatelessTransaction
262− address={state.galaxyOwner}
215+ // Upper scope
263− shipName={state.galaxyName}
264− isAvailable={state.isAvailable}
265 web3={props.web3}
216 web3={props.web3}
266 contracts={props.contracts}
217 contracts={props.contracts}
267 wallet={props.wallet}
218 wallet={props.wallet}
268 walletType={props.walletType}
219 walletType={props.walletType}
269 walletHdPath={props.walletHdPath}
220 walletHdPath={props.walletHdPath}
270 networkType={props.networkType}
221 networkType={props.networkType}
271− // Tx
222+ setTxnHashCursor={props.setTxnHashCursor}
272− txApproval={state.txApproval}
223+ popRoute={props.popRoute}
273− txn={state.txn}
224+ pushRoute={props.pushRoute}
274− stx={state.stx}
225+ // Other
275− nonce={state.nonce}
226+ ref={this.statelessRef}
276− gasPrice={state.gasPrice}
277− showGasDetails={state.showGasDetails}
278− toggleGasDetails={this.toggleGasDetails}
279− chainId={state.chainId}
280− gasLimit={state.gasLimit}
281− canGenerate={
227+ canGenerate={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()}
228+ 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} />
299
229
300 </Col>
230 </Col>
301 </Row>
231 </Row>