diff --git a/index.html b/index.html index 81f9987..b3beae4 100644 --- a/index.html +++ b/index.html @@ -1136,7 +1136,7 @@ } return { isValid: parseFloat(value) >= minValidAmount[selectedCurrency], - errorText: `Amount must be greater than ${formatAmount(minValidAmount[selectedCurrency])} ${selectedCurrency.toUpperCase()}` + errorText: `Amount must be greater than ${getConvertedAmount(minValidAmount[selectedCurrency], true)} ${selectedCurrency.toUpperCase()}` } } } @@ -1175,7 +1175,7 @@
-
${formatAmount(getConvertedAmount(amount))}
+
${getConvertedAmount(amount, true)}
${transactionReceiver} @@ -1211,7 +1211,7 @@ getRef('transactions_list').innerHTML = ''; getRef('address_balance').innerHTML = ''; btcOperator.getAddressData(address).then(result => { - getRef('address_balance').value = formatAmount(getConvertedAmount(result.balance)); + getRef('address_balance').value = getConvertedAmount(result.balance, true); getRef('address_balance').dataset.btcAmount = result.balance; getRef('address_balance').parentElement.classList.remove('hidden') getRef('filter_selector').classList.remove('hidden') @@ -1286,7 +1286,7 @@
Fee
-
${formatAmount(getConvertedAmount(fee))}
+
${getConvertedAmount(fee, true)}
@@ -1300,14 +1300,14 @@
Total Inputs
-
${formatAmount(getConvertedAmount(total_input_value))}
+
${getConvertedAmount(total_input_value, true)}
Total Outputs
-
${formatAmount(getConvertedAmount(total_output_value))}
+
${getConvertedAmount(total_output_value, true)}
@@ -1328,7 +1328,7 @@ ${inputs.map(input => html`
  • ${input.address} -
    ${formatAmount(getConvertedAmount(input.value))}
    +
    ${getConvertedAmount(input.value, true)}
  • `)} @@ -1342,7 +1342,7 @@ ${outputs.map(output => html`
  • ${output.address} -
    ${formatAmount(getConvertedAmount(output.value))}
    +
    ${getConvertedAmount(output.value, true)}
  • `)} @@ -1389,7 +1389,7 @@ } if (!amount) return '0'; - return amount.toLocaleString(undefined, { style: 'currency', currency: selectedCurrency, minimumFractionDigits: 0, maximumFractionDigits: 8 }) + return amount.toLocaleString(undefined, { style: 'currency', currency: selectedCurrency, minimumFractionDigits: 0, maximumFractionDigits: selectedCurrency === 'btc' ? 8 : 2 }) } let globalExchangeRate = {} async function getExchangeRate() { @@ -1405,14 +1405,17 @@ }).catch(err => reject(err)) }) } - function getConvertedAmount(amount) { + function getConvertedAmount(amount, formatAmount = false) { // check if amount is a string and convert it to a number if (typeof amount === 'string') { amount = parseFloat(amount) } + let convertedAmount = amount; if (globalExchangeRate[selectedCurrency]) - return parseFloat((amount * globalExchangeRate[selectedCurrency]).toFixed(8)) - else return amount + convertedAmount = parseFloat((amount * globalExchangeRate[selectedCurrency]).toFixed(8)) + if (formatAmount) + convertedAmount = formatAmount(convertedAmount) + return convertedAmount } function roundUp(amount, precision = 2) { return parseFloat((Math.ceil(amount * Math.pow(10, precision)) / Math.pow(10, precision)).toFixed(precision)) @@ -1448,7 +1451,7 @@ el.isValid // trigger validation } else { if (el.dataset.btcAmount === undefined) return - el.textContent = formatAmount(getConvertedAmount(el.dataset.btcAmount)) + el.textContent = getConvertedAmount(el.dataset.btcAmount, true) } }) previouslySelectedCurrency = selectedCurrency @@ -1714,12 +1717,12 @@ 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].textContent = getConvertedAmount(balance, true); senderBalances[index].dataset.btcAmount = balance; totalBalance += balance; }) console.log(totalBalance) - getRef("total_balance").textContent = `${formatAmount(getConvertedAmount(totalBalance))}`; + getRef("total_balance").textContent = `${getConvertedAmount(totalBalance, true)}`; getRef("total_balance").dataset.btcAmount = totalBalance; }).catch(err => { console.error(err); @@ -1768,7 +1771,7 @@ renderElem(getRef('fees_wrapper'), html`
    - Approximate fee: ${formatAmount(getConvertedAmount(fees))} + Approximate fee: ${getConvertedAmount(fees, true)}

    *Exact fee will be calculated after you fill all the required fields

    @@ -1817,7 +1820,7 @@ renderElem(getRef('fees_wrapper'), html``) const [senders, privKeys, receivers, amounts] = getTransactionInputs(); btcOperator.createTx(senders, receivers, amounts).then(({ fee }) => { - renderElem(getRef('fees_wrapper'), html` ${formatAmount(getConvertedAmount(fee))} `) + renderElem(getRef('fees_wrapper'), html` ${getConvertedAmount(fee, true)} `) getRef('send_transaction').disabled = false; getRef('fees_section').classList.remove('hidden') getRef('error_section').classList.add('hidden') @@ -1852,7 +1855,7 @@ } else { getRef('fees_section').classList.remove('hidden') getRef('error_section').classList.add('hidden') - if (getRef('send_tx').validity) + if (getRef('send_tx').isFormValid) getRef('send_transaction').disabled = false; } }, 300)) @@ -1909,14 +1912,14 @@
    Receivers
      ${receivers.map((receiver, index) => html`
    • - ${receiver} ${formatAmount(getConvertedAmount(amounts[index]))} + ${receiver} ${getConvertedAmount(amounts[index], true)}
    • `)}
    Fee
    - ${formatAmount(getConvertedAmount(fee))} + ${getConvertedAmount(fee, true)}
    `, @@ -2028,7 +2031,7 @@

    Senders