Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: Multiple send bug fixes #1538

Merged
merged 24 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ab69e25
Added tests/bitcoin to gitignore
moneymanolis Jan 24, 2021
ec0a863
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis May 2, 2021
d55390c
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis May 5, 2021
ca5e957
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis May 13, 2021
329ab71
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis May 22, 2021
2029ae8
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis May 26, 2021
928536f
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis May 28, 2021
08afceb
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Aug 1, 2021
423f169
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Nov 3, 2021
9e5b294
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Nov 4, 2021
7f25465
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Nov 14, 2021
c109684
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Nov 17, 2021
12d481c
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Nov 18, 2021
646b8e3
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Nov 25, 2021
261bfad
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Dec 22, 2021
9ae5006
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Jan 13, 2022
aa0ad5f
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Jan 17, 2022
59706f8
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Jan 21, 2022
fa52dd8
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Jan 24, 2022
f66f5cd
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Jan 25, 2022
ae209b3
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
moneymanolis Jan 25, 2022
d78c208
Multiple send bug fixes, disabling RBF and subtract fee from for Liqu…
moneymanolis Jan 26, 2022
1938376
Merge branch 'master' into send_bugfixes
Jan 27, 2022
db9b65d
Merge branch 'master' into send_bugfixes
Jan 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cypress/integration/spec_wallet_send.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('Send transactions from bitcoin hotwallets', () => {
cy.get('#btn_send').click()
cy.get('#address_0').type("bcrt1qsj30deg0fgzckvlrn5757yk55yajqv6dqx0x7u")
cy.get('#label_0').type("Burn address")
cy.get('#amount_0').type("19.5")
cy.get('#send_max_0').click()
cy.get('#create_psbt_btn').click()
cy.get('body').contains("Paste signed transaction")
cy.get('#hot_device_1_tx_sign_btn').click()
Expand All @@ -38,7 +38,7 @@ describe('Send transactions from bitcoin hotwallets', () => {
cy.get('#fullbalance_amount', { timeout: Cypress.env("broadcast_timeout") })
.should(($div) => {
const n = parseFloat($div.text())
expect(n).to.be.lessThan(0.5) // 20 minted, 19.5 send, the difference is fee
expect(n).to.be.equals(0)
})
})

Expand Down Expand Up @@ -71,7 +71,7 @@ describe('Send transactions from bitcoin hotwallets', () => {
cy.get('#btn_send').click()
cy.get('#address_0').type("bcrt1qsj30deg0fgzckvlrn5757yk55yajqv6dqx0x7u")
cy.get('#label_0').type("Burn address")
cy.get('#amount_0').type("19.5")
cy.get('#send_max_0').click()
cy.get('#create_psbt_btn').click()
cy.get('body').contains("Paste signed transaction")
cy.get('#hot_device_1_tx_sign_btn').click()
Expand All @@ -81,7 +81,7 @@ describe('Send transactions from bitcoin hotwallets', () => {
cy.get('#fullbalance_amount', { timeout: Cypress.env("broadcast_timeout") })
.should(($div) => {
const n = parseFloat($div.text())
expect(n).to.be.lessThan(0.5) // 20 minted, 19.5 send, the difference is fee
expect(n).to.be.equals(0)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
let spendableAmount;
if (!this.isCoinSelectionActive()) {
if(unit == 'btc' || unit == 'sat'){
spendableAmount = '{{ wallet.full_available_balance | btcamount }}';
spendableAmount = '{{ wallet.full_available_balance }}';
} else {
if (unit in assetBalances){
return assetBalances[unit].balance;
Expand All @@ -126,7 +126,7 @@
}
}
} else {
spendableAmount = this.getCoinSelectedAmount;
spendableAmount = this.getCoinSelectedAmount();
}

return (unit == 'sat' ? spendableAmount * 100000000 : spendableAmount);
Expand Down
52 changes: 38 additions & 14 deletions src/cryptoadvance/specter/templates/includes/fee-selection.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template id="fee-selection">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}">
<div class="fee_container">
<div>
<div id="subtract_fees_div">
<label><input type="checkbox" class="inline" name="subtract" id="subtract" {% if subtract %}checked{% endif %}> {{ _("Subtract fees from amount") }}</label>
<div class="tool-tip" style="text-align: center;">
<i class="tool-tip__icon">i</i>
Expand Down Expand Up @@ -68,6 +68,8 @@
this.wholeTemplate = shadow
var template_content = document.getElementById('fee-selection').content;
var clone = template_content.cloneNode(true);
this.feeContainer = clone.querySelector(".fee_container")
this.subtractFeesDiv = clone.getElementById("subtract_fees_div")

// The radio-button for manual
this.fee_option_manual = clone.querySelector("#fee_option_manual")
Expand Down Expand Up @@ -111,7 +113,8 @@

// Presets
this.feeOptionPreset = this.getAttribute('fee-option-preset') == null ? "dynamic" : this.getAttribute('fee-option-preset')
this.rbfOption.value = "false"
this.rbfOption.value = "true"
this.rbfOption.checked = true
this.subtract.value = "false"

this.createLighterDOMNodes()
Expand Down Expand Up @@ -294,6 +297,18 @@
}
}

// Returns fees that can be picked up
selectedFee() {
if (this.ld.feeOption.value == "manual") {
let manualRate = this.ld.feeRate.value
return manualRate
}
else {
let dynamicRate = this.ld.feeRateDynamic.value
return dynamicRate
}
}

// Updates Light DOM values for the form
rbfUpdated() {
if (this.rbfOption.checked) {
Expand All @@ -304,10 +319,24 @@
}
}

deactivateRbf() {
this.rbfLabel.remove()
this.ld.rbfOption.value = "false"
}

// Subtract setter
setSubtract(checked) {
try { console.log("setSubtract running")
this.subtract.checked = checked
this.subtractUpdated()
} catch(e) {console.log(e)}
}

// Updates Light DOM values for the form
subtractUpdated() {
if (this.subtract.checked) {
this.ld.subtract.value = "true"
this.ld.subtract.checked = true
this.ld.subtractFromInput.value = this.subtractFromInput.value
}
else {
Expand All @@ -323,26 +352,21 @@
}
}

deactivateSubtract() {
this.subtractFeesDiv.remove()
this.subtractFrom.remove()
// Removing light DOM elements would currently break wallet_send functions
}

subtractClickHook() {
let event = new CustomEvent('subtractClick', {});
this.subtract.addEventListener("click", () => {
this.ld.subtract.checked = this.subtract.checked
this.subtractUpdated()
this.dispatchEvent(event);
})
}

// Returns fees that can be picked up
selectedFee() {
if (this.ld.feeOption.value == "manual") {
let manualRate = this.ld.feeRate.value
return manualRate
}
else {
let dynamicRate = this.ld.feeRateDynamic.value
return dynamicRate
}
}

// Adds line breaks at the end of the component
addLineBreaks(number) {
for (let i = 0; i < number; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@

{% block scripts %}
<script>

{% if specter.is_liquid %}
const MIN_FEE_RATE = 0.1;
const NETWORK = "Liquid"
{% else %}
const MIN_FEE_RATE = 1;
const NETWORK = "Bitcoin"
{% endif %}

// Amounts and units
var units = [];
var amounts = [];
Expand Down Expand Up @@ -156,6 +158,24 @@
})
var FeeSelectionComponent = document.getElementById('fee-selection-component')
FeeSelectionComponent = document.getElementById('fee-selection-component')

// Switch off RBF and subtract fee for Liquid
function adjustForLiquid() {
if (NETWORK == "Liquid") {
console.log("On Liquid, removing RBF and subtract from features ... ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... ?

FeeSelectionComponent.deactivateRbf()
FeeSelectionComponent.deactivateSubtract() // Subtract from is still set to true for send max under the hood
// Remove some line breaks
advancedSettingsDiv = document.getElementById("advanced_settings")
lineBreaks = Array.from(advancedSettingsDiv.querySelectorAll('br'))
lineBreaks.pop() // We still need the last line break
for (var br of lineBreaks) {
if (br.parentNode == advancedSettingsDiv) {
advancedSettingsDiv.removeChild(br)
}
}
}
}

// Main part of displaying subtractFrom, the rest is with addRecipient, deleteRecipient and toggleSendUIType
FeeSelectionComponent.addEventListener("subtractClick", (event) => {
Expand Down Expand Up @@ -372,15 +392,9 @@
async function setMaxAmount(i) {
let amountInput = document.getElementById('amount_' + i);
if (!validAddress(i)) {
showError(`{{ _("Please first enter a valid address") }}`);
return;
}
let subtract = document.getElementById('subtract');
subtract.checked = (units[i] == 'sat' || units[i] == 'btc');
if (amounts.length > 1) {
document.getElementById('subtract_from').style.display = 'block';
document.getElementById('subtract_from_input').value = i + 1;
}
FeeSelectionComponent.setSubtract(units[i] == 'sat' || units[i] == 'btc' || units[i] == 'lbtc');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I remember LBTC has unit btc or sat, so it will never be lbtc

let othersAmount = 0;
for(let j in amounts) {
if (j != i) {
Expand Down Expand Up @@ -635,7 +649,7 @@
}
} catch (e) {
console.log(e);
document.getElementById('calculated_tx_fee').innerText = `: {{ _("Failed to calculate transaction fees. Perhaps you used an invalid Bitcoin address.") }}`; // TODO: Remove second part of the message until we have a better address validation here.
document.getElementById('calculated_tx_fee').innerText = `: {{ _("Failed to calculate transaction fees.") }}`;
}
return -1;
}
Expand All @@ -648,6 +662,7 @@
{% else %}
addRecipient("", 0, "btc", "");
{% endif %}
adjustForLiquid()
document.getElementById('toggle_advanced').addEventListener('click', (event) => {
toggleAdvanced();
});
Expand Down