-
Notifications
You must be signed in to change notification settings - Fork 2
/
balance.js
43 lines (29 loc) · 933 Bytes
/
balance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Code for updating the balance table
*/
//http://ludo.cubicphuse.nl/jquery-treetable/
const { makeTreeTable } = require('./treeTable')
function updateBalance(node, balances, endIndex, formatter) {
const amounts = new Map();
balances.forEach((value, key) => {
let currentAccount = ''
let val = value[endIndex]
if (val === 0) {
return;
}
for (a of key.account.split(':')) {
if (currentAccount == '') {
currentAccount = a;
} else {
currentAccount = currentAccount + ':' + a
}
if (amounts.has(currentAccount)) {
amounts.set(currentAccount, amounts.get(currentAccount) + val)
} else {
amounts.set(currentAccount, val)
}
}
});
makeTreeTable(amounts, node, formatter, false)
}
module.exports = updateBalance