From 5d034006e8a73c7d64dee22c856c3733643454f8 Mon Sep 17 00:00:00 2001 From: trejgun Date: Sun, 24 Jun 2018 17:48:02 +0800 Subject: [PATCH] fixes #4307 BigNumber casting issue --- ui/app/conversion-util.js | 2 +- ui/app/conversion-util.test.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ui/app/conversion-util.test.js diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 100402d95..90c2226e7 100644 --- a/ui/app/conversion-util.js +++ b/ui/app/conversion-util.js @@ -140,7 +140,7 @@ const addCurrencies = (a, b, options = {}) => { bBase, ...conversionOptions } = options - const value = (new BigNumber(a, aBase)).add(b, bBase) + const value = (new BigNumber(a.toString(), aBase)).add(b.toString(), bBase) return converter({ value, diff --git a/ui/app/conversion-util.test.js b/ui/app/conversion-util.test.js new file mode 100644 index 000000000..c37264855 --- /dev/null +++ b/ui/app/conversion-util.test.js @@ -0,0 +1,23 @@ +import assert from 'assert' +import {addCurrencies} from './conversion-util' + + + +describe('conversion utils', () => { + describe.only('addCurrencies()', () => { + it('add whole numbers', () => { + const result = addCurrencies(3, 5) + assert.equal(result.toNumber(), 8) + }) + + it('add decimals', () => { + const result = addCurrencies(1.3, 1.5) + assert.equal(result.toNumber(), 2.8) + }) + + it('add repeating decimals', () => { + const result = addCurrencies(1/3, 1/7) + assert.equal(result.toNumber(), 0.47619047619047616) + }) + }) +})