aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-09-08 02:59:15 +0800
committerDan Finlay <dan@danfinlay.com>2017-09-08 02:59:15 +0800
commitb6e8791bc2bc912d874edcc92fcf3c4ce5a9b72a (patch)
tree2302ceb24fbd71fcfd041ca3939e305fd29b4c19 /app
parent74f7fc4613d136b57a4395d273ce4bf52d6685db (diff)
downloadtangerine-wallet-browser-b6e8791bc2bc912d874edcc92fcf3c4ce5a9b72a.tar
tangerine-wallet-browser-b6e8791bc2bc912d874edcc92fcf3c4ce5a9b72a.tar.gz
tangerine-wallet-browser-b6e8791bc2bc912d874edcc92fcf3c4ce5a9b72a.tar.bz2
tangerine-wallet-browser-b6e8791bc2bc912d874edcc92fcf3c4ce5a9b72a.tar.lz
tangerine-wallet-browser-b6e8791bc2bc912d874edcc92fcf3c4ce5a9b72a.tar.xz
tangerine-wallet-browser-b6e8791bc2bc912d874edcc92fcf3c4ce5a9b72a.tar.zst
tangerine-wallet-browser-b6e8791bc2bc912d874edcc92fcf3c4ce5a9b72a.zip
test not passing
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/pending-balance-calculator.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/app/scripts/lib/pending-balance-calculator.js b/app/scripts/lib/pending-balance-calculator.js
index 4f6e03138..9df87e34b 100644
--- a/app/scripts/lib/pending-balance-calculator.js
+++ b/app/scripts/lib/pending-balance-calculator.js
@@ -1,5 +1,6 @@
const BN = require('ethereumjs-util').BN
const EthQuery = require('ethjs-query')
+const normalize = require('eth-sig-util').normalize
class PendingBalanceCalculator {
@@ -9,15 +10,30 @@ class PendingBalanceCalculator {
}
async getBalance() {
+ console.log('getting balance')
const results = await Promise.all([
this.getBalance(),
this.getPendingTransactions(),
])
+ console.dir(results)
const balance = results[0]
const pending = results[1]
- return balance
+ console.dir({ balance, pending })
+
+ const pendingValue = pending.reduce(function (total, tx) {
+ return total.sub(this.valueFor(tx))
+ }, new BN(0))
+
+ const balanceBn = new BN(normalize(balance))
+
+ return `0x${ balanceBn.sub(pendingValue).toString(16) }`
+ }
+
+ valueFor (tx) {
+ const value = new BN(normalize(tx.txParams.value))
+ return value
}
}