Skip to content

Commit

Permalink
Merge branch 'development' into 1887-storing-btc-account
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed May 9, 2019
2 parents 91881f6 + 417108a commit c68eaaa
Show file tree
Hide file tree
Showing 70 changed files with 1,213 additions and 348 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Expand Up @@ -27,6 +27,7 @@
"rules": {
"jest/no-focused-tests": "error",
"prefer-destructuring": "off",
"prefer-object-spread": 2,
"func-names": "off",
"global-require": "off",
"new-cap": ["error", {
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
@@ -1,6 +1,6 @@
{
"name": "lisk-hub",
"version": "1.16.0-rc.1",
"version": "1.16.0",
"description": "Lisk Hub",
"main": "./build/main.js",
"author": {
Expand Down
7 changes: 7 additions & 0 deletions app/src/hwManager.js
Expand Up @@ -34,6 +34,13 @@ export const addConnectedDevices = (device) => {
win.send({ event: 'hwDeviceListChanged', value: connectedDevices });
};

export const updateConnectedDevices = (device) => {
logDebug('Updating device', device);
const deviceIndex = connectedDevices.findIndex(d => d.path === device.path);
connectedDevices[deviceIndex] = device;
win.send({ event: 'hwDeviceListChanged', value: connectedDevices });
};

export const removeConnectedDeviceByID = (deviceId) => {
logDebug('Removing device with id: ', deviceId);
connectedDevices.some((device, index) =>
Expand Down
48 changes: 25 additions & 23 deletions app/src/ledger.js
@@ -1,4 +1,4 @@
import { app } from 'electron'; // eslint-disable-line import/no-extraneous-dependencies
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 TransportNodeHid from '@ledgerhq/hw-transport-node-hid'; // eslint-disable-line import/no-extraneous-dependencies
Expand All @@ -7,6 +7,8 @@ import {
HWDevice,
addConnectedDevices,
removeConnectedDeviceByPath,
getDeviceById,
updateConnectedDevices,
} from './hwManager';

import { createCommand, isValidAddress } from './utils';
Expand Down Expand Up @@ -40,22 +42,9 @@ const getLedgerAccount = (index = 0) => {
return ledgerAccount;
};

const isInsideLedgerApp = async (path) => {
try {
const transport = await TransportNodeHid.open(path);
const liskLedger = new DposLedger(transport);
const ledgerAccount = getLedgerAccount(0);
const liskAccount = await liskLedger.getPubKey(ledgerAccount);
transport.close();
return isValidAddress(liskAccount.address);
} catch (e) {
return false;
}
};

const createLedgerHWDevice = (liskAccount, path) =>
new HWDevice(
liskAccount.publicKey.substring(0, 10),
Math.floor(Math.random() * 1e5) + 1,
null,
'Ledger Nano S',
path,
Expand All @@ -76,18 +65,22 @@ const getLiskAccount = async (path) => {
}
};

const isInsideLedgerApp = async (path) => {
const liskAccount = await getLiskAccount(path);
if (liskAccount) return isValidAddress(liskAccount.address);
return false;
};

const ledgerObserver = {
// eslint-disable-next-line max-statements
next: async ({ device, type }) => {
if (device) {
if (type === 'add') {
if (process.platform !== 'linux' || await isInsideLedgerApp(device.path)) {
const liskAccount = await getLiskAccount(device.path);
const ledgerDevice = createLedgerHWDevice(liskAccount, device.path);
addConnectedDevices(ledgerDevice);
hwDevice = ledgerDevice;
win.send({ event: 'hwConnected', value: { model: ledgerDevice.model } });
}
if (type === 'add' && process.platform !== 'linux') {
const ledgerDevice = createLedgerHWDevice(device.path);
ledgerDevice.openApp = await isInsideLedgerApp(device.path);
addConnectedDevices(ledgerDevice);
hwDevice = ledgerDevice;
win.send({ event: 'hwConnected', value: { model: ledgerDevice.model } });
} else if (type === 'remove') {
if (hwDevice) {
removeConnectedDeviceByPath(hwDevice.path);
Expand All @@ -99,6 +92,14 @@ const ledgerObserver = {
},
};

ipcMain.on('checkLedger', async (event, { id }) => {
const ledgerDevice = getDeviceById(id);
ledgerDevice.openApp = await isInsideLedgerApp(ledgerDevice.path);
updateConnectedDevices(ledgerDevice);
hwDevice = ledgerDevice;
win.send({ event: 'checkLedger.done' });
});

let observableListen = null;
const syncDevices = () => {
try {
Expand All @@ -109,6 +110,7 @@ const syncDevices = () => {
}
};
syncDevices();

app.on('will-quit', () => {
if (observableListen) {
observableListen.unsubscribe();
Expand Down
2 changes: 1 addition & 1 deletion app/src/modules/autoUpdater.test.js
Expand Up @@ -157,7 +157,7 @@ describe('autoUpdater', () => {
});

it('should download the update if update is available and the "Update" button was pressed', () => {
const newPrams = Object.assign({}, params, { electron });
const newPrams = { ...params, electron };
autoUpdater(newPrams);
callbacks['update-available']({ version });
clock.tick(1001);
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.config.react.js
Expand Up @@ -50,7 +50,7 @@ const headCssLoader = {
modules: false,
},
};
const headCssLoadersConfig = Object.assign({}, headCssLoader);
const headCssLoadersConfig = { ...headCssLoader };

const cssLoadersConfig = {
fallback: 'style-loader',
Expand Down
14 changes: 11 additions & 3 deletions i18n/locales/en/common.json
Expand Up @@ -98,7 +98,9 @@
"Confirm your passphrase": "Confirm your passphrase",
"Confirmation in the next step": "Confirmation in the next step",
"Confirmations": "Confirmations",
"Connect": "Connect",
"Connect your Hardware Wallet": "Connect your Hardware Wallet",
"Connected": "Connected",
"Connected to ": "Connected to ",
"Connected to:": "Connected to:",
"Connecting to network": "Connecting to network",
Expand Down Expand Up @@ -183,6 +185,7 @@
"For longer passphrases, simply paste it in the first input field.": "For longer passphrases, simply paste it in the first input field.",
"For more information refer to our ": "For more information refer to our ",
"Forged": "Forged",
"Found several devices, choose the one you’d like to access": "Found several devices, choose the one you’d like to access",
"Get passphrase": "Get passphrase",
"Get to your Dashboard": "Get to your Dashboard",
"Give feedback about this feature": "Give feedback about this feature",
Expand Down Expand Up @@ -211,7 +214,7 @@
"I have read and agree to the Terms of Use": "I have read and agree to the Terms of Use",
"I understand": "I understand",
"ID already added to bookmarks": "ID already added to bookmarks",
"IP or domain address of a node": "IP or domain address of a node",
"If you’re not sure how to do this please follow the": "If you’re not sure how to do this please follow the",
"In": "In",
"Include your operating system and screen resolution in your report": "Include your operating system and screen resolution in your report",
"Incoming": "Incoming",
Expand Down Expand Up @@ -269,7 +272,7 @@
"Logout": "Logout",
"Look at your Ledger for confirmation": "Look at your Ledger for confirmation",
"Look at your Trezor %s for completing the action": "Look at your Trezor %s for completing the action",
"Looking for a device": "Looking for a device",
"Looking for a device...": "Looking for a device...",
"Mainnet": "Mainnet",
"Market": "Market",
"Max": "Max",
Expand Down Expand Up @@ -309,6 +312,7 @@
"Note: After registration completes,": "Note: After registration completes,",
"Nothing to change – already voted/unvoted": "Nothing to change – already voted/unvoted",
"OR": "OR",
"Official guidelines": "Official guidelines",
"Ok": "Ok",
"Okay": "Okay",
"On your dashboard": "On your dashboard",
Expand Down Expand Up @@ -393,6 +397,7 @@
"See all transactions": "See all transactions",
"See more": "See more",
"Select all": "Select all",
"Select device": "Select device",
"Select the missing words to confirm": "Select the missing words to confirm",
"Selection": "Selection",
"Send": "Send",
Expand Down Expand Up @@ -423,6 +428,7 @@
"Sign a message": "Sign a message",
"Sign back in": "Sign back in",
"Sign in": "Sign in",
"Sign in with a Hardware Wallet": "Sign in with a Hardware Wallet",
"Sign in with a Passphrase": "Sign in with a Passphrase",
"Simply scan the QR code using the Lisk Mobile app or any other QR code reader": "Simply scan the QR code using the Lisk Mobile app or any other QR code reader",
"Since Last Login": "Since Last Login",
Expand Down Expand Up @@ -485,8 +491,8 @@
"Try using menu for navigation.": "Try using menu for navigation.",
"Type": "Type",
"Type at least 3 characters": "Type at least 3 characters",
"Unable to connect to the node": "Unable to connect to the node",
"Unable to connect to the node, no response from the server.": "Unable to connect to the node, no response from the server.",
"Unable to connect to the node, please check the address and try again": "Unable to connect to the node, please check the address and try again",
"Unable to detect the communication layer with your Hardware Wallet": "Unable to detect the communication layer with your Hardware Wallet",
"Unable to detect the communication layer. Is ledger connected? Is Fido U2F Extension Installed?": "Unable to detect the communication layer. Is ledger connected? Is Fido U2F Extension Installed?",
"Undo": "Undo",
Expand Down Expand Up @@ -580,6 +586,7 @@
"checking availability": "checking availability",
"for full access": "for full access",
"from": "from",
"ie. 192.168.0.1": "ie. 192.168.0.1",
"if the problem persists": "if the problem persists",
"missed": "missed",
"or": "or",
Expand All @@ -589,6 +596,7 @@
"{{count}} delegate(s) selected to unvote_plural": "{{count}} delegates selected to unvote",
"{{count}} delegate(s) selected to vote": "{{count}} delegate selected to vote",
"{{count}} delegate(s) selected to vote_plural": "{{count}} delegates selected to vote",
"{{deviceModel}} connected! Open the Lisk app on the device": "{{deviceModel}} connected! Open the Lisk app on the device",
"{{fee}} LSK": "{{fee}} LSK",
"{{length}} bytes left": "{{length}} bytes left",
"{{length}} extra characters": "{{length}} extra characters",
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Expand Up @@ -19,6 +19,8 @@ module.exports = {
'src/store/reducers/liskService.test.js',
'src/store/middlewares/socket.test.js',
'src/store/middlewares/peers.test.js',
'src/components/registerV2/registerV2.test.js',
'src/components/headerV2/headerV2.test.js',
],
verbose: false,
cache: false,
Expand Down Expand Up @@ -127,6 +129,8 @@ module.exports = {
'src/components/hwWallet/trezorLogin.js',
'src/components/loginV2/loginV2.js',
'src/utils/hwWallet.js',
'src/components/headerV2/headerV2.js',
'src/components/registerV2/registerV2.js',
],
coverageThreshold: {
global: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "lisk-hub",
"version": "1.16.0-rc.1",
"version": "1.16.0",
"description": "Lisk Hub",
"homepage": "https://github.com/LiskHQ/lisk-hub",
"bugs": "https://github.com/LiskHQ/lisk-hub/issues",
Expand Down
12 changes: 12 additions & 0 deletions src/actions/hwWallets.js
@@ -0,0 +1,12 @@
import actionTypes from '../constants/actions';

/**
* An action to dispatch a device list to HwWallets
*
*/
export const updateDeviceList = data => ({
data,
type: actionTypes.deviceListUpdated,
});

export default updateDeviceList;
17 changes: 17 additions & 0 deletions src/actions/hwWallets.test.js
@@ -0,0 +1,17 @@
import { updateDeviceList } from './hwWallets';
import actionTypes from '../constants/actions';

describe('hwWallet Actions', () => {
it(`Should dispatch ${actionTypes.deviceListUpdated} with deviceList`, () => {
const data = [
{ deviceId: 1, openApp: false, model: 'Ledger' },
{ deviceId: 2, model: 'Trezor' },
{ deviceId: 3, openApp: true, model: 'Ledger' },
];
const expectedAction = {
data,
type: actionTypes.deviceListUpdated,
};
expect(updateDeviceList(data)).toEqual(expectedAction);
});
});
4 changes: 2 additions & 2 deletions src/actions/peers.js
Expand Up @@ -12,13 +12,13 @@ import { errorToastDisplayed } from './toaster';
import { networkSet } from './network';

const peerSet = (data, config) => ({
data: Object.assign({
data: {
passphrase: data.passphrase,
publicKey: data.publicKey,
liskAPIClient: new Lisk.APIClient(config.nodes, { nethash: config.nethash }),
options: config,
loginType: data.loginType,
}),
},
type: actionTypes.liskAPIClientSet,
});

Expand Down
3 changes: 3 additions & 0 deletions src/assets/images/icons-v2/icon-warning.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/assets/images/icons-v2/icon_ledger_device.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/assets/images/icons-v2/icon_trezor_device.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c68eaaa

Please sign in to comment.