From 8a1e253ed1950b96a20f055d510e272048811a74 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Sun, 19 Feb 2023 00:10:09 +0530 Subject: [PATCH] Bug fixes --- index.html | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index deedea5..3162505 100644 --- a/index.html +++ b/index.html @@ -126,7 +126,7 @@

Senders

-
@@ -713,7 +713,7 @@ }); getExchangeRate() .catch(e => { - console.error(e) + // console.error(e) getRef('currency_selector').classList.add('hidden') }).finally(() => { routeTo(window.location.hash) @@ -1315,8 +1315,9 @@ if (typeof amount === 'string') { amount = parseFloat(amount) } - const result = parseFloat((amount * globalExchangeRate[getRef('currency_selector').value]).toFixed(8)) - return result + if (globalExchangeRate[getRef('currency_selector').value]) + return parseFloat((amount * globalExchangeRate[getRef('currency_selector').value]).toFixed(8)) + else return amount } function roundUp(amount, precision = 2) { return parseFloat((Math.ceil(amount * Math.pow(10, precision)) / Math.pow(10, precision)).toFixed(precision)) @@ -1460,9 +1461,6 @@ e.target.closest('.card').remove() } }) - getRef('check_balance').onclick = evt => { - checkBalance(); - } async function checkBalance() { const addresses = [...getRef('sender_container').querySelectorAll('.sender-input')].filter(input => input.value.trim() !== '').map(input => input.value.trim()) if (addresses.length === 0) { @@ -1473,20 +1471,22 @@ let totalBalance = 0; console.debug(addresses); let senderBalances = [...getRef('sender_container').querySelectorAll('.sender-balance')]; - try { - senderBalances.forEach(el => el.innerHTML = ''); - await getExchangeRate(); - const balances = await Promise.all(addresses.map((addr, index) => btcOperator.getBalance(addr))) - balances.forEach((result, index) => { - senderBalances[index].textContent = formatAmount(getConvertedAmount(result)); - senderBalances[index].dataset.btcAmount = result; - totalBalance += result; + senderBalances.forEach(el => el.innerHTML = ''); + Promise.all(addresses.map((addr, index) => btcOperator.getBalance(addr))).then(balances => { + balances.forEach((balance, index) => { + senderBalances[index].textContent = formatAmount(getConvertedAmount(balance)); + senderBalances[index].dataset.btcAmount = balance; + totalBalance += balance; }) + console.log(totalBalance) getRef("total_balance").textContent = `${formatAmount(getConvertedAmount(totalBalance))}`; getRef("total_balance").dataset.btcAmount = totalBalance; - } catch (e) { - notify(e, 'error'); - } + }).catch(err => { + console.error(err); + notify('Error while fetching balance', 'error'); + senderBalances.forEach(el => el.innerHTML = ''); + getRef("total_balance").innerHTML = ''; + }) } getRef('add_receiver').onclick = evt => { let receiverCard = getRef('receiver_template').content.cloneNode(true)