aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-09-08 03:30:25 +0800
committerDan Finlay <dan@danfinlay.com>2017-09-08 03:30:25 +0800
commit40585744365c128d1f64c5bf93ee8cedc9e91dae (patch)
tree8726029de67dc2106d8a90700adf248efb06d893 /app
parentb6e8791bc2bc912d874edcc92fcf3c4ce5a9b72a (diff)
downloadtangerine-wallet-browser-40585744365c128d1f64c5bf93ee8cedc9e91dae.tar
tangerine-wallet-browser-40585744365c128d1f64c5bf93ee8cedc9e91dae.tar.gz
tangerine-wallet-browser-40585744365c128d1f64c5bf93ee8cedc9e91dae.tar.bz2
tangerine-wallet-browser-40585744365c128d1f64c5bf93ee8cedc9e91dae.tar.lz
tangerine-wallet-browser-40585744365c128d1f64c5bf93ee8cedc9e91dae.tar.xz
tangerine-wallet-browser-40585744365c128d1f64c5bf93ee8cedc9e91dae.tar.zst
tangerine-wallet-browser-40585744365c128d1f64c5bf93ee8cedc9e91dae.zip
Add basic test for valueFor
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/pending-balance-calculator.js13
1 files changed, 9 insertions, 4 deletions
diff --git a/app/scripts/lib/pending-balance-calculator.js b/app/scripts/lib/pending-balance-calculator.js
index 9df87e34b..f2c9ce379 100644
--- a/app/scripts/lib/pending-balance-calculator.js
+++ b/app/scripts/lib/pending-balance-calculator.js
@@ -6,13 +6,13 @@ class PendingBalanceCalculator {
constructor ({ getBalance, getPendingTransactions }) {
this.getPendingTransactions = getPendingTransactions
- this.getBalance = getBalance
+ this.getNetworkBalance = getBalance
}
async getBalance() {
console.log('getting balance')
const results = await Promise.all([
- this.getBalance(),
+ this.getNetworkBalance(),
this.getPendingTransactions(),
])
console.dir(results)
@@ -21,18 +21,23 @@ class PendingBalanceCalculator {
const pending = results[1]
console.dir({ balance, pending })
+ console.dir(pending)
const pendingValue = pending.reduce(function (total, tx) {
- return total.sub(this.valueFor(tx))
+ return total.add(this.valueFor(tx))
}, new BN(0))
const balanceBn = new BN(normalize(balance))
+ console.log(`subtracting ${pendingValue.toString()} from ${balanceBn.toString()}`)
return `0x${ balanceBn.sub(pendingValue).toString(16) }`
}
valueFor (tx) {
- const value = new BN(normalize(tx.txParams.value))
+ const txValue = tx.txParams.value
+ const normalized = normalize(txValue).substring(2)
+ console.log({ txValue, normalized })
+ const value = new BN(normalize(txValue).substring(2), 16)
return value
}