From 89953275d5ad38540c8a40d59c06a01d02d4ff77 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Thu, 8 Dec 2022 22:39:45 +0530 Subject: [PATCH] Bug fixes and code refactoring --- index.html | 1 + js/main_UI.js | 74 ++++++++++++++++++++++----------------------------- 2 files changed, 33 insertions(+), 42 deletions(-) diff --git a/index.html b/index.html index 76539f0..e06bdb1 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,7 @@ + diff --git a/js/main_UI.js b/js/main_UI.js index 7ceb498..19c2332 100644 --- a/js/main_UI.js +++ b/js/main_UI.js @@ -329,51 +329,25 @@ function fetchRibcData() { receiverID: "FMyRTrz9CG4TFNM6rCQgy3VQ5NF23bY2xD" }); } -function fetchInternData() { - return floBlockchainAPI - .readAllTxs("FThgnJLcuStugLc24FJQggmp2WgaZjrBSn") - .then((allTxs) => { - allTxs.forEach((tx) => { - const floId = tx.vout[0].scriptPubKey.addresses[0]; - if (!floGlobals.appObjects.RIBC.internList[floId]) return; // not an intern - const { txid, floData, time } = tx - if (!floGlobals.internTxs[floId]) - floGlobals.internTxs[floId] = { - total: 0, - txs: [] - }; - const amount = parseFloat(floData.match(/([0-9]+)/)[1]) || 0; // get amount from floData - floGlobals.internTxs[floId].total += amount; - floGlobals.internTxs[floId].txs.push({ - txid, - amount, - time - }); - - }); - render.internPaymentList(); - }).catch((err) => { - console.log(err); - }); +function fetchTransactions() { + return floTokenAPI.getAllTxs('FThgnJLcuStugLc24FJQggmp2WgaZjrBSn') } const render = { internCard(floId) { const { total, txs } = floGlobals.internTxs[floId]; return html` -
  • - -
    -

    ${floGlobals.appObjects.RIBC.internList[floId]}

    - -
    -
    -

    Last payment: ${formatAmount(txs[0].amount)} on ${getFormattedTime(txs[0].time, 'date-only')}

    -

    Total paid: ${formatAmount(total)}

    -
    - +
  • +
    +

    ${floGlobals.appObjects.RIBC.internList[floId]}

    + +
    +
    +

    Last payment: ${formatAmount(txs[0].amount)} on ${getFormattedTime(txs[0].time, 'date-only')}

    +

    Total paid: ${formatAmount(total)}

    +
    +
    + View details +
  • `; @@ -430,8 +404,24 @@ const render = { async function main() { try { - await fetchRibcData(); - await fetchInternData() + const [txData] = await Promise.all([fetchTransactions(),fetchRibcData()]); + for (const txid in txData.transactions) { + const {parsedFloData:{tokenAmount},transactionDetails} = txData.transactions[txid] + const floId = transactionDetails.vout[0].scriptPubKey.addresses[0]; + if (!floGlobals.appObjects.RIBC.internList[floId]) continue; // not an intern + if (!floGlobals.internTxs[floId]) + floGlobals.internTxs[floId] = { + total: 0, + txs: [] + }; + floGlobals.internTxs[floId].total += tokenAmount; + floGlobals.internTxs[floId].txs.push({ + txid, + amount: tokenAmount, + time: transactionDetails.time + }); + } + render.internPaymentList(); routeTo(window.location.hash) } catch (err) { console.log(err);