From ff39781d5f5889bb1206877032c2300c7c3864be Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sun, 19 Nov 2017 15:41:13 +0300 Subject: [PATCH] address balance spendable amount --- routes/shepherd/dashboardUpdate.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/routes/shepherd/dashboardUpdate.js b/routes/shepherd/dashboardUpdate.js index e89553a..293bc2d 100644 --- a/routes/shepherd/dashboardUpdate.js +++ b/routes/shepherd/dashboardUpdate.js @@ -115,18 +115,24 @@ module.exports = (shepherd) => { if (result[a]) { for (let b = 0; b < result[a].length; b++) { - let filteredArray; - - filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount); + const filteredArraySpends = json.filter(res => res.address === result[a][b]); + const filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount); let sum = 0; + let spendableSum = 0; + for (let i = 0; i < filteredArray.length; i++) { sum += filteredArray[i]; + + if (filteredArraySpends[i].spendable) { + spendableSum += filteredArray[i]; + } } newAddressArray[a][b] = { address: result[a][b], amount: sum, + spendable: spendableSum, type: a === 0 ? 'public': 'private', }; }