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

UI: Improve Adding/deleting recipients in Send , and move the recipient to a webcomponent #1782

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
9da2be9
made a drag drop recipient list
relativisticelectron Jun 5, 2022
2894ada
Working better.
relativisticelectron Jun 5, 2022
8accefd
Working drag and drop for recipients
relativisticelectron Jun 5, 2022
0bf9d88
Works good
relativisticelectron Jun 5, 2022
591f9a9
Fixed bug
relativisticelectron Jun 5, 2022
d5db750
Better css
relativisticelectron Jun 5, 2022
15075cf
better css
relativisticelectron Jun 5, 2022
05882c2
fixed bug
relativisticelectron Jun 5, 2022
513f1a4
Added rearranged recipients in test
relativisticelectron Jun 5, 2022
2fb40ac
changed ids to make the test harder
relativisticelectron Jun 5, 2022
69dd176
Prevented the last recipient from being deleted
relativisticelectron Jun 5, 2022
500573a
Better cursor
relativisticelectron Jun 5, 2022
1f2514f
Fixed bug, that I introduced
relativisticelectron Jun 5, 2022
39a6f6f
fixed bug now....
relativisticelectron Jun 5, 2022
0a1a970
Merge branch 'master' into 20220605_recipients
relativisticelectron Jun 5, 2022
985fcec
removed line
relativisticelectron Jun 5, 2022
f69ca5e
added handle https://sortablejs.github.io/Sortable/#handle
relativisticelectron Jun 5, 2022
d55f550
changed cursor to grab https://www.w3schools.com/csSref/tryit.asp?fi…
relativisticelectron Jun 5, 2022
8f3c856
use more functions
relativisticelectron Jun 5, 2022
96a8480
css improvements
relativisticelectron Jun 5, 2022
9505ccc
removed line
relativisticelectron Jun 5, 2022
bb2958d
Added titles
relativisticelectron Jun 5, 2022
61985cf
updated https://github.com/SortableJS/Sortable/releases
relativisticelectron Jun 5, 2022
318f329
Added a checker if the address is mine
relativisticelectron Jun 5, 2022
566201f
working coloring
relativisticelectron Jun 6, 2022
462f08c
cleaner code
relativisticelectron Jun 6, 2022
a65d3d0
changed color
relativisticelectron Jun 6, 2022
de715c3
Merge branch 'is_mine' into 20220605_recipients
relativisticelectron Jun 6, 2022
43858a4
Added color in css
relativisticelectron Jun 6, 2022
141824d
better width
relativisticelectron Jun 6, 2022
e5ffcd6
added edge case handling
relativisticelectron Jun 6, 2022
0359773
bugfix
relativisticelectron Jun 6, 2022
42f3404
Catch an exception from embit and interpret as invalid address
relativisticelectron Jun 6, 2022
92e6840
Added send_request javascript in helpers
relativisticelectron Jun 6, 2022
df9cb50
typo
relativisticelectron Jun 6, 2022
b36221d
Better console outputs
relativisticelectron Jun 6, 2022
b24323f
Merge branch 'master' into 20220605_recipients
Jun 10, 2022
576190d
Merge remote-tracking branch 'cryptoadvance/master' into 20220605_rec…
relativisticelectron Jun 14, 2022
663f1fe
Added an html select option for the subtract_from_input
relativisticelectron Jun 14, 2022
f1c762c
added the hidden attribute
relativisticelectron Jun 14, 2022
d992893
Solved vertical spacing proiblem, by reintroducing the coin-selection…
relativisticelectron Jun 14, 2022
650f34f
better vertical spacing
relativisticelectron Jun 14, 2022
dba94f4
moved position of vertical spacing
relativisticelectron Jun 14, 2022
700a6a4
fixed cypress test
relativisticelectron Jun 14, 2022
799a591
trying to relabel the fee selection
relativisticelectron Jun 14, 2022
3dd4200
fixing that select is not avaiable in request.form by transcribing it…
relativisticelectron Jun 14, 2022
821c44e
Fixed test issues
relativisticelectron Jun 14, 2022
077198e
Changed kwargs_from_request_json to recipients starting from 0
relativisticelectron Jun 14, 2022
4b15534
refactoring
relativisticelectron Jun 14, 2022
8e0d4d9
some remaining renumbering from subtract_from=1 to subtract_from=0
relativisticelectron Jun 14, 2022
e2d5dfd
Refactoring and BUGFIX
relativisticelectron Jun 14, 2022
612a90d
removed logs
relativisticelectron Jun 14, 2022
c065ae3
refactor
relativisticelectron Jun 14, 2022
f20ca56
refactor
relativisticelectron Jun 14, 2022
3a0d551
changed dev help text
relativisticelectron Jun 15, 2022
b2cccdb
Added move buttons
relativisticelectron Jun 15, 2022
f8e9b24
new cypress test not working
relativisticelectron Jun 15, 2022
7a8dc93
Moved cypress test to new file
relativisticelectron Jun 15, 2022
2ac5a1d
removed spaces
relativisticelectron Jun 15, 2022
0440df1
Merge branch '20220615_cypress_test' into 20220605_recipients
relativisticelectron Jun 15, 2022
f6b7b1c
improved tests
relativisticelectron Jun 15, 2022
5da60bc
working tests!
relativisticelectron Jun 15, 2022
1cb2fc4
BUGFIX
relativisticelectron Jun 15, 2022
d392156
Bugfix, again discovered through cypress
relativisticelectron Jun 15, 2022
a213403
added get_recipient_ids_in_order which gives the ordered ids as integers
relativisticelectron Jun 16, 2022
3a10ae4
fixed that csrf_token is not replaced in helpers.js
relativisticelectron Jun 16, 2022
af66ac3
Merge branch 'master' into 20220605_recipients
moneymanolis Jun 22, 2022
24946ab
bugfix
relativisticelectron Jun 23, 2022
de337b8
Merge remote-tracking branch 'cryptoadvance/master' into 20220605_rec…
relativisticelectron Jun 23, 2022
0f8a077
removed sortable_js
relativisticelectron Jun 28, 2022
50647c4
changed cypress test
relativisticelectron Jun 28, 2022
8b98666
made cypress test more strict
relativisticelectron Jun 28, 2022
40f9eb7
prototype
relativisticelectron Jun 29, 2022
f4b468e
working render box
relativisticelectron Jun 29, 2022
8bcce48
better onchange
relativisticelectron Jun 29, 2022
4f10c92
working render box and json is in request
relativisticelectron Jun 29, 2022
a0adb12
deleted useless class
relativisticelectron Jun 29, 2022
87fe402
some automation
relativisticelectron Jun 29, 2022
2378568
working generalization of the input form
relativisticelectron Jun 29, 2022
591ea55
made the attributes static
relativisticelectron Jun 29, 2022
6b87eee
recursion fix
relativisticelectron Jun 29, 2022
f3e5e88
rename
relativisticelectron Jun 29, 2022
bbc14ad
later html
relativisticelectron Jun 29, 2022
92d66f4
adding whole form without error, but wrong style
relativisticelectron Jun 29, 2022
9c10529
working style
relativisticelectron Jun 29, 2022
cdae83f
in the middle of moving functions to the template....
relativisticelectron Jun 29, 2022
f2ae780
working but slow
relativisticelectron Jun 30, 2022
16a3c21
no errors at least
relativisticelectron Jun 30, 2022
d3e2ffa
addid and removing works
relativisticelectron Jun 30, 2022
62e46b4
removed formAssociated and deJsonified the value
relativisticelectron Jun 30, 2022
3412819
working unit toggle
relativisticelectron Jun 30, 2022
51376ba
fixes and renamed
relativisticelectron Jun 30, 2022
5a3593a
working tx creation
relativisticelectron Jun 30, 2022
0ce085c
bugfix
relativisticelectron Jun 30, 2022
7277029
modified test
relativisticelectron Jun 30, 2022
d5172fa
css fix
relativisticelectron Jun 30, 2022
4a7b0e7
css fix
relativisticelectron Jun 30, 2022
4ea7098
send max fix
relativisticelectron Jun 30, 2022
138baec
moved also green address in webcomponent
relativisticelectron Jun 30, 2022
878a11f
refactor
relativisticelectron Jun 30, 2022
9619c63
Merge branch 'master' into 20220828_recipients_without_SortableJS
relativisticelectron Jun 30, 2022
cbdeb96
moved files
relativisticelectron Jun 30, 2022
aa6eac9
Merge remote-tracking branch 'origin/20220828_recipients_without_Sort…
relativisticelectron Jun 30, 2022
ccc1c0d
refactor
relativisticelectron Jun 30, 2022
52c72b3
refactor
relativisticelectron Jun 30, 2022
1ae4ad9
better events and some docs
relativisticelectron Jun 30, 2022
2cc7c3b
cleanup
relativisticelectron Jun 30, 2022
3bd55e8
doc
relativisticelectron Jun 30, 2022
1b4282e
now sending the combined dicts as a list (to preserve ordering)
relativisticelectron Jun 30, 2022
eb84ece
added margin
relativisticelectron Jul 1, 2022
5031b51
fixed most cypress issues
relativisticelectron Jul 1, 2022
cbffcb2
Merge remote-tracking branch 'cryptoadvance/master' into 20220828_rec…
relativisticelectron Jul 1, 2022
d34e36f
fixed cypress
relativisticelectron Jul 1, 2022
da54a91
Fixed the cypress test
relativisticelectron Jul 9, 2022
bdc7574
Merge branch 'master' into 20220828_recipients_without_SortableJS
relativisticelectron Jul 9, 2022
3f074ea
test fix: endpoint added
relativisticelectron Jul 12, 2022
1cb93b1
Merge branch 'master' into 20220828_recipients_without_SortableJS
relativisticelectron Jul 14, 2022
e59d2d6
Merge remote-tracking branch 'cryptoadvance/master' into 20220828_rec…
relativisticelectron Jul 18, 2022
e12361b
Merge remote-tracking branch 'cryptoadvance/master' into 20220828_rec…
relativisticelectron Jul 20, 2022
71444ab
keep subtract_from from within fee-selection.html
moneymanolis Jul 20, 2022
758c29b
Merge branch '20220828_recipients_without_SortableJS' of github.com:r…
moneymanolis Jul 20, 2022
cf35e8e
make subtract_from work again if recipients are deleted
moneymanolis Jul 21, 2022
5337935
camelCase
relativisticelectron Jul 21, 2022
96a8be6
better attributes
relativisticelectron Jul 22, 2022
de96d01
better attributes
relativisticelectron Jul 22, 2022
d5698d2
removed amount from init
relativisticelectron Jul 22, 2022
0f619bb
calculateConvertedUnit on set amount
relativisticelectron Jul 22, 2022
71c34c8
fixes
relativisticelectron Jul 22, 2022
47f8cf7
fix
relativisticelectron Jul 22, 2022
835423e
cypress changes and improvements
moneymanolis Jul 22, 2022
a16c966
improved styling
moneymanolis Jul 22, 2022
267bf75
hide delete button if there is only one recipient
moneymanolis Jul 22, 2022
255eadd
simplified hidden remove button
relativisticelectron Jul 23, 2022
06f1f6d
Merge branch 'master' into 20220828_recipients_without_SortableJS
relativisticelectron Jul 23, 2022
7fbd7a6
renamed hiddenCloseButton --> hiddenRemoveButton
relativisticelectron Jul 23, 2022
b9c5d60
Fixed calling external functions by now tiggering remove and send-ma…
relativisticelectron Jul 23, 2022
78f8913
Update src/cryptoadvance/specter/templates/wallet/send/new/wallet_sen…
relativisticelectron Jul 23, 2022
75fba10
cypress test for hiding delete button
moneymanolis Jul 23, 2022
a49b6c4
Merge branch '20220828_recipients_without_SortableJS' of github.com:r…
moneymanolis Jul 23, 2022
efb579b
replaced this.clone with clone
moneymanolis Jul 23, 2022
e1fabad
upgrade to new version of cypress
Jul 26, 2022
4d17fee
Merge remote-tracking branch 'cryptoadvance/master' into 20220828_rec…
relativisticelectron Jul 26, 2022
d6c8689
suggestion https://github.com/cryptoadvance/specter-desktop/pull/178…
relativisticelectron Jul 26, 2022
0e22b92
removing console.log
relativisticelectron Jul 26, 2022
85a4777
use addRecipient's arguments
relativisticelectron Jul 27, 2022
033baa6
updated description in psbt_creator
moneymanolis Jul 28, 2022
1b4c075
fix comments
relativisticelectron Jul 28, 2022
b3ff4d8
remove comment
relativisticelectron Jul 29, 2022
219ba42
remove 10⁻⁸
moneymanolis Jul 29, 2022
3e0f19d
Merge branch '20220828_recipients_without_SortableJS' of github.com:r…
moneymanolis Jul 29, 2022
7904f7a
Merge branch 'master' into 20220828_recipients_without_SortableJS
moneymanolis Jul 29, 2022
267cb99
don't initiate addRecipient with amount=0
moneymanolis Jul 30, 2022
e7d049f
Merge branch '20220828_recipients_without_SortableJS' of github.com:r…
moneymanolis Jul 30, 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
113 changes: 66 additions & 47 deletions src/cryptoadvance/specter/templates/includes/recipient-box.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@
</template>


<template id="liquid-asset-selector">
<select id="amount_unit" name="amount_unit" style="width: 100px;" >
<option value="btc">LBTC</option>
<option value="sat">L-sat (10⁻⁸ LBTC)</option>
{% for asset in wallet.balance.get("assets",{}).keys() | sort %}
<option value="{{asset}}">{{asset | assetlabel}}</option>
{% endfor %}
</select>
</template>

<template id="bitcoin-asset-selector">
<label><input id="amount_unit_sat" type="radio" class="inline" style="margin: 0 5px;" name="amount_unit" value="sat">sat</label>
<label><input id="amount_unit_btc" type="radio" class="inline" style="margin: 0 5px;" name="amount_unit" value="btc">BTC</label>
</template>



<script type="text/javascript">
class RecipientBox extends HTMLElement {
Expand All @@ -84,7 +100,6 @@

this.internals = this.attachInternals();
this.recipientId = null; // MUST be set for a functioning instance
this.unit = null; // will be calculated

this.buildHTML(); // created the html
this.attachListeners(); // attaches the listeners to some html objects
Expand All @@ -109,52 +124,48 @@
this.removeElement = clone.getElementById('remove');

this.shadowRoot.appendChild(clone);
this.addAssetSelectorToShadowRoot('', 'btc')
this.addAssetSelectorToShadowRoot()
}



// add the html code for the assetSelector
addAssetSelectorToShadowRoot(amount, amountUnit) {
if (amount >= 0){
this.amountElement.value = amount;
}


if (amountUnit == 'sat') {
amount = parseFloat(Number.parseFloat(amount * 1e8).toFixed(0));
if (amount == 'NaN') {
amount = '-'
}
}
let step = 1;
if (amountUnit == 'btc') {
step = 1e-8;
}
let satChecked = amountUnit == 'btc' ? '' : 'checked';
let btcChecked = amountUnit == 'btc' ? 'checked' : '';
let convertedUnit = amountUnit == 'btc' ? 'sat' : 'BTC';
this.shadowRoot.getElementById("converted_unit_label").innerText = convertedUnit;

addAssetSelectorToShadowRoot() {
// add different asset selector template for bitcoin and liquid
{% if specter.is_liquid and wallet.balance.get("assets", {}) %}
let assetSelector = `
<select name="amount_unit" style="width: 100px;" >
<option value="btc">LBTC</option>
<option value="sat">L-sat (10⁻⁸ LBTC)</option>
{% for asset in wallet.balance.get("assets",{}).keys() | sort %}
<option value="{{asset}}">{{asset | assetlabel}}</option>
{% endfor %}
</select>
`;
var template_content = document.getElementById('liquid-asset-selector').content;
var clone = template_content.cloneNode(true);

this.amountUnitElement = clone.getElementById('amount_unit');
// create custom getter and setter functions
this.setUnit = (newValue) => {
this.amountUnitElement.value = newValue;
this.updateUnitLabelAndStep();
}
this.getUnit = () => {
return this.amountUnitElement.value;
}
{% else %}
let assetSelector = `
<label><input type="radio" class="inline" style="margin: 0 5px;" name="amount_unit" value="sat" ${satChecked}>sat</label>
<label><input type="radio" class="inline" style="margin: 0 5px;" name="amount_unit" value="btc" ${btcChecked}>BTC</label>
`;
var template_content = document.getElementById('bitcoin-asset-selector').content;
var clone = template_content.cloneNode(true);

this.amountUnitSatElement = clone.getElementById('amount_unit_sat');
this.amountUnitBtcElement = clone.getElementById('amount_unit_btc');
// create custom getter and setter functions
this.setUnit = (newValue) => {
this.amountUnitBtcElement.checked = newValue == 'btc';
this.amountUnitSatElement.checked = newValue == 'sat';
this.updateUnitLabelAndStep();
}
this.getUnit = () => {
return this.amountUnitBtcElement.checked ? this.amountUnitBtcElement.value : this.amountUnitSatElement.value ;
}

// set the initial unit at creation
moneymanolis marked this conversation as resolved.
Show resolved Hide resolved
{% endif %}

this.shadowRoot.getElementById('asset_selector').innerHTML = assetSelector;

this.shadowRoot.getElementById('asset_selector').appendChild(clone);

}

Expand All @@ -166,15 +177,10 @@
// that need to trigger the same event
this.shadowRoot.querySelectorAll('[name="amount_unit"]').forEach(input => {
input.addEventListener('change',() => {
this.toggleUnit(input.value);
this.updateUnitLabelAndStep();

this.dispatchEvent(new CustomEvent('unit-change'));
});

// set unit at instance creation
if (input.checked){
this.toggleUnit(input.value);
}
});


Expand Down Expand Up @@ -262,7 +268,7 @@
// like <recipient-box title='title'></div> works.
static get observedAttributes() {
// define the attributes that can be defined via <recipient-box name="recipient-box" id='4'></recipient-box>
var attributes = ["value", "name", "id", "title", "address", "label",
var attributes = ["value", "name", "id", "title", "address", "label", "unit",
"recipientId", "max", "step", "amount", "hiddenRemoveButton"];
return attributes;
}
Expand All @@ -281,6 +287,8 @@
this.recipientId = newValue;
} else if (attribute=="label"){
this.label = newValue;
} else if (attribute=="unit"){
this.unit = newValue;
} else if (attribute=="step"){
this.step = newValue;
} else if (attribute=="max"){
Expand Down Expand Up @@ -321,6 +329,16 @@
return this.labelElement.value;
}

// unit
set unit(newValue){
// this function is different for bitcoin and liquid
this.setUnit(newValue);
}
get unit(){
// this function is different for bitcoin and liquid
return this.getUnit();
}

// step
set step(newValue){
this.amountElement.step = newValue;
Expand Down Expand Up @@ -350,6 +368,8 @@
}




// value
set value(newValue) {
// loop through all the keys and set the attributes
Expand Down Expand Up @@ -400,8 +420,7 @@



toggleUnit(unit) {
this.unit = unit;
updateUnitLabelAndStep() {
let unitLabelEl = this.shadowRoot.getElementById('converted_unit_label');
if(this.unit == 'sat'){
unitLabelEl.innerHTML = 'BTC';
Expand All @@ -410,7 +429,7 @@
}else{
unitLabelEl.innerHTML = '';
}
this.amountElement.setAttribute('step', this.unit == 'sat' ? '1' : '1e-8');
this.step = this.unit == 'sat' ? 1 : 1e-8;
this.calculateConvertedUnit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
})


function addRecipient(addr, amount, amount_unit, label) {
function addRecipient(address, amount, amount_unit, label) {
let recipientIds = getRecipientIds();
recipientId = 0;
if (recipientIds.length > 0) {
Expand All @@ -241,6 +241,10 @@
newRecipient.id = `recipient_${recipientId}`;
newRecipient.recipientId = recipientId;
newRecipient.title = `Recipient ${recipientId+1}`;
newRecipient.address = address;
newRecipient.amount = amount;
newRecipient.unit = amount_unit;
newRecipient.label = label;
newRecipient.addEventListener('remove', (event) => {
removeRecipient(newRecipient.recipientId);
})
Expand Down