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 all commits
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
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ test_task:

cypress_test_task:
container:
image: registry.gitlab.com/cryptoadvance/specter-desktop/cypress-python:v9.5.4
image: registry.gitlab.com/cryptoadvance/specter-desktop/cypress-python:v9.7.0
cpu: 6
memory: 6G
pre_prep_script:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ tests/elements
signing_dir
site
docs/README.md
cypresstest-output.xml
1 change: 0 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@
"mochaFile": "cypresstest-output.xml",
"toConsole": true
}

}
10 changes: 0 additions & 10 deletions cypress/integration/spec_elm_single_segwit_wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ describe('Operating with an elements singlesig wallet', () => {
expect(newBalance).to.be.lte(oldBalance - 1.5)
})
})

// Workaround: Transaction does not disappear
cy.get('#btn_send').click()
// The "delete" button in the first psbt
cy.get('.row > :nth-child(2) > .btn').click()
})

it('send unconfidential transaction from segwit', () => {
Expand Down Expand Up @@ -83,11 +78,6 @@ describe('Operating with an elements singlesig wallet', () => {
expect(newBalance).to.be.lte(oldBalance - 1.5)
})
})

// Workaround: Transaction does not disappear
cy.get('#btn_send').click()
// The "delete" button in the first psbt
cy.get('.row > :nth-child(2) > .btn').click()
})

it('send unconfidential transaction from nested segwit', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/spec_ghost_machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ describe('Ghost machine', () => {
cy.viewport(1200,660)
cy.visit('/')
cy.addDevice('DIY ghost', 'Specter-DIY', 'ghost_machine')
cy.addWallet('Ghost wallet', null, 'segwit', 'funded', 'btc')
cy.addWallet('Ghost wallet', 'segwit', 'funded', 'btc', 'singlesig', 'DIY ghost')
})
})
2 changes: 1 addition & 1 deletion cypress/integration/spec_rescan.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Test the UI related to a blockchain rescan', () => {
it('Go to the rescan section from a fresh wallet', () => {
// Create a completely fresh wallet which is not receiving funds from the continous mining
cy.addDevice('Trezor hold', 'Trezor', 'hold_accident')
cy.addWallet('Fresh wallet', 'Trezor hold', 'segwit', false)
cy.addWallet('Fresh wallet', 'segwit', false, 'btc', 'singlesig', 'Trezor hold')
cy.get('#btn_transactions').click()
cy.get('#go-to-rescan-btn').click()
cy.get('#blockchain-rescan').should('be.visible')
Expand Down
224 changes: 146 additions & 78 deletions cypress/integration/spec_wallet_send.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cypress/integration/spec_wallet_utxo.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ describe('Test the actions in UTXO list', () => {

it('Managing unsigned transactions', () => {
// Make an unsigned tx
cy.get('#address_0').type("bcrt1qvtdx75y4554ngrq6aff3xdqnvjhmct5wck95qs") // address from "Ghost wallet"
cy.get('#send_max_0').click()
cy.get('#recipient_0').find('#address').type("bcrt1qvtdx75y4554ngrq6aff3xdqnvjhmct5wck95qs") // address from "Ghost wallet"
cy.get('#recipient_0').get('#send_max').click()
cy.get('#create_psbt_btn').click()
// Check the labeling of the unsigned UTXO
cy.log("Check the labeling of the unsigned UTXO")
Expand Down
67 changes: 42 additions & 25 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ Cypress.Commands.add("addDevice", (name, device_type, mnemonic) => {
Cypress.Commands.add("addHotDevice", (name, node_type) => {
// node_type is either elements or bitcoin
cy.get('body').then(($body) => {
cy.task("delete:elements-hotwallet")
if ($body.text().includes(name)) {
cy.get('#toggle_devices_list').click()
var refName = "#device_list_item_"+name.toLowerCase().replace(/ /g,"_")
cy.get(refName).click( {force: true} )
cy.get('#forget_device').click()
cy.deleteDevice(name)
// We might get an error here, if the device is used in a wallet
// We assume therefore that this is ok (see below)
}
Expand Down Expand Up @@ -149,40 +145,60 @@ Cypress.Commands.add("addHotWallet", (wallet_name, device_name, node_type, walle
})
})

Cypress.Commands.add("addWallet", (wallet_name, device_name, wallet_type, funded, node_type) => {
if (wallet_type == null) {
wallet_type = "segwit"
Cypress.Commands.add("addWallet", (walletName, walletType, funded, nodeType, keyType, deviceNameOne, deviceNameTwo, deviceNameThree) => {
if (walletType == null) {
walletType = "segwit"
}
if (device_name == null) {
device_name = "DIY ghost"
if (deviceNameOne == null) {
deviceNameOne = "DIY ghost"
}
cy.get('body').then(($body) => {
if ($body.text().includes(wallet_name)) {
cy.contains(wallet_name).click()
if ($body.text().includes(walletName)) {
cy.contains(walletName).click()
cy.get('#btn_settings' ).click( {force: true})
cy.get('#advanced_settings_tab_btn').click()
cy.get('#delete_wallet').click()
}
cy.get('#side-content').click()
cy.get('#btn_new_wallet').click()
cy.get('[href="./simple/"]').click()
var device_button = "#"+device_name.toLowerCase().replace(/ /g,"_")
cy.get(device_button).click()
cy.get('#wallet_name').type(wallet_name)
if (wallet_type == "nested_segwit") {
cy.get('#type_nested_segwit_btn').click()
if (keyType == 'singlesig') {
cy.get('[href="./simple/"]').click()
var device_button = "#"+deviceNameOne.toLowerCase().replace(/ /g,"_")
cy.get(device_button).click()
cy.get('#wallet_name').type(walletName)
if (walletType == "nested_segwit") {
cy.get('#type_nested_segwit_btn').click()
}
if (walletType == "taproot") {
cy.get('#type_taproot_btn').click()
}
}
if (wallet_type == "taproot") {
cy.get('#type_taproot_btn').click()
// Makes a 2 out 3 multisig
else if (keyType == "multisig") {
cy.get('[href="./multisig/"]').click()
var deviceButtonOne = "#"+deviceNameOne.toLowerCase().replace(/ /g,"_")
cy.get(deviceButtonOne).click()
var deviceButtonTwo = "#"+deviceNameTwo.toLowerCase().replace(/ /g,"_")
cy.get(deviceButtonTwo).click()
var deviceButtonThree = "#"+deviceNameThree.toLowerCase().replace(/ /g,"_")
cy.get(deviceButtonThree).click()
cy.get('#submit-device').click()
cy.get('#wallet_name').type(walletName)
if (walletType == "nested_segwit") {
cy.get('#type_nested_segwit_btn').click()
}
cy.get(':nth-child(9) > .inline').clear()
cy.get(':nth-child(9) > .inline').type(2)
}
cy.get('#keysform > .centered').click()
cy.get('body').contains("New wallet was created successfully!")
cy.get('#btn_continue').click()
cy.get('#page_overlay_popup_cancel_button').click()
if (funded) {
cy.mine2wallet(node_type)
cy.mine2wallet(nodeType)
}
})
})

Cypress.Commands.add("deleteWallet", (name) => {
cy.get('body').then(($body) => {
if ($body.text().includes(name)) {
Expand Down Expand Up @@ -234,9 +250,10 @@ Cypress.Commands.add("mine2wallet", (chain) => {
// Quick and easy way to fill out the send form and create a psbt
Cypress.Commands.add("createPsbt", (address, label="a_label", amount=0.01) => {
cy.get('#btn_send').click()
cy.get('#address_0').type(address)
cy.get('#label_0').type(label)
// it is not clear why .shadow(), or { includeShadowDom: true } is needed here to find the elements in the ShadowDOM, but not in the other cypresss tests
moneymanolis marked this conversation as resolved.
Show resolved Hide resolved
cy.get('#recipient_0').find('#address', { includeShadowDom: true }).type(address)
cy.get('#recipient_0').find('#label', { includeShadowDom: true }).type(label)
//cy.get('#send_max_0').click()
cy.get('#amount_0').type(amount)
cy.get('#recipient_0').find('#amount', { includeShadowDom: true }).type(amount)
cy.get('#create_psbt_btn').click()
})
2 changes: 1 addition & 1 deletion docker/cypress-python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ RUN DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y

WORKDIR /test
RUN rm -rf node_modules package-lock.json ~/.cache/Cypress
RUN npm install --save-dev cypress@9.5.4
RUN npm install --save-dev cypress@9.7.0
RUN $(npm bin)/cypress verify
9 changes: 6 additions & 3 deletions docker/cypress-python/Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

An image, ready to be used with cypress but also provides all the dependencies we need for testing specter-desktop.
Use versions of cypress as the version part of the tag. So e.g.:

```
docker build . -t registry.gitlab.com/cryptoadvance/specter-desktop/cypress-python
docker push registry.gitlab.com/cryptoadvance/specter-desktop/cypress-python
```
docker build . -t registry.gitlab.com/cryptoadvance/specter-desktop/cypress-python:v9.7.0
docker push registry.gitlab.com/cryptoadvance/specter-desktop/cypress-python:v9.7.0
```

Search for `cypress-python` on where this is used in the project.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"wait-on": "^5.3.0"
},
"devDependencies": {
"cypress": "^9.5.4",
"cypress": "^9.7.0",
"cypress-wait-until": "^1.7.1"
},
"scripts": {
Expand Down
41 changes: 23 additions & 18 deletions src/cryptoadvance/specter/commands/psbt_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def __init__(
):
"""
* depending of ui_option = (ui|text) Fill the payment-details in either of these:
* request_form: expects the payment-details in a dict request_form:
{ "address_1":"bc1...","btc_amount_1":"0.2", "amount_unit_1":"btc", "label_1":"someLabel","address_2": ...}
* request_form: For details on the structure of the data for each recipient (amounts, addresses, etc.) see below at paymentinfo_from_ui
* recipients_txt: expects the payment-details in textblock "recipients" and recipients_amount_unit for all
amounts in recipients_txt either "sats" or "btc"
* in both cases, the request_form also contains:
Expand Down Expand Up @@ -135,32 +134,39 @@ def create_psbt(self, wallet):

@classmethod
def paymentinfo_from_ui(cls, specter, wallet, request_form):
"""calculates the correct format needed by wallet.createpsbt() out of a request-form
returns something like (addresses, labels, amounts, amount_units) (all arrays)
"""Calculates the correct format needed by wallet.createpsbt() out of a request form.
The recipient_dicts part in the form is a list of dicts and looks like this:
[{'unit': 'btc', 'amount': 1, 'btc_amount': 1, 'recipient_id': 0, 'label': '', 'address': 'bcrt1q ... 58qwn'},
{'unit': 'btc', 'amount': 2, 'btc_amount': 2, 'recipient_id': 1, 'label': '', 'address': 'bcrt1q ... vaa3p'},
{'unit': 'btc', 'amount': 3, 'btc_amount': 3, 'recipient_id': 2, 'label': '', 'address': 'bcrt1q ... n0a85'}]

Returns (addresses, labels, amounts, amount_units) (all arrays)
"""
i = 0
addresses = []
labels = []
amounts = []
amount_units = []
while "address_{}".format(i) in request_form:
addresses.append(request_form["address_{}".format(i)])

recipient_dicts = json.loads(request_form["recipient_dicts"])
print(recipient_dicts)
for recipient_dict in recipient_dicts:
addresses.append(recipient_dict["address"])
amount = 0.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not strictly related to this PR, but what's the point of this line?

Copy link
Collaborator Author

@relativisticelectron relativisticelectron Jul 19, 2022

Choose a reason for hiding this comment

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

I guess this line could be moved into the except part...

try:
amount = float(request_form["btc_amount_{}".format(i)])
amount = float(recipient_dict["btc_amount"])
except ValueError:
pass
if isnan(amount):
amount = 0.0
amounts.append(amount)
unit = request_form["amount_unit_{}".format(i)]
unit = recipient_dict["unit"]
if specter.is_liquid and unit in ["sat", "btc"]:
unit = specter.default_asset
amount_units.append(unit)
labels.append(request_form["label_{}".format(i)])
if request_form["label_{}".format(i)] != "":
wallet.setlabel(addresses[i], labels[i])
i += 1
labels.append(recipient_dict["label"])
if recipient_dict["label"] != "":
wallet.setlabel(addresses[-1], labels[-1])

return addresses, labels, amounts, amount_units

@classmethod
Expand All @@ -170,7 +176,6 @@ def paymentinfo_from_text(
"""calculates the correct format needed by wallet.createpsbt() out of a request-form
out of a textbox holding addresses and amounts.
"""
i = 0
addresses = []
labels = []
amounts = []
Expand Down Expand Up @@ -264,7 +269,7 @@ def kwargs_from_request_form(request_form):
"""calculates the needed kwargs fow wallet.createpsbt() out of a request_form"""
# Who pays the fees?
subtract = str2bool(request_form.get("subtract", False))
subtract_from = int(request_form.get("subtract_from", 1))
subtract_from = int(request_form.get("subtract_from", 0))
fee_option = request_form.get("fee_option")
fee_rate = None
if fee_option:
Expand Down Expand Up @@ -296,7 +301,7 @@ def kwargs_from_request_form(request_form):
rbf_tx_id = request_form.get("rbf_tx_id", "")
kwargs = {
"subtract": subtract,
"subtract_from": subtract_from - 1,
"subtract_from": subtract_from,
"fee_rate": fee_rate,
"rbf": rbf,
"selected_coins": selected_coins,
Expand All @@ -319,14 +324,14 @@ def kwargs_from_request_json(cls, request_json):
except JSONDecodeError as e:
raise SpecterError(f"Error parsing json: {e}")
subtract = bool(json_data.get("subtract", False))
subtract_from = int(json_data.get("subtract_from", 1))
subtract_from = int(json_data.get("subtract_from", 0))

fee_rate = float(json_data.get("fee_rate", None))
rbf = bool(json_data.get("rbf", False))
rbf_tx_id = json_data.get("rbf_tx_id", "")
kwargs = {
"subtract": subtract,
"subtract_from": subtract_from - 1,
"subtract_from": subtract_from,
"fee_rate": fee_rate,
"rbf": rbf,
"selected_coins": [],
Expand Down
3 changes: 3 additions & 0 deletions src/cryptoadvance/specter/liquid/addresslist.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ def get(self, addr, default=None):
return self[addr]
except KeyError:
return default
except TypeError:
logger.warning(f"{addr} seems to be invalid")
return default
2 changes: 1 addition & 1 deletion src/cryptoadvance/specter/server_endpoints/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def send_new(wallet_alias):
recipients_txt = ""
fillform = False
subtract = False
subtract_from = 1
subtract_from = 0
fee_options = "dynamic"
rbf = not app.specter.is_liquid
rbf_utxo = []
Expand Down
18 changes: 18 additions & 0 deletions src/cryptoadvance/specter/server_endpoints/wallets_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,24 @@ def utxo_csv(wallet_alias):
return _("Failed to export wallet utxo. Error: {}").format(e), 500


@wallets_endpoint_api.route(
"/wallet/<wallet_alias>/is_address_mine/<address>", methods=["GET"]
)
@login_required
def is_address_mine(wallet_alias, address):
wallet = app.specter.wallet_manager.get_by_alias(wallet_alias)

# filter out invalid input
if (not address) or not isinstance(address, str):
return jsonify(False)

# Segwit addresses are always between 14 and 74 characters long.
if len(address) < 14:
return jsonify(False)

return jsonify(wallet.is_address_mine(address))


@wallets_endpoint_api.route("/wallet/<wallet_alias>/send/estimatefee", methods=["POST"])
@login_required
def estimate_fee(wallet_alias):
Expand Down
Loading