Skip to content

Commit

Permalink
Merge branch '1.10.0' into 1428-add-hwWallet-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltomasik committed Jan 23, 2019
2 parents 655014e + 1aeea8f commit 0c2e33a
Show file tree
Hide file tree
Showing 221 changed files with 7,166 additions and 987 deletions.
2 changes: 0 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -4,8 +4,6 @@ about: Create a report to help us improve

---

<!--- Provide a general summary of the issue in the Title above -->

### Steps to reproduce
<!-- Provide an unambiguous set of steps to reproduce the bug -->

Expand Down
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Expand Up @@ -2,7 +2,7 @@

### What issue have I solved?
<!--- Complementary description if needed -->
-- #INSERT_ISSUE_NUMBER
#INSERT_ISSUE_NUMBER

### How have I implemented/fixed it?
<!--- Describe your technical implementation -->
Expand Down
12 changes: 4 additions & 8 deletions Jenkinsfile
Expand Up @@ -7,7 +7,7 @@ pipeline {
buildDiscarder(logRotator(numToKeepStr: '168', artifactNumToKeepStr: '5'))
}
environment {
LISK_CORE_VERSION = '1.3.0'
LISK_CORE_VERSION = '1.4.0-rc.0'
}
stages {
stage('Install npm dependencies') {
Expand Down Expand Up @@ -39,12 +39,8 @@ pipeline {
npm run --silent build:testnet
npm run --silent bundlesize
if [ -z $CHANGE_BRANCH ]; then
npm install
USE_SYSTEM_XORRISO=true npm run dist:linux
else
echo "Skipping desktop build for Linux because we're building a PR."
fi
npm install
USE_SYSTEM_XORRISO=true npm run dist:linux
'''
}
}
Expand Down Expand Up @@ -119,7 +115,7 @@ pipeline {
sed -i -r -e '/ports:/,+2d' docker-compose.yml
# random port assignment
cat <<EOF >docker-compose.override.yml
version: "2"
version: "3"
services:
lisk:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -67,6 +67,12 @@ Then, in order to launch version with hardware wallet, you can run
npm run dev-hardware-wallet
```

In order to launch electron that gets live updates from already running webpack-dev-server on port 8080, you can run

```
LISK_HUB_URL="http://localhost:8080" npm run start
```

#### Windows

Build package for Windows (on Windows in [Git BASH](https://git-for-windows.github.io/)).
Expand Down
13 changes: 12 additions & 1 deletion app/package.json
@@ -1,10 +1,21 @@
{
"name": "lisk-hub",
"version": "1.8.0-beta.1",
"version": "1.9.0-rc.2",
"description": "Lisk Hub",
"main": "./build/main.js",
"author": {
"name": "Lisk Foundation",
"email": "admin@lisk.io"
},
"scripts": {
"postinstall": "electron-rebuild --force"
},
"dependencies": {
"find-free-port": "2.0.0",
"node-hid": "0.7.2",
"usb": "1.3.3"
},
"devDependencies": {
"electron-rebuild": "1.8.2"
}
}
33 changes: 33 additions & 0 deletions app/server.js
@@ -0,0 +1,33 @@
const server = {
// eslint-disable-next-line max-statements
init: (port) => {
const express = require('express'); // eslint-disable-line
const Path = require('path');
const bodyParser = require('body-parser'); // eslint-disable-line

if (process.env.LISK_HUB_URL) {
return process.env.LISK_HUB_URL;
}

const app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.set('views', Path.join(__dirname, '.'));
app.use(express.static(Path.join(__dirname, '.')));

app.get('*', (req, res) => res.sendFile(Path.join(__dirname, 'index.html')));

// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
app.listen(port);
return `http://localhost:${port}/`;
},
};

export default server;
21 changes: 10 additions & 11 deletions app/src/ledger.js
@@ -1,19 +1,18 @@
import { app, ipcMain } from 'electron'; // eslint-disable-line import/no-extraneous-dependencies
import Lisk from 'lisk-elements'; // eslint-disable-line import/no-extraneous-dependencies
import { LedgerAccount, SupportedCoin, DposLedger } from 'dpos-ledger-api'; // eslint-disable-line import/no-extraneous-dependencies
import win from './modules/win';
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'; // eslint-disable-line import/no-extraneous-dependencies

import win from './modules/win';

// eslint-disable-next-line import/no-extraneous-dependencies
// TransportNodeHid = require('@ledgerhq/hw-transport-node-hid');
// mock transportnodehid, todo fix this to work also on windows and linux
const TransportNodeHid = {
open: () => {},
listen: () => {},
setListenDevicesDebounce: () => {},
setListenDevicesPollingSkip: () => {},
};
TransportNodeHid.setListenDevicesDebounce(200);
// const TransportNodeHid = {
// open: () => {},
// listen: () => {},
// setListenDevicesDebounce: () => {},
// setListenDevicesPollingSkip: () => {},
// };
// TransportNodeHid.setListenDevicesDebounce(200);
/*
TransportNodeHid.setListenDevicesDebug((msg, ...args) => {
console.log(msg);
Expand Down Expand Up @@ -50,7 +49,7 @@ const ledgerObserver = {
next: async ({ device, type }) => {
if (device) {
if (type === 'add') {
if (process.platform === 'darwin' || await isInsideLedgerApp(device.path)) {
if (process.platform !== 'linux' || await isInsideLedgerApp(device.path)) {
ledgerPath = device.path;
win.send({ event: 'ledgerConnected', value: null });
}
Expand Down
27 changes: 20 additions & 7 deletions app/src/main.js
Expand Up @@ -3,6 +3,7 @@ import electronLocalshortcut from 'electron-localshortcut'; // eslint-disable-li
import { autoUpdater } from 'electron-updater'; // eslint-disable-line import/no-extraneous-dependencies
import path from 'path';
import storage from 'electron-json-storage'; // eslint-disable-line import/no-extraneous-dependencies
import fp from 'find-free-port';
import win from './modules/win';
import './styles.dialog.css';
// import localeHandler from './modules/localeHandler';
Expand All @@ -11,6 +12,8 @@ import updateChecker from './modules/autoUpdater';
require('babel-polyfill'); // eslint-disable-line import/no-extraneous-dependencies
require('./ledger');

const defaultServerPort = 3000;

const checkForUpdates = updateChecker({
autoUpdater,
dialog: electron.dialog,
Expand All @@ -20,15 +23,21 @@ const checkForUpdates = updateChecker({
});

const { app, ipcMain } = electron;

let appIsReady = false;

const createWindow = (err, port) => {
if (err) {
throw new Error(err);
}
win.create({
electron, path, electronLocalshortcut, storage, checkForUpdates, port,
});
};

app.on('ready', () => {
appIsReady = true;
win.create({
electron, path, electronLocalshortcut, storage, checkForUpdates,
});

fp(defaultServerPort, createWindow);
});

app.on('window-all-closed', () => {
Expand All @@ -47,9 +56,7 @@ app.on('activate', () => {
// sometimes, the event is triggered before app.on('ready', ...)
// then creating new windows will fail
if (win.browser === null && appIsReady) {
win.create({
electron, path, electronLocalshortcut, storage, checkForUpdates,
});
fp(defaultServerPort, createWindow);
}
});

Expand Down Expand Up @@ -90,6 +97,12 @@ ipcMain.on('proxyCredentialsEntered', (event, username, password) => {
global.myTempFunction(username, password);
});


// ipcMain.on('ledgerConnected', () => {
// console.log('ledgerConnected');
// store.dispatch({ type: actionTypes.connectHardwareWallet });
// });

// ToDo - enable this feature when it is implemented in the new design
// ipcMain.on('set-locale', (event, locale) => {
// const langCode = locale.substr(0, 2);
Expand Down
17 changes: 12 additions & 5 deletions app/src/modules/win.js
@@ -1,13 +1,19 @@
import localeHandler from './localeHandler';
import menu from './../menu';
import process from './process';
import server from '../../server';

const win = {
browser: null,
eventStack: [],
init: ({ electron, path, electronLocalshortcut }) => {
init: ({
electron, path, electronLocalshortcut, port,
}) => {
const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize;
const { BrowserWindow } = electron;

const url = server.init(port);

win.browser = new BrowserWindow({
width: width > 1680 ? 1680 : width,
height: height > 1050 ? 1050 : height,
Expand All @@ -28,16 +34,18 @@ const win = {
win.browser.webContents.toggleDevTools();
});

win.browser.loadURL(`file://${__dirname}/index.html`);
win.browser.loadURL(url);
},


create: ({ // eslint-disable-line max-statements
electron, path, electronLocalshortcut, storage, checkForUpdates,
electron, path, electronLocalshortcut, storage, checkForUpdates, port,
}) => {
const { Menu } = electron;

win.init({ electron, path, electronLocalshortcut });
win.init({
electron, path, electronLocalshortcut, port,
});
localeHandler.send({ storage });

win.browser.on('blur', () => win.browser.webContents.send('blur'));
Expand Down Expand Up @@ -118,4 +126,3 @@ const sendEventsFromEventStack = () => {


export default win;

8 changes: 7 additions & 1 deletion app/src/modules/win.test.js
Expand Up @@ -2,6 +2,7 @@ import { expect } from 'chai'; // eslint-disable-line import/no-extraneous-depen
import { spy, mock } from 'sinon'; // eslint-disable-line import/no-extraneous-dependencies
import win from './win';
import process from './process';
import server from '../../server';

describe('Electron Browser Window Wrapper', () => {
const callbacks = {};
Expand Down Expand Up @@ -41,11 +42,15 @@ describe('Electron Browser Window Wrapper', () => {
},
app: { getName: () => ('Lisk Hub'), getVersion: () => ('some version') },
};
const url = 'http://localhost:8080/';

let processMock;
let serverMock;

beforeEach(() => {
processMock = mock(process);
serverMock = mock(server);
serverMock.expects('init').returns(url);
});


Expand All @@ -55,6 +60,7 @@ describe('Electron Browser Window Wrapper', () => {
win.eventStack.length = 0;
events.length = 0;
processMock.restore();
serverMock.restore();
});

describe('Init', () => {
Expand All @@ -64,7 +70,7 @@ describe('Electron Browser Window Wrapper', () => {
expect(win.browser.webPreferences.preload).to.equal('test');
expect(win.browser.center).to.equal(true);
expect(win.browser.devtools).to.equal(true);
expect(win.browser.loadURL).to.have.been.calledWith(`file://${__dirname}/index.html`);
expect(win.browser.loadURL).to.have.been.calledWith(url);
});

it('Creates the window of maximum size possible size on < 1680X1050 display', () => {
Expand Down
14 changes: 13 additions & 1 deletion config/setupJest.js
Expand Up @@ -8,6 +8,8 @@ import sinonStubPromise from 'sinon-stub-promise';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import i18next from 'i18next';
import ReactPiwik from 'react-piwik';
import crypto from 'crypto';
// TODO remove next line after upgrading node version to at least 7
import 'es7-object-polyfill';

Expand Down Expand Up @@ -46,6 +48,17 @@ Object.defineProperty(window, 'localStorage', {
value: localStorageMock,
});

Object.defineProperty(window, 'crypto', {
value: {
getRandomValues: arr => crypto.randomBytes(arr.length),
},
});

ReactPiwik.push = () => {};
ReactPiwik.trackingEvent = () => {};
sinon.stub(ReactPiwik.prototype, 'connectToHistory').callsFake(() => 1);
sinon.stub(ReactPiwik.prototype, 'initPiwik').callsFake(() => {});

// https://github.com/nkbt/react-copy-to-clipboard/issues/20#issuecomment-414065452
// Polyfill window prompts to always confirm. Needed for react-copy-to-clipboard to work.
global.prompt = () => true;
Expand All @@ -60,4 +73,3 @@ const getSelection = () => ({
});
window.getSelection = getSelection;
document.getSelection = getSelection;

2 changes: 1 addition & 1 deletion config/webpack.config.js
Expand Up @@ -38,7 +38,7 @@ module.exports = {
},
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
test: /\.(eot|svg|ttf|woff|woff2|otf)$/,
exclude: [/images/],
options: {
name: '[path][name]-[hash:6].[ext]',
Expand Down

0 comments on commit 0c2e33a

Please sign in to comment.