Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Ready for Alpha 2
Browse files Browse the repository at this point in the history
  • Loading branch information
mvele10 committed Jul 30, 2018
1 parent 7725c80 commit bf2e252
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 14 deletions.
Binary file added bitseed-webui3-0.1alpha2.zip
Binary file not shown.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"author": "[email protected]",
"licemse": "MIT",
"dependencies": {
"moment": "^2.22.2",
"moment-duration-format": "^2.2.2",
"react": "^16.4.1",
"react-css-grid": "^2.0.0-0",
"react-dom": "^16.4.1",
"react-router-bootstrap": "^0.24.4",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.4"
"react-scripts": "1.1.4",
"systeminformation": "^3.42.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
70 changes: 68 additions & 2 deletions public/server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,60 @@
const http = require('http')
const fs = require('fs')
const os = require('os')
const sysInfo = require('systeminformation')

console.log('Bitseed Web UI server is now running. Waiting for requests...')
/* Device Uptime*/
const moment = require("moment")
const momentDurationFormatSetup = require("moment-duration-format")
const uptimeFormat = "w [weeks], d [days], h [hours], m [minutes]"
/* */

/* Local IP and MAC Address */
const networkInterfaces = os.networkInterfaces()
const localInterface = (Object.keys(networkInterfaces)
.map(x => networkInterfaces[x]
.filter(x => x.family === 'IPv4' && !x.internal)[0])
.filter(x => x)[0])
const macAddress = localInterface.mac
const localAddress = localInterface.address
/* */

/* Disk Size */
let diskSize = 'No Data'
let diskSpaceUsed = 'No Data'
let diskSpaceAvailable = 'No Data'

sysInfo.fsSize().then(response => {
diskSize = formatBytes(response[0].size)
diskSpaceUsed = `${formatBytes(response[0].used)} (${response[0].use}%)`
diskSpaceAvailable = formatBytes(response[0].size - response[0].used)
})
/* */

/* RAM */
let ramUsed = 'No Data'
let ramFree = 'No Data'

sysInfo.mem().then(response => {
ramUsed = formatBytes(response.used)
ramFree = formatBytes(response.free)
})
/* */

/* CPU Load */
let cpuLoad = 'No Data'

sysInfo.currentLoad().then(response => {
cpuLoad = `${response.avgload}`
})
/* */




function formatBytes(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],f=Math.floor(Math.log(a)/Math.log(c));return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f]}

console.log('Bitseed Web UI server is now running. Waiting for requests...')
http.createServer((request, response) => {
response.setHeader('Access-Control-Allow-Origin', '*')
response.setHeader('Access-Control-Allow-Methods', 'GET, POST')
Expand Down Expand Up @@ -53,9 +105,23 @@ http.createServer((request, response) => {
response.setHeader('Content-Type', 'application/json')
response.statusCode = 200
response.end(JSON.stringify({ status: 'ok'}))
} else if (request.url === '/deviceInformation') {
response.setHeader('Content-Type', 'application/json')
response.statusCode = 200
response.end(JSON.stringify({
uptime: moment.duration(os.uptime(), "seconds").format(uptimeFormat),
localAddress: localAddress,
macAddress: macAddress,
diskSize: diskSize,
diskSpaceUsed: diskSpaceUsed,
diskSpaceAvailable: diskSpaceAvailable,
ramUsed: ramUsed,
ramFree: ramFree,
cpuLoad: cpuLoad
}))
}
} else {
response.statusCode = 501
response.end('Invalid Request')
}
}).listen(3001)
}).listen(3001)
18 changes: 17 additions & 1 deletion src/APIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,23 @@ export default class APIClient {
})
}

static getBitseedDeviceData() {
static getDeviceInformation() {
return new Promise((resolve, reject) => {
fetch('http://localhost:3001/deviceInformation', {
method: 'GET',
})
.then((response) => {
return response.json()
})
.then((responseJSON) => {
resolve(responseJSON)
}).catch((error) => {
reject(error)
})
})
}

static getBitseedDeviceSerial() {
return new Promise((resolve, reject) => {
fetch('http://localhost:3001/serial', {
method: 'GET',
Expand Down
2 changes: 2 additions & 0 deletions src/Device.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { Component } from 'react'
import AddressesPanel from './Panels/AddressesPanel'
import DeviceInformationPanel from './Panels/DeviceInformationPanel'

export default class Device extends Component {
render() {
return (
<div>
<DeviceInformationPanel />
<AddressesPanel />
</div>
)
Expand Down
19 changes: 18 additions & 1 deletion src/Panels/AddressesPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default class AddressesPanel extends Component {
publicIPv4Address: { address: '', isReachable: false},
publicIPv6Address: { address: '', isReachable: false},
publicOnionAddress: { address: '', isReachable: false},
localAddress: { address: '', isReachable: undefined},
macAddress: { address: '', isReachable: undefined}
}

getNodeStatus() {
Expand Down Expand Up @@ -100,6 +102,15 @@ export default class AddressesPanel extends Component {
}
}
})

APIClient.getDeviceInformation().then((response) => {
console.log(response)
this.setState({
localAddress: { address: response.localAddress, isReachable: undefined},
macAddress: { address: response.macAddress, isReachable: undefined}
})
})

APIClient.getNetworkInfo().then((response) => {
if (response.result !== undefined) {
if (response.result.networks !== undefined) {
Expand Down Expand Up @@ -162,7 +173,8 @@ export default class AddressesPanel extends Component {
<React.Fragment>
<Grid gap={0} width={0}>
<span style={{ fontWeight: 'bold', textAlign: 'left'}}>{title}</span>
<span style={{ fontWeight: 'normal', textAlign: 'right'}}>{description.address} ({description.isReachable === false ? 'Not ' : null}Reachable)</span>
{description.isReachable !== undefined && <span style={{ fontWeight: 'normal', textAlign: 'right'}}>{description.address} ({description.isReachable === false ? 'Not ' : null}Reachable)</span>}
{description.isReachable === undefined && <span style={{ fontWeight: 'normal', textAlign: 'right'}}>{description.address}</span>}
</Grid>
<br />
</React.Fragment>
Expand All @@ -176,6 +188,8 @@ export default class AddressesPanel extends Component {
{this.renderRowWithColumn('Public IPv4 Address:', this.state.publicIPv4Address)}
{this.renderRowWithColumn('Public IPv6 Address:', this.state.publicIPv6Address)}
{this.renderRowWithColumn('Public Onion Address:', this.state.publicOnionAddress)}
{this.renderRowWithColumn('Local Address:', this.state.localAddress)}
{this.renderRowWithColumn('MAC Address:', this.state.macAddress)}
</React.Fragment>
)
} else {
Expand All @@ -194,6 +208,8 @@ export default class AddressesPanel extends Component {
<Panel.Heading>
<Grid width={96} gap={0} align='center'>
<Panel.Title>Your Addresses</Panel.Title>
<Grid width={20} gap={90} align='right'>

{ !panelConfiguration.panelHeaderButton.panelHeaderButtonHidden &&
<Button
bsStyle={panelConfiguration.panelHeaderButton.panelHeaderButtonButtonStyle}
Expand All @@ -203,6 +219,7 @@ export default class AddressesPanel extends Component {
{panelConfiguration.panelHeaderButton.panelHeaderButtonText}
</Button>
}
</Grid>
</Grid>
</Panel.Heading>
<Panel.Body>
Expand Down
9 changes: 0 additions & 9 deletions src/Panels/BitcoinPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default class BitcoinPanel extends Component {
},
pruned: false,
isBitcoinDaemonStatusLoading: true,
deviceID: '',
blocks: '',
headers: '',
connectedPeers: '',
Expand Down Expand Up @@ -77,12 +76,6 @@ export default class BitcoinPanel extends Component {
}

getNodeStatus() {
APIClient.getBitseedDeviceData().then((response) => {
this.setState({ deviceID: response })
}).catch((error) => {
this.setState({ deviceID: 'No Data' })
})

APIClient.getPingResult().then((data) => {
if (data.error !== null && data.error.code === -28) {
this.setState({
Expand Down Expand Up @@ -186,8 +179,6 @@ export default class BitcoinPanel extends Component {
{this.renderRowWithColumn('Peer Connection', this.state.connectedPeers)}
{this.renderRowWithColumn('Tx in Mempool', this.state.txmempool)}
{this.renderRowWithColumn('Minimum Relay Fee', this.state.minrelaytxfee)}
{this.renderRowWithColumn('Device ID', this.state.deviceID)}
{this.renderRowWithColumn('Device Version', 'No Data')}
</React.Fragment>
)
}
Expand Down
3 changes: 3 additions & 0 deletions src/Panels/BitcoinSettingsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class BitcoinSettingsPanel extends Component {
<Panel.Title>Bitcoin Server Settings</Panel.Title>
</Panel.Heading>
<Panel.Body>
{/*
<Form horizontal>
<FormGroup controlId="fromRPCProtocol">
<Col componentClass={ControlLabel} sm={3}>
Expand Down Expand Up @@ -69,6 +70,8 @@ export default class BitcoinSettingsPanel extends Component {
</Col>
</FormGroup>
</Form>
*/}
Coming Soon...
</Panel.Body>
</Panel>
</Grid>
Expand Down
Loading

0 comments on commit bf2e252

Please sign in to comment.