From 3a73b4f59bdb799611618daf3ac2cd7423b9fbaa Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Wed, 13 Sep 2023 22:45:37 +0530 Subject: [PATCH] adding UI for multisig fee increase --- index.html | 43 +++++++++++++++++++++++------------------- scripts/btcOperator.js | 4 ++-- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/index.html b/index.html index 0f11929..bab4384 100644 --- a/index.html +++ b/index.html @@ -1270,7 +1270,6 @@ let txDetailsAbortController const render = { transactionCard(transactionDetails) { - console.log(transactionDetails) let { address, amount, time, txid, sender, receiver, type, block } = transactionDetails; let transactionReceiver let icon @@ -1966,42 +1965,42 @@ } let changingFeeOf = null - function initFeeChange(e) { + async function initFeeChange(e) { const button = e.target.closest('button') buttonLoader(button, true) const txid = button.closest('li').dataset.txid changingFeeOf = txid - btcOperator.getTx(txid).then(async details => { - const { inputs, outputs, fee } = details + try { + const { inputs, outputs, fee } = await btcOperator.getTx(txid) + const { witness } = btcOperator.deserializeTx(await btcOperator.getTx.hex(txid)) + const requiredSigns = extractLastHexStrings(witness).reduce((acc, hex) => { + const { address, required } = btcOperator.decodeRedeemScript(hex) || {} + if (address) + return { ...acc, [address]: required } + else return acc + }, {}) const senders = inputs.map(input => input.address) const receivers = outputs.map(output => output.address) const amounts = outputs.map(output => 0.00000001) - let recommendedFee = 0 - try { - const { fee } = await btcOperator.createTx(senders, receivers, amounts) - recommendedFee = fee - } catch (e) { - console.error(e) - } - console.log(inputs) + const { fee: recommendedFee = 0 } = await btcOperator.createTx(senders, receivers, amounts) renderElem(getRef('increase_fee_popup_content'), html`

Senders

    - ${inputs.map(input => html.node`
  • + ${senders.map((address) => html.node`
  • Address
    - ${input.address} + ${address}
    - + ${[...Array(requiredSigns[address] || 1)].map(_ => html` - + `)}
  • `)}
@@ -2035,11 +2034,11 @@ `) document.getElementById('new_fee').querySelector('.currency-symbol').innerHTML = currencyIcons[selectedCurrency] openPopup('increase_fee_popup') - }).catch(e => { + } catch (e) { console.error(e) - }).finally(_ => { + } finally { buttonLoader(button, false) - }) + } } function increaseFee() { buttonLoader(document.getElementById('increase_fee'), true) @@ -2072,6 +2071,12 @@ buttonLoader(document.getElementById('increase_fee'), false) }) } + function extractLastHexStrings(arr) { + return arr + .filter(innerArray => innerArray.length > 0) + .map(innerArray => innerArray[innerArray.length - 1]) + } + diff --git a/scripts/btcOperator.js b/scripts/btcOperator.js index 160cbb4..b741a94 100644 --- a/scripts/btcOperator.js +++ b/scripts/btcOperator.js @@ -1,4 +1,4 @@ -(function (EXPORTS) { //btcOperator v1.1.3b +(function (EXPORTS) { //btcOperator v1.1.3c /* BTC Crypto and API Operator */ const btcOperator = EXPORTS; @@ -770,7 +770,7 @@ }) } - function deserializeTx(tx) { + const deserializeTx = btcOperator.deserializeTx = function (tx) { if (typeof tx === 'string' || Array.isArray(tx)) { try { tx = coinjs.transaction().deserialize(tx);