@@ -3,7 +3,8 @@ import React from 'react'
33
44import { Code, H3 } from './Base'
55import { Button } from './Base'
6−import { CheckboxButton, Input, InnerLabel } from './Base'
6+import { CheckboxButton, Input, InnerLabel,
7+ InnerLabelDropdown } from './Base'
78import { Warning } from '../components/Base'
89
910import { addressFromSecp256k1Public } from '../lib/wallet'
@@ -28,10 +29,11 @@ class StatelessTransaction extends React.Component {
2829 showGasDetails: false,
2930 userApproval: false,
3031 chainId: '',
32+ customChain: false,
3133 nonce: '',
3234 stx: Nothing(),
3335 txn: Nothing(),
34− txError: Nothing(),
36+ txError: Nothing()
3537 }
3638
3739 this.createUnsignedTxn = this.createUnsignedTxn.bind(this)
@@ -46,6 +48,7 @@ class StatelessTransaction extends React.Component {
4648 this.setGasLimit = this.setGasLimit.bind(this)
4749 this.rangeChange = this.rangeChange.bind(this)
4850 this.toggleGasDetails = this.toggleGasDetails.bind(this)
51+ this.handleChainUpdate = this.handleChainUpdate.bind(this)
4952 }
5053
5154 componentDidMount() {
@@ -106,6 +109,19 @@ class StatelessTransaction extends React.Component {
106109 })
107110 }
108111
112+ handleChainUpdate(chainId) {
113+ if (chainId === "custom") {
114+ this.setState({
115+ customChain: true
116+ })
117+ } else {
118+ this.setState({
119+ customChain: false,
120+ chainId
121+ })
122+ }
123+ }
124+
109125 setUserApproval(){
110126 const {state} = this
111127 this.setState({ userApproval: !state.userApproval })
@@ -185,13 +201,53 @@ class StatelessTransaction extends React.Component {
185201 this.submit()
186202 }
187203
204+ getChainTitle(chainId) {
205+ let map = {
206+ "1": "Mainnet - 1",
207+ "2": "Morden - 2",
208+ "3": "Ropsten - 3",
209+ "4": "Goerli - 4",
210+ "42": "Kovan - 42",
211+ "1337": "Geth private chains - 1337",
212+ "custom": "Custom"
213+ }
214+
215+ return map[chainId]
216+ }
217+
218+ getChainOptions() {
219+ return [{
220+ title: this.getChainTitle("1"),
221+ value: "1"
222+ }, {
223+ title: this.getChainTitle("2"),
224+ value: "2"
225+ }, {
226+ title: this.getChainTitle("3"),
227+ value: "3"
228+ }, {
229+ title: this.getChainTitle("4"),
230+ value: "4"
231+ }, {
232+ title: this.getChainTitle("42"),
233+ value: "42"
234+ }, {
235+ title: this.getChainTitle("1337"),
236+ value: "1337"
237+ }, {
238+ title: this.getChainTitle("custom"),
239+ value: "custom"
240+ }]
241+ }
242+
188243 render() {
189244 const { web3, canGenerate } = this.props
190245 const { gasPrice, gasLimit, nonce, chainId,
191− txn, stx, userApproval, showGasDetails } = this.state
246+ txn, stx, userApproval, showGasDetails,
247+ customChain } = this.state
192248
193249 const { setNonce, setChainId, setGasLimit, setGasPrice, toggleGasDetails,
194− setUserApproval, sendTxn, createUnsignedTxn } = this
250+ setUserApproval, sendTxn, createUnsignedTxn, handleChainUpdate } = this
195251
196252 const { state } = this
197253
@@ -199,6 +255,8 @@ class StatelessTransaction extends React.Component {
199255 const canApprove = Just.hasInstance(stx)
200256 const canSend = Just.hasInstance(stx) && userApproval === true
201257
258+ const chainOptions = this.getChainOptions()
259+
202260 const generateButtonColor =
203261 Nothing.hasInstance(txn)
204262 ? 'blue'
@@ -294,7 +352,7 @@ class StatelessTransaction extends React.Component {
294352
295353 const nonceDialogue =
296354 <Input
297− className={ 'mono mt-4' }
355+ className={ 'mono mt-4 mb-4' }
298356 prop-size={ 'md' }
299357 prop-format={ 'innerLabel' }
300358 value={ nonce }
@@ -305,18 +363,30 @@ class StatelessTransaction extends React.Component {
305363 </InnerLabel>
306364 </Input>
307365
366+ const chainDialogueTitle = customChain ? "Custom" : this.getChainTitle(chainId)
308367 const chainDialogue =
309− <Input
310− className={ 'mono mt-4 mb-8' }
311− prop-size={ 'md' }
312− prop-format={ 'innerLabel' }
313− value={ chainId }
314− onChange={ setChainId }
368+ <InnerLabelDropdown
369+ className={'mt-6'}
370+ fullWidth={true}
371+ title={'Chain ID'}
372+ options={chainOptions}
373+ handleUpdate={handleChainUpdate}
374+ currentSelectionTitle={chainDialogueTitle}
315375 >
316− <InnerLabel>
317− { 'Chain ID' }
318− </InnerLabel>
319− </Input>
376+ </InnerLabelDropdown>
377+
378+ const customChainDialogue = !customChain ? null :
379+ <Input
380+ className={ 'mono mt-4 mb-8' }
381+ prop-size={ 'md' }
382+ prop-format={ 'innerLabel' }
383+ value={ chainId }
384+ onChange={ setChainId }
385+ >
386+ <InnerLabel>
387+ { 'Chain ID' }
388+ </InnerLabel>
389+ </Input>
320390
321391 const onlineParamsDialogue = web3.matchWith({
322392 Just: _ => <div />,
@@ -324,6 +394,7 @@ class StatelessTransaction extends React.Component {
324394 <React.Fragment>
325395 { nonceDialogue }
326396 { chainDialogue }
397+ { customChainDialogue }
327398 </React.Fragment>
328399 })
329400