1import Maybe from 'folktale/maybe'
2import React from 'react'
3import { Button } from '../components/Base'
8} from '../components/Base'
9import { Row, Col, H1, P } from '../components/Base'
10import * as azimuth from 'azimuth-js'
11import Web3 from 'web3'
13import { CONTRACT_ADDRESSES } from '../lib/contracts'
14import { NETWORK_NAMES, renderNetworkType } from '../lib/network'
15import { ROUTE_NAMES } from '../lib/router'
17class Network extends React.Component {
26 this.toggle = this.toggle.bind(this);
27 this.close = this.close.bind(this);
28 this.handleNetworkChange = this.handleNetworkChange.bind(this);
32 this.setState((state, _) => ({
33 dropdownOpen: !state.dropdownOpen
37 handleNetworkChange(network) {
38 const { setNetworkType, setNetwork } = this.props
40 if (network === NETWORK_NAMES.LOCAL) {
41 setNetworkType(network)
43 const endpoint = 'ws://localhost:8545'
44 const provider = new Web3.providers.WebsocketProvider(endpoint)
45 const web3 = new Web3(provider)
46 const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV)
48 setNetwork(Maybe.Just(web3), Maybe.Just(contracts))
51 if (network === NETWORK_NAMES.ROPSTEN) {
52 setNetworkType(network)
55 `https://ropsten.infura.io/v3/${process.env.REACT_APP_INFURA_KEY}`
57 const provider = new Web3.providers.HttpProvider(endpoint)
58 const web3 = new Web3(provider)
59 const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.ROPSTEN)
61 setNetwork(Maybe.Just(web3), Maybe.Just(contracts))
64 if (network === NETWORK_NAMES.MAINNET) {
65 setNetworkType(network)
68 `https://mainnet.infura.io/v3/${process.env.REACT_APP_INFURA_KEY}`
70 const provider = new Web3.providers.HttpProvider(endpoint)
71 const web3 = new Web3(provider)
72 const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.MAINNET)
74 setNetwork(Maybe.Just(web3), Maybe.Just(contracts))
77 if (network === NETWORK_NAMES.OFFLINE) {
78 setNetworkType(network)
82 // The 'offline' network type targets the mainnet contracts, but does not
83 // actually use a provider to connect. We use a web3 instance to
84 // initalise the contracts, but the network itself is set to Nothing.
86 // We may want to offer the ability to select a target network for
87 // transactions when offline.
89 const web3 = new Web3()
92 process.env.NODE_ENV === 'development'
93 ? CONTRACT_ADDRESSES.DEV
94 : CONTRACT_ADDRESSES.MAINNET
96 const contracts = azimuth.initContracts(web3, target)
98 setNetwork(Maybe.Nothing(), Maybe.Just(contracts))
104 this.setState({ dropdownOpen: false })
109 this.setState({ dropdownOpen: false })
113 const { dropdownOpen } = this.state
114 const { networkType, pushRoute } = this.props
119 <H1>{ 'Select Network' }</H1>
124 "Please select the Ethereum node you'd like to send " +
125 "transactions to. For highly valuable keys, please select " +
133 handleToggle={this.toggle}
134 handleClose={this.close}
135 isOpen={dropdownOpen}
137 currentSelectionTitle={renderNetworkType(networkType)}
143 () => this.selectClose(() => this.handleNetworkChange(NETWORK_NAMES.MAINNET))
146 { 'Main Network (default)' }
152 () => this.selectClose(() => this.handleNetworkChange(NETWORK_NAMES.LOCAL))
155 { //'Ganache Node @ Port 8545 (Default)'
164 () => this.selectClose(() => this.handleNetworkChange(NETWORK_NAMES.ROPSTEN))
176 () => this.selectClose(() => this.handleNetworkChange(NETWORK_NAMES.OFFLINE))
182 </InnerLabelDropdown>
186 onClick={ () => pushRoute(ROUTE_NAMES.WALLET) }
197export default Network
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list