ADD network indicator

pull/1/head
serapath 7 years ago
parent 79021679a2
commit 1b88139fda
  1. 71
      src/app/tabs/run-tab.js
  2. 19
      src/lib/detect-network.js

@ -1,6 +1,7 @@
'use strict' 'use strict'
var $ = require('jquery') var $ = require('jquery')
var yo = require('yo-yo') var yo = require('yo-yo')
var detectNetwork = require('../../lib/detect-network')
var helper = require('../../lib/helper.js') var helper = require('../../lib/helper.js')
var txExecution = require('../execution/txExecution') var txExecution = require('../execution/txExecution')
var txFormat = require('../execution/txFormat') var txFormat = require('../execution/txFormat')
@ -165,6 +166,20 @@ var css = csjs`
padding-left: 10px; padding-left: 10px;
display: inline; display: inline;
} }
.network {
display: flex;
justify-content: flex-end;
align-items: center;
position: absolute;
color: grey;
width: 100%;
height: 100%;
padding-right: 20px;
pointer-events: none;
}
.networkItem {
margin-right: 5px;
}
` `
module.exports = runTab module.exports = runTab
@ -366,33 +381,47 @@ function contractDropdown (appAPI, appEvents, instanceContainer) {
------------------------------------------------ */ ------------------------------------------------ */
function settings (appAPI, appEvents) { function settings (appAPI, appEvents) {
// SETTINGS HTML // SETTINGS HTML
var net = yo`<span class=${css.network}></span>`
const updateNetwork = () => {
detectNetwork((err, { id, name } = {}) => {
if (err) console.error(err)
console.log(`update network[${id}] name: ${name}`)
net.innerHTML = `
<i class="${css.networkItem} fa fa-plug" aria-hidden="true"></i> ${name}(${id || '-'})
`
})
}
updateNetwork()
var el = yo` var el = yo`
<div class="${css.settings}"> <div class="${css.settings}">
<div class="${css.crow}"> <div class="${css.crow}">
<div id="selectExEnv" class="${css.col1_1}"> <div id="selectExEnv" class="${css.col1_1}">
Environment Environment
</div> </div>
<select id="selectExEnvOptions" class="${css.select}"> <div style="position: relative;">
<option id="vm-mode" ${net}
title="Execution environment does not connect to any node, everything is local and in memory only." <select id="selectExEnvOptions" onchange=${updateNetwork} class="${css.select}">
value="vm" <option id="vm-mode"
checked name="executionContext"> title="Execution environment does not connect to any node, everything is local and in memory only."
JavaScript VM value="vm"
</option> checked name="executionContext">
<option id="injected-mode" JavaScript VM
title="Execution environment has been provided by Mist or similar provider." </option>
value="injected" <option id="injected-mode"
checked name="executionContext"> title="Execution environment has been provided by Mist or similar provider."
Injected Web3 value="injected"
</option> checked name="executionContext">
<option id="web3-mode" Injected Web3
title="Execution environment connects to node at localhost (or via IPC if available), transactions will be sent to the network and can cause loss of money or worse! </option>
If this page is served via https and you access your node via http, it might not work. In this case, try cloning the repository and serving it via http." <option id="web3-mode"
value="web3" title="Execution environment connects to node at localhost (or via IPC if available), transactions will be sent to the network and can cause loss of money or worse!
name="executionContext"> If this page is served via https and you access your node via http, it might not work. In this case, try cloning the repository and serving it via http."
Web3 Provider value="web3"
</option> name="executionContext">
</select> Web3 Provider
</option>
</select>
</div>
</div> </div>
<div class="${css.crow}"> <div class="${css.crow}">
<div class="${css.col1_1}">Account</div> <div class="${css.col1_1}">Account</div>

@ -0,0 +1,19 @@
var executionContext = require('../execution-context')
window.executionContext = executionContext
module.exports = detectNetwork
function detectNetwork (callback) {
var web3provider = executionContext.web3()
var get = web3provider.version ? web3provider.version.getNetwork : web3provider.web3.version.getNetwork
get((err, id) => {
var name = null
if (err) name = 'Unknown'
else if (id === '1') name = 'Main'
else if (id === '2') name = 'Morden (deprecated)'
else if (id === '3') name = 'Ropsten'
else if (id === '4') name = 'Rinkeby'
else if (id === '42') name = 'Kovan'
else name = 'Unknown'
callback(err, { id, name })
})
}
Loading…
Cancel
Save