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
38 const { networkType } = this.props
39 this.handleNetworkChange(networkType)
42 handleNetworkChange(network) {
43 const { setNetworkType, setNetwork } = this.props
45 if (network === NETWORK_NAMES.LOCAL) {
46 setNetworkType(network)
48 const endpoint = 'wss://localhost:8545'
49 const provider = new Web3.providers.WebsocketProvider(endpoint)
50 const web3 = new Web3(provider)
51 const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV)
53 setNetwork(Maybe.Just(web3), Maybe.Just(contracts))
56 if (network === NETWORK_NAMES.ROPSTEN) {
57 setNetworkType(network)
60 `https://ropsten.infura.io/v3/${process.env.REACT_APP_INFURA_KEY}`
62 const provider = new Web3.providers.HttpProvider(endpoint)
63 const web3 = new Web3(provider)
64 const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.ROPSTEN)
66 setNetwork(Maybe.Just(web3), Maybe.Just(contracts))
69 if (network === NETWORK_NAMES.MAINNET) {
70 setNetworkType(network)
73 `https://mainnet.infura.io/v3/${process.env.REACT_APP_INFURA_KEY}`
75 const provider = new Web3.providers.HttpProvider(endpoint)
76 const web3 = new Web3(provider)
77 const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.MAINNET)
79 setNetwork(Maybe.Just(web3), Maybe.Just(contracts))
82 if (network === NETWORK_NAMES.OFFLINE) {
83 setNetworkType(network)
87 // The 'offline' network type targets the mainnet contracts, but does not
88 // actually use a provider to connect. We use a web3 instance to
89 // initalise the contracts, but the network itself is set to Nothing.
91 // We may want to offer the ability to select a target network for
92 // transactions when offline.
94 const web3 = new Web3()
97 process.env.NODE_ENV === 'development'
98 ? CONTRACT_ADDRESSES.DEV
99 : CONTRACT_ADDRESSES.MAINNET
101 const contracts = azimuth.initContracts(web3, target)
103 setNetwork(Maybe.Nothing(), Maybe.Just(contracts))
109 this.setState({ dropdownOpen: false })
114 this.setState({ dropdownOpen: false })
118 const { dropdownOpen } = this.state
119 const { networkType, pushRoute } = this.props
124 <H1>{ 'Select Network' }</H1>
129 "Please select the Ethereum node you'd like to send " +
130 "transactions to. For highly valuable keys, please select " +
138 handleToggle={this.toggle}
139 handleClose={this.close}
140 isOpen={dropdownOpen}
142 currentSelectionTitle={renderNetworkType(networkType)}
148 () => this.selectClose(() => this.handleNetworkChange(NETWORK_NAMES.MAINNET))
151 { 'Main Network (default)' }
157 () => this.selectClose(() => this.handleNetworkChange(NETWORK_NAMES.LOCAL))
160 { //'Ganache Node @ Port 8545 (Default)'
169 () => this.selectClose(() => this.handleNetworkChange(NETWORK_NAMES.ROPSTEN))
181 () => this.selectClose(() => this.handleNetworkChange(NETWORK_NAMES.OFFLINE))
187 </InnerLabelDropdown>
191 onClick={ () => pushRoute(ROUTE_NAMES.WALLET) }
202export 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