From 556c7527c382a867afb1b6c3b938a16b02fd6eb0 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 12 Sep 2018 10:53:39 +0200 Subject: [PATCH 01/25] Added covergae folder --- jest.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jest.config.js b/jest.config.js index d7e1c86a..9391dd0d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,6 @@ module.exports = { rootDir: './src', + coverageDirectory: 'coverage/', collectCoverage: true, testURL: 'http://localhost', modulePathIgnorePatterns: [ From 2e5d12428b162dd65e8e270843113223083cb493 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 12 Sep 2018 10:54:03 +0200 Subject: [PATCH 02/25] Added format utils tests --- src/utils/__tests__/formatUtils.test.js | 48 +++++++++++++++++++++++++ src/utils/formatUtils.js | 6 ++-- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/utils/__tests__/formatUtils.test.js diff --git a/src/utils/__tests__/formatUtils.test.js b/src/utils/__tests__/formatUtils.test.js new file mode 100644 index 00000000..b1c01d0a --- /dev/null +++ b/src/utils/__tests__/formatUtils.test.js @@ -0,0 +1,48 @@ +import * as formatUtils from '../formatUtils'; + +describe('format utils', () => { + it('formatAmount', () => { + const input = [ + { amount: 0, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } }, + { amount: 0.5, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } }, + { amount: 1, coinInfo: { isBitcoin: false, shortcut: 'eth' } }, + { amount: 99999, coinInfo: { isBitcoin: false, currencyUnits: 'tau' } }, + ]; + + input.forEach((entry) => { + expect(formatUtils.formatAmount(entry.amount, entry.coinInfo)).toMatchSnapshot(); + }); + }); + + it('formatTime', () => { + const input = [0, 1, 2, 100, 999]; + + input.forEach((entry) => { + expect(formatUtils.formatTime(entry)).toMatchSnapshot(); + }); + }); + + it('btckb2satoshib', () => { + const input = [0, 1, 2, 100, 999]; + + input.forEach((entry) => { + expect(formatUtils.btckb2satoshib(entry)).toMatchSnapshot(); + }); + }); + + it('stringToHex', () => { + const input = ['test', '0001', 'test99999']; + + input.forEach((entry) => { + expect(formatUtils.stringToHex(entry)).toMatchSnapshot(); + }); + }); + + it('hexToString', () => { + const input = [0, 'xxxtestSringtestStringaaaaaa', 30303031, 2746573743939393939, -9]; + + input.forEach((entry) => { + expect(formatUtils.hexToString(entry)).toMatchSnapshot(); + }); + }); +}); diff --git a/src/utils/formatUtils.js b/src/utils/formatUtils.js index 982c9afb..986b0ee9 100644 --- a/src/utils/formatUtils.js +++ b/src/utils/formatUtils.js @@ -1,11 +1,9 @@ /* @flow */ - -const currencyUnits: string = 'mbtc2'; - // TODO: chagne currency units +const currencyUnitsConstant: string = 'mbtc2'; -export const formatAmount = (n: number, coinInfo: any): string => { +export const formatAmount = (n: number, coinInfo: any, currencyUnits = currencyUnitsConstant): string => { const amount = (n / 1e8); if (coinInfo.isBitcoin && currencyUnits === 'mbtc' && amount <= 0.1 && n !== 0) { const s = (n / 1e5).toString(); From 84b218ecaa53b3042085520cdfc6301eaf241ea0 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 12 Sep 2018 12:05:14 +0200 Subject: [PATCH 03/25] Added missing device tests --- .../__snapshots__/device.test.js.snap | 10 ++++++++ src/utils/__tests__/device.test.js | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/utils/__tests__/__snapshots__/device.test.js.snap b/src/utils/__tests__/__snapshots__/device.test.js.snap index 70364320..8ce5ffe6 100644 --- a/src/utils/__tests__/__snapshots__/device.test.js.snap +++ b/src/utils/__tests__/__snapshots__/device.test.js.snap @@ -55,3 +55,13 @@ exports[`device utils get version 4`] = `"1"`; exports[`device utils get version 5`] = `"1"`; exports[`device utils get version 6`] = `"T"`; + +exports[`device utils isDisabled 1`] = `false`; + +exports[`device utils isDisabled 2`] = `true`; + +exports[`device utils isWebUSB 1`] = `true`; + +exports[`device utils isWebUSB 2`] = `false`; + +exports[`device utils isWebUSB 3`] = `true`; diff --git a/src/utils/__tests__/device.test.js b/src/utils/__tests__/device.test.js index 6bfdc4c6..e135a151 100644 --- a/src/utils/__tests__/device.test.js +++ b/src/utils/__tests__/device.test.js @@ -38,6 +38,29 @@ describe('device utils', () => { }); }); + it('isWebUSB', () => { + const data = [ + { transport: { version: ['webusb'] } }, + { transport: { version: ['aaaaaa'] } }, + { transport: { version: ['webusb', 'test'] } }, + ]; + + data.forEach((item) => { + expect(dUtils.isWebUSB(item.transport)).toMatchSnapshot(); + }); + }); + + it('isDisabled', () => { + const data = [ + { selectedDevice: { features: null }, devices: [1, 2, 3], transport: { version: ['webusb', 'test'] } }, + { selectedDevice: { features: null }, devices: [], transport: { version: ['test'] } }, + ]; + + data.forEach((item) => { + expect(dUtils.isDisabled(item.selectedDevice, item.devices, item.transport)).toMatchSnapshot(); + }); + }); + it('get version', () => { const deviceMock = [ { }, From 6f9f31a2e4a9a6ac8445718e13c0e2c31dd1f782 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 12 Sep 2018 14:39:33 +0200 Subject: [PATCH 04/25] Ignore window utils --- jest.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jest.config.js b/jest.config.js index 9391dd0d..20d39ad9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,6 +5,7 @@ module.exports = { testURL: 'http://localhost', modulePathIgnorePatterns: [ 'node_modules', + 'utils/windowUtils.js', ], collectCoverageFrom: [ 'utils/**.js', From 1a6c90bec0bdd9b8f2982051ef30256b04be383a Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 12 Sep 2018 14:52:49 +0200 Subject: [PATCH 05/25] Added more unit tests - eth utils --- src/reducers/ModalReducer.js | 1 + .../__snapshots__/ethUtils.test.js.snap | 30 ++++++++++++- .../__snapshots__/formatUtils.test.js.snap | 45 +++++++++++++++++++ src/utils/__tests__/ethUtils.test.js | 44 +++++++++++++++++- 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/utils/__tests__/__snapshots__/formatUtils.test.js.snap diff --git a/src/reducers/ModalReducer.js b/src/reducers/ModalReducer.js index f6e09a51..bd86b456 100644 --- a/src/reducers/ModalReducer.js +++ b/src/reducers/ModalReducer.js @@ -57,6 +57,7 @@ export default function modal(state: State = initialState, action: Action): Stat if (state.opened && action.device.path === state.device.path && action.device.status === 'occupied') { return initialState; } + return state; case DEVICE.DISCONNECT: diff --git a/src/utils/__tests__/__snapshots__/ethUtils.test.js.snap b/src/utils/__tests__/__snapshots__/ethUtils.test.js.snap index 0ffd930d..c95555dd 100644 --- a/src/utils/__tests__/__snapshots__/ethUtils.test.js.snap +++ b/src/utils/__tests__/__snapshots__/ethUtils.test.js.snap @@ -1,5 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`eth utils calcGasPrice 1`] = `"89090990901"`; + exports[`eth utils decimalToHex 1`] = `"0"`; exports[`eth utils decimalToHex 2`] = `"1"`; @@ -8,4 +10,30 @@ exports[`eth utils decimalToHex 3`] = `"2"`; exports[`eth utils decimalToHex 4`] = `"64"`; -exports[`eth utils decimalToHex 5`] = `"3e7"`; +exports[`eth utils decimalToHex 5`] = `"2540be3ff"`; + +exports[`eth utils hexToDecimal 1`] = `"9999999999"`; + +exports[`eth utils hexToDecimal 2`] = `"100"`; + +exports[`eth utils hexToDecimal 3`] = `"2"`; + +exports[`eth utils hexToDecimal 4`] = `"1"`; + +exports[`eth utils hexToDecimal 5`] = `"0"`; + +exports[`eth utils padLeftEven 1`] = `"02540be3ff"`; + +exports[`eth utils sanitizeHex 1`] = `"0x02540be3ff"`; + +exports[`eth utils sanitizeHex 2`] = `"0x01"`; + +exports[`eth utils sanitizeHex 3`] = `"0x02"`; + +exports[`eth utils sanitizeHex 4`] = `"0x0100"`; + +exports[`eth utils sanitizeHex 5`] = `null`; + +exports[`eth utils strip 1`] = `""`; + +exports[`eth utils strip 2`] = `"02540be3ff"`; diff --git a/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap b/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap new file mode 100644 index 00000000..c9eab582 --- /dev/null +++ b/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`format utils btckb2satoshib 1`] = `0`; + +exports[`format utils btckb2satoshib 2`] = `100000`; + +exports[`format utils btckb2satoshib 3`] = `200000`; + +exports[`format utils btckb2satoshib 4`] = `10000000`; + +exports[`format utils btckb2satoshib 5`] = `99900000`; + +exports[`format utils formatAmount 1`] = `"0 btc"`; + +exports[`format utils formatAmount 2`] = `"5e-9 btc"`; + +exports[`format utils formatAmount 3`] = `"1e-8 eth"`; + +exports[`format utils formatAmount 4`] = `"0.00099999 undefined"`; + +exports[`format utils formatTime 1`] = `"No time estimate"`; + +exports[`format utils formatTime 2`] = `"1 minutes"`; + +exports[`format utils formatTime 3`] = `"2 minutes"`; + +exports[`format utils formatTime 4`] = `"1 hour 40 minutes"`; + +exports[`format utils formatTime 5`] = `"16 hours 39 minutes"`; + +exports[`format utils hexToString 1`] = `""`; + +exports[`format utils hexToString 2`] = `"ªªª"`; + +exports[`format utils hexToString 3`] = `""`; + +exports[`format utils hexToString 4`] = `""`; + +exports[`format utils hexToString 5`] = `""`; + +exports[`format utils stringToHex 1`] = `"0074006500730074"`; + +exports[`format utils stringToHex 2`] = `"0030003000300031"`; + +exports[`format utils stringToHex 3`] = `"007400650073007400390039003900390039"`; diff --git a/src/utils/__tests__/ethUtils.test.js b/src/utils/__tests__/ethUtils.test.js index 3ff6e2ea..09238617 100644 --- a/src/utils/__tests__/ethUtils.test.js +++ b/src/utils/__tests__/ethUtils.test.js @@ -1,11 +1,53 @@ +import BigNumber from 'bignumber.js'; import * as ethUtils from '../ethUtils'; describe('eth utils', () => { it('decimalToHex', () => { - const input = [0, 1, 2, 100, 999]; + const input = [0, 1, 2, 100, 9999999999]; input.forEach((entry) => { expect(ethUtils.decimalToHex(entry)).toMatchSnapshot(); }); }); + + it('hexToDecimal', () => { + const input = ['2540be3ff', '64', '2', '1', '0']; + + input.forEach((entry) => { + expect(ethUtils.hexToDecimal(entry)).toMatchSnapshot(); + }); + }); + + it('padLeftEven', () => { + const input = ['2540be3ff']; + + input.forEach((entry) => { + expect(ethUtils.padLeftEven(entry)).toMatchSnapshot(); + }); + }); + + it('sanitizeHex', () => { + const input = ['0x2540be3ff', '1', '2', '100', 999]; + + input.forEach((entry) => { + expect(ethUtils.sanitizeHex(entry)).toMatchSnapshot(); + }); + }); + + + it('strip', () => { + const input = ['0x', '0x2540be3ff']; + + input.forEach((entry) => { + expect(ethUtils.strip(entry)).toMatchSnapshot(); + }); + }); + + it('calcGasPrice', () => { + const input = [{ price: new BigNumber(9898998989), limit: '9' }]; + + input.forEach((entry) => { + expect(ethUtils.calcGasPrice(entry.price, entry.limit)).toMatchSnapshot(); + }); + }); }); From 7b22a965b6e9f2a5b5978eade2cc8aa84cfbefa8 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 12 Sep 2018 14:55:12 +0200 Subject: [PATCH 06/25] 100% coverage in eth utils --- src/utils/__tests__/__snapshots__/ethUtils.test.js.snap | 6 ++++++ src/utils/__tests__/ethUtils.test.js | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utils/__tests__/__snapshots__/ethUtils.test.js.snap b/src/utils/__tests__/__snapshots__/ethUtils.test.js.snap index c95555dd..f5b70d96 100644 --- a/src/utils/__tests__/__snapshots__/ethUtils.test.js.snap +++ b/src/utils/__tests__/__snapshots__/ethUtils.test.js.snap @@ -22,6 +22,8 @@ exports[`eth utils hexToDecimal 4`] = `"1"`; exports[`eth utils hexToDecimal 5`] = `"0"`; +exports[`eth utils hexToDecimal 6`] = `"null"`; + exports[`eth utils padLeftEven 1`] = `"02540be3ff"`; exports[`eth utils sanitizeHex 1`] = `"0x02540be3ff"`; @@ -34,6 +36,10 @@ exports[`eth utils sanitizeHex 4`] = `"0x0100"`; exports[`eth utils sanitizeHex 5`] = `null`; +exports[`eth utils sanitizeHex 6`] = `""`; + exports[`eth utils strip 1`] = `""`; exports[`eth utils strip 2`] = `"02540be3ff"`; + +exports[`eth utils strip 3`] = `"02540be3ff"`; diff --git a/src/utils/__tests__/ethUtils.test.js b/src/utils/__tests__/ethUtils.test.js index 09238617..07bd1250 100644 --- a/src/utils/__tests__/ethUtils.test.js +++ b/src/utils/__tests__/ethUtils.test.js @@ -11,7 +11,7 @@ describe('eth utils', () => { }); it('hexToDecimal', () => { - const input = ['2540be3ff', '64', '2', '1', '0']; + const input = ['2540be3ff', '64', '2', '1', '0', '']; input.forEach((entry) => { expect(ethUtils.hexToDecimal(entry)).toMatchSnapshot(); @@ -27,7 +27,7 @@ describe('eth utils', () => { }); it('sanitizeHex', () => { - const input = ['0x2540be3ff', '1', '2', '100', 999]; + const input = ['0x2540be3ff', '1', '2', '100', 999, '']; input.forEach((entry) => { expect(ethUtils.sanitizeHex(entry)).toMatchSnapshot(); @@ -36,7 +36,7 @@ describe('eth utils', () => { it('strip', () => { - const input = ['0x', '0x2540be3ff']; + const input = ['0x', '0x2540be3ff', '2540be3ff']; input.forEach((entry) => { expect(ethUtils.strip(entry)).toMatchSnapshot(); From 466a0da0959cd5baea1a93d1cdb2005512f9f0db Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 12 Sep 2018 16:01:48 +0200 Subject: [PATCH 07/25] Added more tests - format utils --- .flowconfig | 2 +- .../__snapshots__/formatUtils.test.js.snap | 18 +++++++++--------- src/utils/__tests__/formatUtils.test.js | 7 ++++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.flowconfig b/.flowconfig index b28be239..a3d33db0 100644 --- a/.flowconfig +++ b/.flowconfig @@ -8,7 +8,7 @@ .*/node_modules/react-router/.* .*/node_modules/react-router-redux/.* .*/_old/.* -.*/src/solidity/.* +.*/public/.* [libs] ./src/flowtype/npm/redux_v3.x.x.js diff --git a/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap b/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap index c9eab582..c7a37e6c 100644 --- a/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap +++ b/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap @@ -12,11 +12,13 @@ exports[`format utils btckb2satoshib 5`] = `99900000`; exports[`format utils formatAmount 1`] = `"0 btc"`; -exports[`format utils formatAmount 2`] = `"5e-9 btc"`; +exports[`format utils formatAmount 2`] = `"10 mBTC"`; -exports[`format utils formatAmount 3`] = `"1e-8 eth"`; +exports[`format utils formatAmount 3`] = `"0.000005 mBTC"`; -exports[`format utils formatAmount 4`] = `"0.00099999 undefined"`; +exports[`format utils formatAmount 4`] = `"1e-8 eth"`; + +exports[`format utils formatAmount 5`] = `"0.00099999 undefined"`; exports[`format utils formatTime 1`] = `"No time estimate"`; @@ -28,15 +30,13 @@ exports[`format utils formatTime 4`] = `"1 hour 40 minutes"`; exports[`format utils formatTime 5`] = `"16 hours 39 minutes"`; -exports[`format utils hexToString 1`] = `""`; +exports[`format utils formatTime 6`] = `"45 minutes"`; -exports[`format utils hexToString 2`] = `"ªªª"`; +exports[`format utils hexToString 1`] = `"test"`; -exports[`format utils hexToString 3`] = `""`; +exports[`format utils hexToString 2`] = `"0001"`; -exports[`format utils hexToString 4`] = `""`; - -exports[`format utils hexToString 5`] = `""`; +exports[`format utils hexToString 3`] = `"test99999"`; exports[`format utils stringToHex 1`] = `"0074006500730074"`; diff --git a/src/utils/__tests__/formatUtils.test.js b/src/utils/__tests__/formatUtils.test.js index b1c01d0a..e2bc4593 100644 --- a/src/utils/__tests__/formatUtils.test.js +++ b/src/utils/__tests__/formatUtils.test.js @@ -4,18 +4,19 @@ describe('format utils', () => { it('formatAmount', () => { const input = [ { amount: 0, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } }, + { amount: 1000000, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } }, { amount: 0.5, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } }, { amount: 1, coinInfo: { isBitcoin: false, shortcut: 'eth' } }, { amount: 99999, coinInfo: { isBitcoin: false, currencyUnits: 'tau' } }, ]; input.forEach((entry) => { - expect(formatUtils.formatAmount(entry.amount, entry.coinInfo)).toMatchSnapshot(); + expect(formatUtils.formatAmount(entry.amount, entry.coinInfo, entry.coinInfo.currencyUnits)).toMatchSnapshot(); }); }); it('formatTime', () => { - const input = [0, 1, 2, 100, 999]; + const input = [0, 1, 2, 100, 999, 45]; input.forEach((entry) => { expect(formatUtils.formatTime(entry)).toMatchSnapshot(); @@ -39,7 +40,7 @@ describe('format utils', () => { }); it('hexToString', () => { - const input = [0, 'xxxtestSringtestStringaaaaaa', 30303031, 2746573743939393939, -9]; + const input = ['0074006500730074', '0030003000300031', '007400650073007400390039003900390039']; input.forEach((entry) => { expect(formatUtils.hexToString(entry)).toMatchSnapshot(); From 56f5790cc02c983e891a65bbf93a1978148e9c4b Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 12 Sep 2018 16:40:59 +0200 Subject: [PATCH 08/25] Added webpack flwo plugin, fixed missing dep --- package.json | 1 + src/views/Wallet/components/LeftNavigation/index.js | 2 -- webpack/dev.babel.js | 3 +++ webpack/local.babel.js | 2 ++ webpack/production.babel.js | 2 ++ yarn.lock | 4 ++++ 6 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4001c4d8..2f7113b0 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "ethereumjs-tx": "^1.3.3", "ethereumjs-units": "^0.2.0", "ethereumjs-util": "^5.1.4", + "flow-webpack-plugin": "^1.2.0", "hdkey": "^0.8.0", "html-webpack-plugin": "^3.2.0", "npm-run-all": "^4.1.3", diff --git a/src/views/Wallet/components/LeftNavigation/index.js b/src/views/Wallet/components/LeftNavigation/index.js index dc57e112..15d2821f 100644 --- a/src/views/Wallet/components/LeftNavigation/index.js +++ b/src/views/Wallet/components/LeftNavigation/index.js @@ -2,7 +2,6 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import colors from 'config/colors'; import Icon from 'components/Icon'; -import Sticky from 'react-sticky-el'; import icons from 'config/icons'; import { TransitionGroup, CSSTransition } from 'react-transition-group'; import styled from 'styled-components'; @@ -178,7 +177,6 @@ class LeftNavigation extends Component { - ); } diff --git a/webpack/dev.babel.js b/webpack/dev.babel.js index 377bb513..484f9e33 100644 --- a/webpack/dev.babel.js +++ b/webpack/dev.babel.js @@ -1,6 +1,8 @@ import webpack from 'webpack'; import HtmlWebpackPlugin from 'html-webpack-plugin'; +import FlowWebpackPlugin from 'flow-webpack-plugin'; + import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; import { @@ -89,6 +91,7 @@ module.exports = { hints: false, }, plugins: [ + new FlowWebpackPlugin(), new HtmlWebpackPlugin({ chunks: ['index'], template: `${SRC}index.html`, diff --git a/webpack/local.babel.js b/webpack/local.babel.js index c62b2e08..93e9d5cb 100644 --- a/webpack/local.babel.js +++ b/webpack/local.babel.js @@ -2,6 +2,7 @@ import webpack from 'webpack'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import CopyWebpackPlugin from 'copy-webpack-plugin'; +import FlowWebpackPlugin from 'flow-webpack-plugin'; import { TREZOR_CONNECT_ROOT, @@ -113,6 +114,7 @@ module.exports = { hints: false, }, plugins: [ + new FlowWebpackPlugin(), new HtmlWebpackPlugin({ chunks: ['index'], template: `${SRC}index.html`, diff --git a/webpack/production.babel.js b/webpack/production.babel.js index 39342d6b..b6ffe396 100644 --- a/webpack/production.babel.js +++ b/webpack/production.babel.js @@ -2,6 +2,7 @@ import webpack from 'webpack'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import CopyWebpackPlugin from 'copy-webpack-plugin'; +import FlowWebpackPlugin from 'flow-webpack-plugin'; import { SRC, BUILD, PUBLIC } from './constants'; module.exports = { @@ -60,6 +61,7 @@ module.exports = { hints: false, }, plugins: [ + new FlowWebpackPlugin(), new HtmlWebpackPlugin({ chunks: ['index'], template: `${SRC}index.html`, diff --git a/yarn.lock b/yarn.lock index 6862c6ee..46ed0785 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4104,6 +4104,10 @@ flow-parser@^0.*: version "0.72.0" resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.72.0.tgz#6c8041e76ac7d0be1a71ce29c00cd1435fb6013c" +flow-webpack-plugin@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/flow-webpack-plugin/-/flow-webpack-plugin-1.2.0.tgz#1958821d16135028e391cad5ee2f3a4fa78197ec" + flush-write-stream@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/flush-write-stream/-/flush-write-stream-1.0.2.tgz#c81b90d8746766f1a609a46809946c45dd8ae417" From a8cf778e23177778dd2108f6b01c92fd8cad9589 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 12 Sep 2018 16:43:08 +0200 Subject: [PATCH 09/25] Fixed undefined in test suite --- src/utils/__tests__/__snapshots__/formatUtils.test.js.snap | 2 +- src/utils/__tests__/formatUtils.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap b/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap index c7a37e6c..448a338a 100644 --- a/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap +++ b/src/utils/__tests__/__snapshots__/formatUtils.test.js.snap @@ -18,7 +18,7 @@ exports[`format utils formatAmount 3`] = `"0.000005 mBTC"`; exports[`format utils formatAmount 4`] = `"1e-8 eth"`; -exports[`format utils formatAmount 5`] = `"0.00099999 undefined"`; +exports[`format utils formatAmount 5`] = `"0.00099999 tau"`; exports[`format utils formatTime 1`] = `"No time estimate"`; diff --git a/src/utils/__tests__/formatUtils.test.js b/src/utils/__tests__/formatUtils.test.js index e2bc4593..eb1d026d 100644 --- a/src/utils/__tests__/formatUtils.test.js +++ b/src/utils/__tests__/formatUtils.test.js @@ -7,7 +7,7 @@ describe('format utils', () => { { amount: 1000000, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } }, { amount: 0.5, coinInfo: { isBitcoin: true, currencyUnits: 'mbtc', shortcut: 'btc' } }, { amount: 1, coinInfo: { isBitcoin: false, shortcut: 'eth' } }, - { amount: 99999, coinInfo: { isBitcoin: false, currencyUnits: 'tau' } }, + { amount: 99999, coinInfo: { isBitcoin: false, shortcut: 'tau' } }, ]; input.forEach((entry) => { From bd86bb22f907c1148cc2f8dc4230ad43a3b3e77c Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 12 Sep 2018 17:12:52 +0200 Subject: [PATCH 10/25] Errors from stylelint as warnings, fixed jest mock --- jest.config.js | 4 ++++ package.json | 1 + src/support/setupJest.js | 1 + src/utils/__tests__/networkUtils.test.js | 15 +++++++++++++++ src/utils/networkUtils.js | 11 ----------- webpack/dev.babel.js | 1 + webpack/local.babel.js | 1 + yarn.lock | 18 +++++++++++++++++- 8 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 src/support/setupJest.js create mode 100644 src/utils/__tests__/networkUtils.test.js diff --git a/jest.config.js b/jest.config.js index 20d39ad9..3017fba1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,6 @@ module.exports = { rootDir: './src', + automock: false, coverageDirectory: 'coverage/', collectCoverage: true, testURL: 'http://localhost', @@ -10,4 +11,7 @@ module.exports = { collectCoverageFrom: [ 'utils/**.js', ], + setupFiles: [ + './support/setupJest.js', + ], }; diff --git a/package.json b/package.json index 2f7113b0..3467d307 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "flow-webpack-plugin": "^1.2.0", "hdkey": "^0.8.0", "html-webpack-plugin": "^3.2.0", + "jest-fetch-mock": "^1.6.5", "npm-run-all": "^4.1.3", "prop-types": "^15.6.2", "raf": "^3.4.0", diff --git a/src/support/setupJest.js b/src/support/setupJest.js new file mode 100644 index 00000000..8e88457e --- /dev/null +++ b/src/support/setupJest.js @@ -0,0 +1 @@ +global.fetch = require('jest-fetch-mock'); \ No newline at end of file diff --git a/src/utils/__tests__/networkUtils.test.js b/src/utils/__tests__/networkUtils.test.js new file mode 100644 index 00000000..190707ce --- /dev/null +++ b/src/utils/__tests__/networkUtils.test.js @@ -0,0 +1,15 @@ +import * as networkUtils from '../networkUtils'; + +describe('network utils', () => { + beforeEach(() => { + fetch.resetMocks(); + }); + + it('httpRequest', () => { + + }); + + it('JSONRequest', () => { + + }); +}); diff --git a/src/utils/networkUtils.js b/src/utils/networkUtils.js index 360168d9..fc29250b 100644 --- a/src/utils/networkUtils.js +++ b/src/utils/networkUtils.js @@ -1,6 +1,5 @@ /* @flow */ - import 'whatwg-fetch'; export const httpRequest = async (url: string, type: string = 'text'): any => { @@ -15,16 +14,6 @@ export const httpRequest = async (url: string, type: string = 'text'): any => { await response.text(); } throw new Error(`${url} ${response.statusText}`); - - - // return fetch(url, { credentials: 'same-origin' }).then((response) => { - // if (response.status === 200) { - - // return response.text().then(result => (json ? JSON.parse(result) : result)); - // } else { - // throw new Error(response.statusText); - // } - // }) }; export const JSONRequest = async (url: string): Promise => { diff --git a/webpack/dev.babel.js b/webpack/dev.babel.js index 484f9e33..9bd1123f 100644 --- a/webpack/dev.babel.js +++ b/webpack/dev.babel.js @@ -48,6 +48,7 @@ module.exports = { { loader: 'stylelint-custom-processor-loader', options: { + emitWarning: true, configPath: '.stylelintrc', }, }, diff --git a/webpack/local.babel.js b/webpack/local.babel.js index 93e9d5cb..db71f539 100644 --- a/webpack/local.babel.js +++ b/webpack/local.babel.js @@ -59,6 +59,7 @@ module.exports = { { loader: 'stylelint-custom-processor-loader', options: { + emitWarning: true, configPath: '.stylelintrc', }, }, diff --git a/yarn.lock b/yarn.lock index 46ed0785..435da204 100644 --- a/yarn.lock +++ b/yarn.lock @@ -255,6 +255,10 @@ version "0.7.0" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd" +"@types/jest@^23.0.0": + version "23.3.2" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.3.2.tgz#07b90f6adf75d42c34230c026a2529e56c249dbb" + "@webassemblyjs/ast@1.5.13": version "1.5.13" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.5.13.tgz#81155a570bd5803a30ec31436bc2c9c0ede38f25" @@ -5330,7 +5334,7 @@ isobject@^3.0.0, isobject@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" -isomorphic-fetch@^2.1.1: +isomorphic-fetch@^2.1.1, isomorphic-fetch@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9" dependencies: @@ -5522,6 +5526,14 @@ jest-environment-node@^23.4.0: jest-mock "^23.2.0" jest-util "^23.4.0" +jest-fetch-mock@^1.6.5: + version "1.6.5" + resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-1.6.5.tgz#178fa1a937ef6f61fb8e8483b6d4602b17e0d96d" + dependencies: + "@types/jest" "^23.0.0" + isomorphic-fetch "^2.2.1" + promise-polyfill "^7.1.1" + jest-get-type@^22.1.0: version "22.4.3" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4" @@ -7711,6 +7723,10 @@ promise-inflight@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3" +promise-polyfill@^7.1.1: + version "7.1.2" + resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-7.1.2.tgz#ab05301d8c28536301622d69227632269a70ca3b" + promise@^7.1.1: version "7.3.1" resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf" From 2cfb955e62449f91c9280d7efffb3342422415f1 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Thu, 13 Sep 2018 13:08:25 +0200 Subject: [PATCH 11/25] Added tests for network utils --- jest.config.js | 1 + package.json | 2 +- .../__snapshots__/networkUtils.test.js.snap | 13 +++++++++++++ src/utils/__tests__/networkUtils.test.js | 12 ++++++++---- 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/utils/__tests__/__snapshots__/networkUtils.test.js.snap diff --git a/jest.config.js b/jest.config.js index 3017fba1..beda6ad6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,6 +7,7 @@ module.exports = { modulePathIgnorePatterns: [ 'node_modules', 'utils/windowUtils.js', + 'utils/promiseUtils.js', ], collectCoverageFrom: [ 'utils/**.js', diff --git a/package.json b/package.json index 3467d307..1fe60c8a 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "styled-components": "^3.3.3", "styled-media-query": "^2.0.2", "styled-normalize": "^8.0.0", - "trezor-connect": "5.0.30", + "trezor-connect": "../connect/src/index.js", "web3": "^0.19.0", "webpack": "^4.16.3", "webpack-bundle-analyzer": "^2.13.1", diff --git a/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap b/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap new file mode 100644 index 00000000..514a0f3d --- /dev/null +++ b/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`network utils JSONRequest ok 1`] = ` +Object { + "test_json": "01234", +} +`; + +exports[`network utils httpRequest json ok response 1`] = ` +Object { + "test_json": "12345", +} +`; diff --git a/src/utils/__tests__/networkUtils.test.js b/src/utils/__tests__/networkUtils.test.js index 190707ce..b5b00116 100644 --- a/src/utils/__tests__/networkUtils.test.js +++ b/src/utils/__tests__/networkUtils.test.js @@ -5,11 +5,15 @@ describe('network utils', () => { fetch.resetMocks(); }); - it('httpRequest', () => { - + it('httpRequest json ok response', async () => { + fetch.mockResponse(JSON.stringify({ test_json: '12345' })); + const result = await networkUtils.httpRequest('/test/', 'json'); + expect(result).toMatchSnapshot(); }); - it('JSONRequest', () => { - + it('JSONRequest ok', async () => { + fetch.mockResponse(JSON.stringify({ test_json: '01234' })); + const result = await networkUtils.JSONRequest('/test/'); + expect(result).toMatchSnapshot(); }); }); From fc9adc95a4cf2ed591d6477bd86935e9a31cf95f Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Thu, 13 Sep 2018 13:34:31 +0200 Subject: [PATCH 12/25] Added more tests --- .../__snapshots__/networkUtils.test.js.snap | 12 +++++-- src/utils/__tests__/networkUtils.test.js | 36 +++++++++++++++++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap b/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap index 514a0f3d..b3339859 100644 --- a/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap +++ b/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap @@ -1,13 +1,21 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`network utils JSONRequest ok 1`] = ` +exports[`network utils JSONRequest 1`] = ` Object { "test_json": "01234", } `; -exports[`network utils httpRequest json ok response 1`] = ` +exports[`network utils JSONRequest error 1`] = `[Error: jsonRequest error: [object Object]]`; + +exports[`network utils httpRequest error (500) 1`] = `[Error: /test/ Internal Server Error]`; + +exports[`network utils httpRequest json ok response binary 1`] = `Promise {}`; + +exports[`network utils httpRequest json ok response json 1`] = ` Object { "test_json": "12345", } `; + +exports[`network utils httpRequest json ok response text 1`] = `Promise {}`; diff --git a/src/utils/__tests__/networkUtils.test.js b/src/utils/__tests__/networkUtils.test.js index b5b00116..8b306c4d 100644 --- a/src/utils/__tests__/networkUtils.test.js +++ b/src/utils/__tests__/networkUtils.test.js @@ -5,15 +5,45 @@ describe('network utils', () => { fetch.resetMocks(); }); - it('httpRequest json ok response', async () => { + it('httpRequest json ok response json', async () => { fetch.mockResponse(JSON.stringify({ test_json: '12345' })); - const result = await networkUtils.httpRequest('/test/', 'json'); + const result = await networkUtils.httpRequest('/http-request-test-response-json/', 'json'); expect(result).toMatchSnapshot(); }); - it('JSONRequest ok', async () => { + it('httpRequest json ok response text', async () => { + fetch.mockResponse(JSON.stringify({ test_json: '12345' })); + const result = networkUtils.httpRequest('/http-request-test-response-text/', 'text'); + expect(result).toMatchSnapshot(); + }); + + it('httpRequest json ok response binary', async () => { + fetch.mockResponse(1); + const result = networkUtils.httpRequest('/http-request-test-response-binary/', 'binary'); + expect(result).toMatchSnapshot(); + }); + + it('httpRequest error (500)', async () => { + fetch.mockResponse(JSON.stringify({ test_json: '12345' }), { status: 500 }); + try { + await networkUtils.httpRequest('/test/', 'json'); + } catch (err) { + expect(err).toMatchSnapshot(); + } + }); + + it('JSONRequest', async () => { fetch.mockResponse(JSON.stringify({ test_json: '01234' })); const result = await networkUtils.JSONRequest('/test/'); expect(result).toMatchSnapshot(); }); + + it('JSONRequest error', async () => { + fetch.mockResponse(JSON.stringify({ test_json: '12345' }), { status: 500 }); + try { + await networkUtils.JSONRequest('/test/', 'json'); + } catch (err) { + expect(err).toMatchSnapshot(); + } + }); }); From be90c9bef990cb9f76237b27c55015b94aa62221 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Thu, 13 Sep 2018 15:44:38 +0200 Subject: [PATCH 13/25] Fixed content-types in mock requests --- .../__tests__/__snapshots__/networkUtils.test.js.snap | 2 +- src/utils/__tests__/networkUtils.test.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap b/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap index b3339859..237c8fbe 100644 --- a/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap +++ b/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap @@ -14,7 +14,7 @@ exports[`network utils httpRequest json ok response binary 1`] = `Promise {}`; exports[`network utils httpRequest json ok response json 1`] = ` Object { - "test_json": "12345", + "test_json": 12345, } `; diff --git a/src/utils/__tests__/networkUtils.test.js b/src/utils/__tests__/networkUtils.test.js index 8b306c4d..a03e5329 100644 --- a/src/utils/__tests__/networkUtils.test.js +++ b/src/utils/__tests__/networkUtils.test.js @@ -6,19 +6,19 @@ describe('network utils', () => { }); it('httpRequest json ok response json', async () => { - fetch.mockResponse(JSON.stringify({ test_json: '12345' })); + fetch.mockResponseOnce('{ "test_json": 12345 }', { status: 200, headers: { 'content-type': 'application/json' } }); const result = await networkUtils.httpRequest('/http-request-test-response-json/', 'json'); expect(result).toMatchSnapshot(); }); it('httpRequest json ok response text', async () => { - fetch.mockResponse(JSON.stringify({ test_json: '12345' })); - const result = networkUtils.httpRequest('/http-request-test-response-text/', 'text'); + fetch.mockResponseOnce('aaaa', { status: 200, headers: { 'content-type': 'text/html' } }); + const result = networkUtils.httpRequest('/http-request-test-response-text/'); expect(result).toMatchSnapshot(); }); it('httpRequest json ok response binary', async () => { - fetch.mockResponse(1); + fetch.mockResponseOnce('{ "id": 1 }', { status: 200, headers: { 'content-type': 'application/octet-stream' } }); const result = networkUtils.httpRequest('/http-request-test-response-binary/', 'binary'); expect(result).toMatchSnapshot(); }); From 4f593d9c5f0d156ce6267be0f111e043aa700006 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Thu, 13 Sep 2018 16:12:48 +0200 Subject: [PATCH 14/25] Removed network utils from testing for now --- jest.config.js | 1 + .../__snapshots__/networkUtils.test.js.snap | 21 -------- src/utils/__tests__/networkUtils.test.js | 49 ------------------- 3 files changed, 1 insertion(+), 70 deletions(-) delete mode 100644 src/utils/__tests__/__snapshots__/networkUtils.test.js.snap delete mode 100644 src/utils/__tests__/networkUtils.test.js diff --git a/jest.config.js b/jest.config.js index beda6ad6..d9c12451 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,6 +8,7 @@ module.exports = { 'node_modules', 'utils/windowUtils.js', 'utils/promiseUtils.js', + 'utils/networkUtils.js', ], collectCoverageFrom: [ 'utils/**.js', diff --git a/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap b/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap deleted file mode 100644 index 237c8fbe..00000000 --- a/src/utils/__tests__/__snapshots__/networkUtils.test.js.snap +++ /dev/null @@ -1,21 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`network utils JSONRequest 1`] = ` -Object { - "test_json": "01234", -} -`; - -exports[`network utils JSONRequest error 1`] = `[Error: jsonRequest error: [object Object]]`; - -exports[`network utils httpRequest error (500) 1`] = `[Error: /test/ Internal Server Error]`; - -exports[`network utils httpRequest json ok response binary 1`] = `Promise {}`; - -exports[`network utils httpRequest json ok response json 1`] = ` -Object { - "test_json": 12345, -} -`; - -exports[`network utils httpRequest json ok response text 1`] = `Promise {}`; diff --git a/src/utils/__tests__/networkUtils.test.js b/src/utils/__tests__/networkUtils.test.js deleted file mode 100644 index a03e5329..00000000 --- a/src/utils/__tests__/networkUtils.test.js +++ /dev/null @@ -1,49 +0,0 @@ -import * as networkUtils from '../networkUtils'; - -describe('network utils', () => { - beforeEach(() => { - fetch.resetMocks(); - }); - - it('httpRequest json ok response json', async () => { - fetch.mockResponseOnce('{ "test_json": 12345 }', { status: 200, headers: { 'content-type': 'application/json' } }); - const result = await networkUtils.httpRequest('/http-request-test-response-json/', 'json'); - expect(result).toMatchSnapshot(); - }); - - it('httpRequest json ok response text', async () => { - fetch.mockResponseOnce('aaaa', { status: 200, headers: { 'content-type': 'text/html' } }); - const result = networkUtils.httpRequest('/http-request-test-response-text/'); - expect(result).toMatchSnapshot(); - }); - - it('httpRequest json ok response binary', async () => { - fetch.mockResponseOnce('{ "id": 1 }', { status: 200, headers: { 'content-type': 'application/octet-stream' } }); - const result = networkUtils.httpRequest('/http-request-test-response-binary/', 'binary'); - expect(result).toMatchSnapshot(); - }); - - it('httpRequest error (500)', async () => { - fetch.mockResponse(JSON.stringify({ test_json: '12345' }), { status: 500 }); - try { - await networkUtils.httpRequest('/test/', 'json'); - } catch (err) { - expect(err).toMatchSnapshot(); - } - }); - - it('JSONRequest', async () => { - fetch.mockResponse(JSON.stringify({ test_json: '01234' })); - const result = await networkUtils.JSONRequest('/test/'); - expect(result).toMatchSnapshot(); - }); - - it('JSONRequest error', async () => { - fetch.mockResponse(JSON.stringify({ test_json: '12345' }), { status: 500 }); - try { - await networkUtils.JSONRequest('/test/', 'json'); - } catch (err) { - expect(err).toMatchSnapshot(); - } - }); -}); From 22e500b144b81c3c7bb73a4bb2915a689611f6ae Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Fri, 14 Sep 2018 12:26:53 +0200 Subject: [PATCH 15/25] Fixed connect dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1fe60c8a..3467d307 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "styled-components": "^3.3.3", "styled-media-query": "^2.0.2", "styled-normalize": "^8.0.0", - "trezor-connect": "../connect/src/index.js", + "trezor-connect": "5.0.30", "web3": "^0.19.0", "webpack": "^4.16.3", "webpack-bundle-analyzer": "^2.13.1", From c9ec9e4438da0b6d6ee48dfcf15e2fe9d38f537a Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Thu, 20 Sep 2018 13:56:24 +0200 Subject: [PATCH 16/25] Added commit hash to footer --- .eslintrc | 3 +++ package.json | 1 + src/components/Footer/index.js | 2 +- webpack/dev.babel.js | 6 +++++- webpack/production.babel.js | 6 ++++++ yarn.lock | 4 ++++ 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index bbe3a8a7..5c87b414 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,6 +4,9 @@ "plugin:flowtype/recommended", "plugin:jest/recommended" ], + "globals": { + "COMMITHASH": true + }, "env": { "browser": true, "jest": true diff --git a/package.json b/package.json index d920fb90..cca0a91d 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "ethereumjs-tx": "^1.3.3", "ethereumjs-units": "^0.2.0", "ethereumjs-util": "^5.1.4", + "git-revision-webpack-plugin": "^3.0.3", "hdkey": "^0.8.0", "html-webpack-plugin": "^3.2.0", "npm-run-all": "^4.1.3", diff --git a/src/components/Footer/index.js b/src/components/Footer/index.js index fa695d98..8f19462c 100644 --- a/src/components/Footer/index.js +++ b/src/components/Footer/index.js @@ -29,7 +29,7 @@ const Copy = styled.div` const Footer = ({ toggle }) => ( - © {getYear(new Date())} + © {getYear(new Date())} SatoshiLabs Terms Show Log diff --git a/webpack/dev.babel.js b/webpack/dev.babel.js index 377bb513..42da5afb 100644 --- a/webpack/dev.babel.js +++ b/webpack/dev.babel.js @@ -1,5 +1,5 @@ import webpack from 'webpack'; - +import GitRevisionPlugin from 'git-revision-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; @@ -7,6 +7,7 @@ import { SRC, BUILD, PORT, PUBLIC, } from './constants'; +const gitRevisionPlugin = new GitRevisionPlugin(); module.exports = { watch: true, @@ -89,6 +90,9 @@ module.exports = { hints: false, }, plugins: [ + new webpack.DefinePlugin({ + COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()), + }), new HtmlWebpackPlugin({ chunks: ['index'], template: `${SRC}index.html`, diff --git a/webpack/production.babel.js b/webpack/production.babel.js index 39342d6b..3761cec3 100644 --- a/webpack/production.babel.js +++ b/webpack/production.babel.js @@ -1,9 +1,12 @@ import webpack from 'webpack'; +import GitRevisionPlugin from 'git-revision-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import CopyWebpackPlugin from 'copy-webpack-plugin'; import { SRC, BUILD, PUBLIC } from './constants'; +const gitRevisionPlugin = new GitRevisionPlugin(); + module.exports = { mode: 'production', entry: { @@ -60,6 +63,9 @@ module.exports = { hints: false, }, plugins: [ + new webpack.DefinePlugin({ + COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()), + }), new HtmlWebpackPlugin({ chunks: ['index'], template: `${SRC}index.html`, diff --git a/yarn.lock b/yarn.lock index 0aeaea58..af3c54fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4519,6 +4519,10 @@ gh-got@^6.0.0: got "^7.0.0" is-plain-obj "^1.1.0" +git-revision-webpack-plugin@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/git-revision-webpack-plugin/-/git-revision-webpack-plugin-3.0.3.tgz#f909949d7851d1039ed530518f73f5d46594e66f" + github-username@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/github-username/-/github-username-4.1.0.tgz#cbe280041883206da4212ae9e4b5f169c30bf417" From 12755bace0785b860db5bd584c701aa5d65f475c Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 21 Sep 2018 10:46:50 +0200 Subject: [PATCH 17/25] flowconfig fix for FlowWebpackPlugin --- .flowconfig | 2 +- src/utils/formatUtils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.flowconfig b/.flowconfig index 6897a28b..9a632b96 100644 --- a/.flowconfig +++ b/.flowconfig @@ -9,7 +9,7 @@ .*/node_modules/react-router-redux/.* .*/node_modules/oboe/test/.* .*/_old/.* -.*/public/.* +.*/public/solidity/.* [libs] ./src/flowtype/npm/redux_v3.x.x.js diff --git a/src/utils/formatUtils.js b/src/utils/formatUtils.js index 986b0ee9..9009cc7e 100644 --- a/src/utils/formatUtils.js +++ b/src/utils/formatUtils.js @@ -3,7 +3,7 @@ // TODO: chagne currency units const currencyUnitsConstant: string = 'mbtc2'; -export const formatAmount = (n: number, coinInfo: any, currencyUnits = currencyUnitsConstant): string => { +export const formatAmount = (n: number, coinInfo: any, currencyUnits: string = currencyUnitsConstant): string => { const amount = (n / 1e8); if (coinInfo.isBitcoin && currencyUnits === 'mbtc' && amount <= 0.1 && n !== 0) { const s = (n / 1e5).toString(); From 02f442c71b790525c44229b15901b60b4eae46f7 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 21 Sep 2018 10:52:12 +0200 Subject: [PATCH 18/25] add gitRevisionPugin to webpack.dev.local --- webpack/local.babel.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webpack/local.babel.js b/webpack/local.babel.js index 8e78c49b..d760c9ac 100644 --- a/webpack/local.babel.js +++ b/webpack/local.babel.js @@ -1,5 +1,6 @@ import webpack from 'webpack'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; +import GitRevisionPlugin from 'git-revision-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import CopyWebpackPlugin from 'copy-webpack-plugin'; import MiniCssExtractPlugin from '../../trezor-connect/node_modules/mini-css-extract-plugin'; @@ -15,6 +16,8 @@ import { PORT, } from './constants'; +const gitRevisionPlugin = new GitRevisionPlugin(); + module.exports = { watch: true, mode: 'development', @@ -163,6 +166,7 @@ module.exports = { new webpack.DefinePlugin({ LOCAL: JSON.stringify(`http://localhost:${PORT}/`), + COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()), }), // ignore node lib from trezor-link From 24737ddb2277ebae20fcc3cd45ca169191b0e081 Mon Sep 17 00:00:00 2001 From: Vasek Mlejnsky Date: Thu, 20 Sep 2018 13:40:16 +0200 Subject: [PATCH 19/25] Fix checkbox css when is checked --- src/components/Checkbox/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/Checkbox/index.js b/src/components/Checkbox/index.js index 1f4eef2b..0201a2f1 100644 --- a/src/components/Checkbox/index.js +++ b/src/components/Checkbox/index.js @@ -1,6 +1,6 @@ import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; -import styled from 'styled-components'; +import styled, { css } from 'styled-components'; import colors from 'config/colors'; import Icon from 'components/Icon'; import icons from 'config/icons'; @@ -34,8 +34,10 @@ const IconWrapper = styled.div` &:hover, &:focus { - border: 1px solid ${colors.TEXT_PRIMARY}; - background: ${props => (props.checked ? colors.TEXT_PRIMARY : colors.WHITE)}; + ${props => !props.checked && css` + border: 1px solid ${colors.GREEN_PRIMARY}; + `} + background: ${props => (props.checked ? colors.GREEN_PRIMARY : colors.WHITE)}; } `; From 7fc4737846be6aea79719de848631d5aa8eb5837 Mon Sep 17 00:00:00 2001 From: Vasek Mlejnsky Date: Thu, 20 Sep 2018 13:40:28 +0200 Subject: [PATCH 20/25] Remove defualt hover color for 'Icon' --- src/components/Icon/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Icon/index.js b/src/components/Icon/index.js index 6e5b0d71..1879547c 100644 --- a/src/components/Icon/index.js +++ b/src/components/Icon/index.js @@ -27,7 +27,7 @@ const SvgWrapper = styled.svg` :hover { path { - fill: ${props => props.hoverColor || colors.TEXT_SECONDARY} + fill: ${props => props.hoverColor} } } `; From 2ff86bd6a7ad3e70a6a38035b889661f536471f6 Mon Sep 17 00:00:00 2001 From: Vasek Mlejnsky Date: Thu, 20 Sep 2018 13:41:13 +0200 Subject: [PATCH 21/25] Passphrase is set as password by default & add autofill feature --- src/components/Paragraph/index.js | 5 +- src/components/inputs/Input/index.js | 4 +- .../modals/passphrase/Passphrase/index.js | 73 ++++++++++++++----- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/src/components/Paragraph/index.js b/src/components/Paragraph/index.js index 88a24fb8..34f498de 100644 --- a/src/components/Paragraph/index.js +++ b/src/components/Paragraph/index.js @@ -26,10 +26,7 @@ const P = ({ children, className, isSmaller = false }) => ( P.propTypes = { className: PropTypes.string, isSmaller: PropTypes.bool, - children: PropTypes.oneOfType([ - PropTypes.array, - PropTypes.string, - ]), + children: PropTypes.node, }; export default P; diff --git a/src/components/inputs/Input/index.js b/src/components/inputs/Input/index.js index 339b73cc..5bd17dc5 100644 --- a/src/components/inputs/Input/index.js +++ b/src/components/inputs/Input/index.js @@ -114,6 +114,7 @@ class Input extends Component { /> )} { } = this.state; // } = this.props.modal; - let passphraseInputValue: string = passphrase; - let passphraseRevisionInputValue: string = passphraseRevision; - if (!visible && !passphraseFocused) { - passphraseInputValue = passphrase.replace(/./g, '•'); - } - if (!visible && !passphraseRevisionFocused) { - passphraseRevisionInputValue = passphraseRevision.replace(/./g, '•'); - } + console.warn('passphrase', passphrase); + console.warn('passphraseRevision', passphraseRevision); + const passphraseInputValue: string = passphrase; + const passphraseRevisionInputValue: string = passphraseRevision; + // if (!visible && !passphraseFocused) { + // passphraseInputValue = passphrase.replace(/./g, '•'); + // } + // if (!visible && !passphraseRevisionFocused) { + // passphraseRevisionInputValue = passphraseRevision.replace(/./g, '•'); + // } + + console.warn('VISIBLE', visible); if (this.passphraseInput) { - this.passphraseInput.value = passphraseInputValue; - this.passphraseInput.setAttribute('type', visible || (!visible && !passphraseFocused) ? 'text' : 'password'); + console.warn('this.passphraseInput', this.passphraseInput); + // this.passphraseInput.value = passphraseInputValue; + // this.passphraseInput.setAttribute('type', visible || (!visible && !passphraseFocused) ? 'text' : 'password'); + this.passphraseInput.setAttribute('type', visible ? 'text' : 'password'); } if (this.passphraseRevisionInput) { - this.passphraseRevisionInput.value = passphraseRevisionInputValue; - this.passphraseRevisionInput.setAttribute('type', visible || (!visible && !passphraseRevisionFocused) ? 'text' : 'password'); + // this.passphraseRevisionInput.value = passphraseRevisionInputValue; + // this.passphraseRevisionInput.setAttribute('type', visible || (!visible && !passphraseRevisionFocused) ? 'text' : 'password'); + this.passphraseRevisionInput.setAttribute('type', visible ? 'text' : 'password'); } } @@ -170,10 +181,19 @@ export default class PinModal extends Component { // or // https://github.com/zakangelle/react-password-mask/blob/master/src/index.js if (input === 'passphrase') { + console.warn('PASSPHRASE CHANGE', value); this.setState(previousState => ({ match: previousState.singleInput || previousState.passphraseRevision === value, passphrase: value, })); + + if (this.state.visible && this.passphraseRevisionInput) { + this.setState({ + match: true, + passphraseRevision: value, + }); + this.passphraseRevisionInput.value = value; + } } else { this.setState(previousState => ({ match: previousState.passphrase === value, @@ -211,12 +231,28 @@ export default class PinModal extends Component { this.setState({ visible: true, }); + if (this.passphraseRevisionInput) { + this.passphraseRevisionInput.disabled = true; + this.passphraseRevisionInput.value = this.state.passphrase; + this.setState(previousState => ({ + passphraseRevision: previousState.passphrase, + match: true, + })); + } } onPassphraseHide = (): void => { this.setState({ visible: false, }); + if (this.passphraseRevisionInput) { + this.passphraseRevisionInput.value = ''; + this.setState({ + passphraseRevision: '', + match: false, + }); + this.passphraseRevisionInput.disabled = false; + } } submit = (empty: boolean = false): void => { @@ -232,7 +268,7 @@ export default class PinModal extends Component { //this.passphraseRevisionInput.style.display = 'none'; //this.passphraseRevisionInput.setAttribute('readonly', 'readonly'); - const p = passphrase; + // const p = passphrase; this.setState({ passphrase: '', @@ -274,8 +310,8 @@ export default class PinModal extends Component { console.log('passphraseInputType', passphraseInputType); return ( - {/* ?

Enter { deviceLabel } passphrase

*/} - {/*

Note that passphrase is case-sensitive.

*/} +

Enter { deviceLabel } passphrase

+

Note that passphrase is case-sensitive.

{ data-lpignore="true" onFocus={() => this.onPassphraseFocus('passphrase')} onBlur={() => this.onPassphraseBlur('passphrase')} - tabIndex="1" + tabIndex="0" /> {!singleInput && ( @@ -306,7 +342,6 @@ export default class PinModal extends Component { data-lpignore="true" onFocus={() => this.onPassphraseFocus('revision')} onBlur={() => this.onPassphraseBlur('revision')} - tabIndex="2" /> {!match && passphraseRevisionTouched && Passphrases do not match } @@ -315,7 +350,7 @@ export default class PinModal extends Component { Show passphrase - +