on master help sign in
- Make StatelessTransaction use new dropdown code
56d2688Chris Johnson
src/bridge/components/StatelessTransaction.js+59−84
@@ -49,10 +49,7 @@ class StatelessTransaction extends React.Component {
49 this.setGasLimit = this.setGasLimit.bind(this)
49 this.setGasLimit = this.setGasLimit.bind(this)
50 this.rangeChange = this.rangeChange.bind(this)
50 this.rangeChange = this.rangeChange.bind(this)
51 this.toggleGasDetails = this.toggleGasDetails.bind(this)
51 this.toggleGasDetails = this.toggleGasDetails.bind(this)
52− this.toggleChainDropdown = this.toggleChainDropdown.bind(this)
52+ this.handleChainUpdate = this.handleChainUpdate.bind(this)
53− this.closeChainDropdown = this.closeChainDropdown.bind(this)
54− this.selectChain = this.selectChain.bind(this)
55− this.openCustomChain = this.openCustomChain.bind(this)
56 }
53 }
57
54
58 componentDidMount() {
55 componentDidMount() {
@@ -113,31 +110,17 @@ class StatelessTransaction extends React.Component {
113 })
110 })
114 }
111 }
115
112
116− openCustomChain() {
113+ handleChainUpdate(chainId) {
114+ if (chainId === "custom") {
117− this.setState({
115+ this.setState({
118− chainDropdownOpen: false,
119− customChain: true
116+ customChain: true
120− })
121− }
122−
123− toggleChainDropdown() {
124− this.setState({
125− chainDropdownOpen: !this.state.chainDropdownOpen
126− })
117+ })
127− }
118+ } else {
128−
129− closeChainDropdown() {
130− this.setState({
119+ this.setState({
131− chainDropdownOpen: false
120+ customChain: false,
132− })
133− }
134−
135− selectChain(chainId) {
136− this.setState({
137− chainId,
121+ chainId
138− chainDropdownOpen: false,
122+ })
139− customChain: false
140− })
123+ }
141 }
124 }
142
125
143 setUserApproval(){
126 setUserApproval(){
@@ -219,14 +202,54 @@ class StatelessTransaction extends React.Component {
219 this.submit()
202 this.submit()
220 }
203 }
221
204
205+ getChainTitle(chainId) {
206+ let map = {
207+ "1": "Mainnet - 1",
208+ "2": "Morden - 2",
209+ "3": "Ropsten - 3",
210+ "4": "Goerli - 4",
211+ "42": "Kovan - 42",
212+ "1337": "Geth private chains - 1337",
213+ "custom": "Custom"
214+ }
215+
216+ return map[chainId]
217+ }
218+
219+ getChainOptions() {
220+ return [{
221+ title: this.getChainTitle("1"),
222+ value: "1"
223+ }, {
224+ title: this.getChainTitle("2"),
225+ value: "2"
226+ }, {
227+ title: this.getChainTitle("3"),
228+ value: "3"
229+ }, {
230+ title: this.getChainTitle("4"),
231+ value: "4"
232+ }, {
233+ title: this.getChainTitle("42"),
234+ value: "42"
235+ }, {
236+ title: this.getChainTitle("1337"),
237+ value: "1337"
238+ }, {
239+ title: this.getChainTitle("custom"),
240+ value: "custom"
241+ }]
242+ }
243+
222 render() {
244 render() {
223 const { web3, canGenerate } = this.props
245 const { web3, canGenerate } = this.props
224 const { gasPrice, gasLimit, nonce, chainId,
246 const { gasPrice, gasLimit, nonce, chainId,
225 txn, stx, userApproval, showGasDetails,
247 txn, stx, userApproval, showGasDetails,
226 customChain, chainDropdownOpen } = this.state
248 customChain, chainDropdownOpen } = this.state
227
249
228− const { setNonce, setChainId, setGasLimit, setGasPrice, toggleGasDetails,
250+ const { setNonce, setChainId, setGasLimit, setGasPrice,
229− setUserApproval, sendTxn, createUnsignedTxn, selectChain } = this
251+ toggleGasDetails, setUserApproval, sendTxn, createUnsignedTxn,
252+ selectChain, handleChainUpdate } = this
230
253
231 const { state } = this
254 const { state } = this
232
255
@@ -234,6 +257,8 @@ class StatelessTransaction extends React.Component {
234 const canApprove = Just.hasInstance(stx)
257 const canApprove = Just.hasInstance(stx)
235 const canSend = Just.hasInstance(stx) && userApproval === true
258 const canSend = Just.hasInstance(stx) && userApproval === true
236
259
260+ const chainOptions = this.getChainOptions()
261+
237 const generateButtonColor =
262 const generateButtonColor =
238 Nothing.hasInstance(txn)
263 Nothing.hasInstance(txn)
239 ? 'blue'
264 ? 'blue'
@@ -340,66 +365,16 @@ class StatelessTransaction extends React.Component {
340 </InnerLabel>
365 </InnerLabel>
341 </Input>
366 </Input>
342
367
343− const chainDialogueTitle = customChain ? "Custom" : chainId
368+ const chainDialogueTitle = customChain ? "Custom" : this.getChainTitle(chainId)
344 const chainDialogue =
369 const chainDialogue =
345 <InnerLabelDropdown
370 <InnerLabelDropdown
346 className={'mt-6'}
371 className={'mt-6'}
347− handleToggle={this.toggleChainDropdown}
348− handleClose={this.closeChainDropdown}
349 fullWidth={true}
372 fullWidth={true}
350− isOpen={chainDropdownOpen}
351 title={'Chain ID'}
373 title={'Chain ID'}
374+ options={chainOptions}
375+ handleUpdate={handleChainUpdate}
352 currentSelectionTitle={chainDialogueTitle}
376 currentSelectionTitle={chainDialogueTitle}
353 >
377 >
354− <DropdownItem
355− isSelected={ false }
356− onClick={() => selectChain("1")}
357− >
358− { '1 - Mainnet' }
359− </DropdownItem>
360−
361− <DropdownItem
362− isSelected={false}
363− onClick={() => selectChain("2")}
364− >
365− {'2 - Morden'}
366− </DropdownItem>
367−
368− <DropdownItem
369− isSelected={false}
370− onClick={() => selectChain("3")}
371− >
372− {'3 - Ropsten'}
373− </DropdownItem>
374−
375− <DropdownItem
376− isSelected={false}
377− onClick={() => selectChain("4")}
378− >
379− {'4 - Goerli'}
380− </DropdownItem>
381−
382− <DropdownItem
383− isSelected={false}
384− onClick={() => selectChain("42")}
385− >
386− {'42 - Kovan'}
387− </DropdownItem>
388−
389− <DropdownItem
390− isSelected={false}
391− onClick={() => selectChain("1337")}
392− >
393− {'1337 - Geth private chains'}
394− </DropdownItem>
395−
396− <DropdownItem
397− isSelected={false}
398− onClick={this.openCustomChain}
399− >
400− {'Custom'}
401− </DropdownItem>
402−
403 </InnerLabelDropdown>
378 </InnerLabelDropdown>
404
379
405 const customChainDialogue = !customChain ? null :
380 const customChainDialogue = !customChain ? null :
src/bridge/views/Network.js+1−1
@@ -98,7 +98,7 @@ class Network extends React.Component {
98 }, {
98 }, {
99 title: 'Offline',
99 title: 'Offline',
100 value: NETWORK_NAMES.OFFLINE
100 value: NETWORK_NAMES.OFFLINE
101− }, ]
101+ }]
102 }
102 }
103
103
104 render() {
104 render() {
src/bridge/views/Wallet.js+1−1
@@ -47,7 +47,7 @@ class Wallet extends React.Component {
47 }, {
47 }, {
48 title: 'Ethereum Keystore File',
48 title: 'Ethereum Keystore File',
49 value: WALLET_NAMES.KEYSTORE
49 value: WALLET_NAMES.KEYSTORE
50− }, ]
50+ }]
51 }
51 }
52
52
53 render() {
53 render() {