From e4b0733198110c3c215ccfc6a5733d8166fff62c Mon Sep 17 00:00:00 2001 From: georgelima Date: Tue, 5 Mar 2019 16:19:49 -0300 Subject: [PATCH 1/9] fix(parse-conf): trim zcash key/value pair before save --- config/daemon/parse-zcash-conf.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/config/daemon/parse-zcash-conf.js b/config/daemon/parse-zcash-conf.js index 0e07470..4b9fde7 100644 --- a/config/daemon/parse-zcash-conf.js +++ b/config/daemon/parse-zcash-conf.js @@ -34,7 +34,6 @@ type ZcashConfFile = { export const parseZcashConf = (): Promise> => new Promise((resolve, reject) => { fs.readFile(locateZcashConf(), (err, file) => { - // TODO: Maybe we can create the zcash.conf on the fly here if (err) return reject(err); const fileString = file.toString(); @@ -42,15 +41,14 @@ export const parseZcashConf = (): Promise> => new Promise((resolve // $FlowFixMe const { rpcuser, rpcpassword, ...payload }: ZcashConfFile = filterObjectNullKeys( fileString.split('\n').reduce((acc, cur) => { + if (!cur) return acc; const [key, value] = cur.split('='); - return { ...acc, [key]: value }; + return { ...acc, [key.trim().toLowerCase()]: value.trim() }; }, {}), ); - if (rpcuser && rpcpassword) { - store.set('rpcuser', rpcuser); - store.set('rpcpassword', rpcpassword); - } + if (rpcuser) store.set('rpcuser', rpcuser); + if (rpcpassword) store.set('rpcpassword', rpcpassword); // $FlowFixMe resolve(Object.keys(payload).reduce((acc, key) => acc.concat(`-${key}=${payload[key]}`), [])); From 4902f6f907b908f1013e11189e3c3655c223ec98 Mon Sep 17 00:00:00 2001 From: georgelima Date: Tue, 5 Mar 2019 16:34:20 -0300 Subject: [PATCH 2/9] test(unit): update snapshots --- .../components/__snapshots__/transaction-item.test.js.snap | 2 +- .../components/__snapshots__/transactions-daily.test.js.snap | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/components/__snapshots__/transaction-item.test.js.snap b/__tests__/components/__snapshots__/transaction-item.test.js.snap index a8c8109..4b79778 100644 --- a/__tests__/components/__snapshots__/transaction-item.test.js.snap +++ b/__tests__/components/__snapshots__/transaction-item.test.js.snap @@ -29,7 +29,7 @@ exports[` should render a transaction item correctly 1`] = `

- 14:31 PM + 16:31 PM

diff --git a/__tests__/components/__snapshots__/transactions-daily.test.js.snap b/__tests__/components/__snapshots__/transactions-daily.test.js.snap index 1922919..0f617c8 100644 --- a/__tests__/components/__snapshots__/transactions-daily.test.js.snap +++ b/__tests__/components/__snapshots__/transactions-daily.test.js.snap @@ -41,7 +41,7 @@ exports[` render() should render user daily transac

- 14:31 PM + 16:31 PM

@@ -94,7 +94,7 @@ exports[` render() should render user daily transac

- 14:31 PM + 16:31 PM

From c3f5e5293b1ea3e9013976e8ab50abd8001d2f0e Mon Sep 17 00:00:00 2001 From: georgelima Date: Tue, 5 Mar 2019 16:46:04 -0300 Subject: [PATCH 3/9] test(snapshots): fix TransactionItem test --- .../components/__snapshots__/transaction-item.test.js.snap | 2 +- __tests__/components/transaction-item.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/components/__snapshots__/transaction-item.test.js.snap b/__tests__/components/__snapshots__/transaction-item.test.js.snap index 4b79778..fc456c6 100644 --- a/__tests__/components/__snapshots__/transaction-item.test.js.snap +++ b/__tests__/components/__snapshots__/transaction-item.test.js.snap @@ -29,7 +29,7 @@ exports[` should render a transaction item correctly 1`] = `

- 16:31 PM + 23:20 PM

diff --git a/__tests__/components/transaction-item.test.js b/__tests__/components/transaction-item.test.js index 4f23fe4..2e8ae3f 100644 --- a/__tests__/components/transaction-item.test.js +++ b/__tests__/components/transaction-item.test.js @@ -19,7 +19,7 @@ describe('', () => { address='123456789123456789123456789123456789' transactionId='a0s9dujo23j0' amount={0.8652} - date='2019-02-20T19:31:57.117Z' + date={new Date(Date.UTC(2018, 10, 20, 1, 20, 35)).toString()} zecPrice={2.94} fees={0.0001} /> From 9297166baf26c98f163020838165ba24667fac71 Mon Sep 17 00:00:00 2001 From: georgelima Date: Tue, 5 Mar 2019 17:01:59 -0300 Subject: [PATCH 4/9] test(unit): mock date in transaction-item test --- .../transaction-item.test.js.snap | 2 +- __tests__/components/transaction-item.test.js | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/__tests__/components/__snapshots__/transaction-item.test.js.snap b/__tests__/components/__snapshots__/transaction-item.test.js.snap index fc456c6..a39e0ba 100644 --- a/__tests__/components/__snapshots__/transaction-item.test.js.snap +++ b/__tests__/components/__snapshots__/transaction-item.test.js.snap @@ -29,7 +29,7 @@ exports[` should render a transaction item correctly 1`] = `

- 23:20 PM + 17:01 PM

diff --git a/__tests__/components/transaction-item.test.js b/__tests__/components/transaction-item.test.js index 2e8ae3f..f3c29aa 100644 --- a/__tests__/components/transaction-item.test.js +++ b/__tests__/components/transaction-item.test.js @@ -8,7 +8,21 @@ import 'jest-dom/extend-expect'; import { TransactionItemComponent } from '../../app/components/transaction-item'; import { appTheme } from '../../app/theme'; -afterEach(cleanup); +let originalDate; + +beforeEach(() => { + originalDate = global.Date; + global.Date = class extends Date { + constructor() { + super(); + return '2019-03-05T19:58:35.457Z'; + } + }; +}); +afterEach(() => { + global.Date = originalDate; + cleanup(); +}); describe('', () => { test('should render a transaction item correctly', () => { @@ -19,7 +33,7 @@ describe('', () => { address='123456789123456789123456789123456789' transactionId='a0s9dujo23j0' amount={0.8652} - date={new Date(Date.UTC(2018, 10, 20, 1, 20, 35)).toString()} + date={new Date().toString()} zecPrice={2.94} fees={0.0001} /> From 3df53c98ae50ed7779b9af5515eabaddba39a45e Mon Sep 17 00:00:00 2001 From: georgelima Date: Tue, 5 Mar 2019 17:21:16 -0300 Subject: [PATCH 5/9] test(unit): mock dateFns format --- __tests__/components/transaction-item.test.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/__tests__/components/transaction-item.test.js b/__tests__/components/transaction-item.test.js index f3c29aa..d405e02 100644 --- a/__tests__/components/transaction-item.test.js +++ b/__tests__/components/transaction-item.test.js @@ -3,24 +3,30 @@ import React from 'react'; import { render, cleanup } from 'react-testing-library'; import { ThemeProvider } from 'styled-components'; +import dateFns from 'date-fns'; import 'jest-dom/extend-expect'; import { TransactionItemComponent } from '../../app/components/transaction-item'; import { appTheme } from '../../app/theme'; let originalDate; +const fixedDate = new Date('2018-02-28T09:39:59'); + +beforeAll(() => { + dateFns.format = jest.fn(() => '17:01 PM'); -beforeEach(() => { originalDate = global.Date; global.Date = class extends Date { constructor() { super(); - return '2019-03-05T19:58:35.457Z'; + + return fixedDate; } }; }); -afterEach(() => { +afterAll(() => { global.Date = originalDate; + dateFns.format.mockRestore(); cleanup(); }); From ae303300d29c5b68db992398705ec9fed035324b Mon Sep 17 00:00:00 2001 From: georgelima Date: Tue, 5 Mar 2019 17:26:28 -0300 Subject: [PATCH 6/9] test(snapshot): mock date in TransactionDaily and update snapshot --- .../transactions-daily.test.js.snap | 4 ++-- .../components/transactions-daily.test.js | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/__tests__/components/__snapshots__/transactions-daily.test.js.snap b/__tests__/components/__snapshots__/transactions-daily.test.js.snap index 0f617c8..76be04e 100644 --- a/__tests__/components/__snapshots__/transactions-daily.test.js.snap +++ b/__tests__/components/__snapshots__/transactions-daily.test.js.snap @@ -41,7 +41,7 @@ exports[` render() should render user daily transac

- 16:31 PM + 17:01 PM

@@ -94,7 +94,7 @@ exports[` render() should render user daily transac

- 16:31 PM + 17:01 PM

diff --git a/__tests__/components/transactions-daily.test.js b/__tests__/components/transactions-daily.test.js index 3a5fc8d..061b2b4 100644 --- a/__tests__/components/transactions-daily.test.js +++ b/__tests__/components/transactions-daily.test.js @@ -3,12 +3,32 @@ import React from 'react'; import { render, cleanup } from 'react-testing-library'; import { ThemeProvider } from 'styled-components'; +import dateFns from 'date-fns'; import 'jest-dom/extend-expect'; import { TransactionDailyComponent } from '../../app/components/transaction-daily'; import { appTheme } from '../../app/theme'; -afterEach(cleanup); +let originalDate; +const fixedDate = new Date('2018-02-28T09:39:59'); + +beforeAll(() => { + dateFns.format = jest.fn(() => '17:01 PM'); + + originalDate = global.Date; + global.Date = class extends Date { + constructor() { + super(); + + return fixedDate; + } + }; +}); +afterAll(() => { + global.Date = originalDate; + dateFns.format.mockRestore(); + cleanup(); +}); describe('', () => { describe('render()', () => { From 0e88d924c4ad3d6b7f707eefd611c19237902b15 Mon Sep 17 00:00:00 2001 From: George Lima Date: Tue, 5 Mar 2019 17:39:01 -0300 Subject: [PATCH 7/9] version: bumping to 0.4.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a310468..b0ca03d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zec-react-wallet", - "version": "0.4.3", + "version": "0.4.4", "description": "Zcash Reference Wallet", "main": "config/main.js", "license": "MIT", From c3df064b4873b28ebe9dcf3b77da36c8a7d16126 Mon Sep 17 00:00:00 2001 From: George Lima Date: Wed, 6 Mar 2019 09:34:54 -0300 Subject: [PATCH 8/9] fix(zcash-conf): parse comment lines in zcash.conf --- __tests__/components/transaction-item.test.js | 1 + __tests__/components/transactions-daily.test.js | 1 + config/daemon/parse-zcash-conf.js | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/__tests__/components/transaction-item.test.js b/__tests__/components/transaction-item.test.js index d405e02..295cefb 100644 --- a/__tests__/components/transaction-item.test.js +++ b/__tests__/components/transaction-item.test.js @@ -13,6 +13,7 @@ let originalDate; const fixedDate = new Date('2018-02-28T09:39:59'); beforeAll(() => { + // $FlowFixMe dateFns.format = jest.fn(() => '17:01 PM'); originalDate = global.Date; diff --git a/__tests__/components/transactions-daily.test.js b/__tests__/components/transactions-daily.test.js index 061b2b4..6efd831 100644 --- a/__tests__/components/transactions-daily.test.js +++ b/__tests__/components/transactions-daily.test.js @@ -13,6 +13,7 @@ let originalDate; const fixedDate = new Date('2018-02-28T09:39:59'); beforeAll(() => { + // $FlowFixMe dateFns.format = jest.fn(() => '17:01 PM'); originalDate = global.Date; diff --git a/config/daemon/parse-zcash-conf.js b/config/daemon/parse-zcash-conf.js index 4b9fde7..73cd148 100644 --- a/config/daemon/parse-zcash-conf.js +++ b/config/daemon/parse-zcash-conf.js @@ -42,6 +42,11 @@ export const parseZcashConf = (): Promise> => new Promise((resolve const { rpcuser, rpcpassword, ...payload }: ZcashConfFile = filterObjectNullKeys( fileString.split('\n').reduce((acc, cur) => { if (!cur) return acc; + + const line = cur.trim(); + + if (line.startsWith('#')) return acc; + const [key, value] = cur.split('='); return { ...acc, [key.trim().toLowerCase()]: value.trim() }; }, {}), From 930e56081656b62f449b9448cf80f8b7fdddf5fa Mon Sep 17 00:00:00 2001 From: George Lima Date: Wed, 6 Mar 2019 09:57:49 -0300 Subject: [PATCH 9/9] fix(zcash-conf): clean store if rpcuser/rpcpassword are empty --- config/daemon/parse-zcash-conf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/daemon/parse-zcash-conf.js b/config/daemon/parse-zcash-conf.js index 73cd148..2625c20 100644 --- a/config/daemon/parse-zcash-conf.js +++ b/config/daemon/parse-zcash-conf.js @@ -52,8 +52,8 @@ export const parseZcashConf = (): Promise> => new Promise((resolve }, {}), ); - if (rpcuser) store.set('rpcuser', rpcuser); - if (rpcpassword) store.set('rpcpassword', rpcpassword); + store.set('rpcuser', rpcuser || ''); + store.set('rpcpassword', rpcpassword || ''); // $FlowFixMe resolve(Object.keys(payload).reduce((acc, key) => acc.concat(`-${key}=${payload[key]}`), []));