diff options
author | Dan J Miller <danjm.com@gmail.com> | 2018-07-04 01:48:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-04 01:48:04 +0800 |
commit | 8def5281b43c2ce2abc272bc3fbef6dc83a41327 (patch) | |
tree | dc052e9f6611ce992af5aba7df9b172266c2d42d | |
parent | 3fd5af636fb5c8887a28e8016f0a61a2890ad8d5 (diff) | |
parent | a6f1734eddb934ce63384951305f86697ba88983 (diff) | |
download | tangerine-wallet-browser-8def5281b43c2ce2abc272bc3fbef6dc83a41327.tar tangerine-wallet-browser-8def5281b43c2ce2abc272bc3fbef6dc83a41327.tar.gz tangerine-wallet-browser-8def5281b43c2ce2abc272bc3fbef6dc83a41327.tar.bz2 tangerine-wallet-browser-8def5281b43c2ce2abc272bc3fbef6dc83a41327.tar.lz tangerine-wallet-browser-8def5281b43c2ce2abc272bc3fbef6dc83a41327.tar.xz tangerine-wallet-browser-8def5281b43c2ce2abc272bc3fbef6dc83a41327.tar.zst tangerine-wallet-browser-8def5281b43c2ce2abc272bc3fbef6dc83a41327.zip |
Merge pull request #4654 from TrejGun/bignumber
fixes #4307 BigNumber casting issue
-rw-r--r-- | ui/app/conversion-util.js | 2 | ||||
-rw-r--r-- | ui/app/conversion-util.test.js | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js index 337763067..a7a226cc5 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..368ce3bba --- /dev/null +++ b/ui/app/conversion-util.test.js @@ -0,0 +1,22 @@ +import assert from 'assert' +import {addCurrencies} from './conversion-util' + + +describe('conversion utils', () => { + describe('addCurrencies()', () => { + it('add whole numbers', () => { + const result = addCurrencies(3, 9) + assert.equal(result.toNumber(), 12) + }) + + it('add decimals', () => { + const result = addCurrencies(1.3, 1.9) + assert.equal(result.toNumber(), 3.2) + }) + + it('add repeating decimals', () => { + const result = addCurrencies(1 / 3, 1 / 9) + assert.equal(result.toNumber(), 0.4444444444444444) + }) + }) +}) |