Add validation to the Send form (address and amount) #462

Closed
johnny9 wants to merge 9 commits from send-validation into main AGit
johnny9 commented 2025-06-01 17:44:50 +00:00 (Migrated from github.com)

This is built on top of https://github.com/bitcoin-core/gui-qml/pull/450 so when reviewing, its best to select just the new commits in the "Files changed" tab.

These changes add properties for the error strings used in the QML to SendRecipient and add validation methods that are checked when the relevant properties are changed by the user.

Screenshot from 2025-06-01 12-42-20

This is built on top of https://github.com/bitcoin-core/gui-qml/pull/450 so when reviewing, its best to select just the new commits in the "Files changed" tab. These changes add properties for the error strings used in the QML to SendRecipient and add validation methods that are checked when the relevant properties are changed by the user. ![Screenshot from 2025-06-01 12-42-20](https://git.fish.foo/attachments/06424a2d-d34f-4045-9cb5-9cd9e0018305)
goqusan (Migrated from github.com) reviewed 2025-06-02 08:12:07 +00:00
goqusan (Migrated from github.com) commented 2025-06-02 08:08:01 +00:00

avoid clearing and setting - it would evaluate qml bindings twice.

avoid clearing and setting - it would evaluate qml bindings twice.
goqusan (Migrated from github.com) commented 2025-06-02 08:12:02 +00:00

could remove this case for now as it allows removing the circular dependency?

could remove this case for now as it allows removing the circular dependency?
goqusan (Migrated from github.com) commented 2025-06-02 08:08:14 +00:00
  • const
* const
GBKS commented 2025-06-02 12:31:08 +00:00 (Migrated from github.com)

Nice addition. A few notes:

  1. Can we restrict the character input altogether, so I can only enter numbers (and periods/commas) in the amount field and only allowed characters in the address field?
  2. We should also add a max length. I think 62 is max for addresses, and 17 for bitcoin amounts (21000000.00000000). Not 100% on those numbers. Either way, right now I can type in infinite characters, so some restriction would be good.
  3. I was not able to get any address to validate (grabbed a few different address types from here).
  4. I see the error "Amount exceeds maximum limit". Would be more useful if it states the limit, like "The maximum is 21,000,000." or so - sneak in the supply cap.
  5. When I enter a huge number and deselect the field, the number changes. Not sure why, and I could not find a pattern how it changes.
  6. For an empty wallet, there is the question whether the Send form should be enabled at all.

Always a bit finicky these input fields.

Nice addition. A few notes: 1. Can we restrict the character input altogether, so I can only enter numbers (and periods/commas) in the amount field and only allowed characters in the address field? 2. We should also add a max length. I think 62 is max [for addresses](https://bitcoin.design/guide/glossary/address/), and 17 for bitcoin amounts (21000000.00000000). Not 100% on those numbers. Either way, right now I can type in infinite characters, so some restriction would be good. 3. I was not able to get any address to validate (grabbed a few different address types from [here](https://iancoleman.io/bip39/#english)). 5. I see the error "Amount exceeds maximum limit". Would be more useful if it states the limit, like "The maximum is 21,000,000." or so - sneak in the supply cap. 6. When I enter a huge number and deselect the field, the number changes. Not sure why, and I could not find a pattern how it changes. 7. For an empty wallet, there is the question whether the Send form should be enabled at all. Always a bit finicky these input fields.
MarnixCroes (Migrated from github.com) reviewed 2025-06-02 19:19:38 +00:00
MarnixCroes (Migrated from github.com) left a comment

1e81bb677c

  • the UX is better if the verification is done without having to change focus from the field:

Screencast from 2025-06-02 13-12-13.webm

  • the amount converter doesn't seem to be working as it should:

Screencast from 2025-06-02 13-14-41.webm

1e81bb677c35aa599547507e44a3a9f7d82eee54 - the UX is better if the verification is done without having to change focus from the field: [Screencast from 2025-06-02 13-12-13.webm](https://github.com/user-attachments/assets/43543599-af36-4718-b385-490ceefa92af) - the amount converter doesn't seem to be working as it should: [Screencast from 2025-06-02 13-14-41.webm](https://github.com/user-attachments/assets/f563d368-d95b-4535-aa7c-5d521f6c2805)
johnny9 commented 2025-06-03 14:56:13 +00:00 (Migrated from github.com)

1e81bb6

* the UX is better if the verification is done without having to change focus from the field:

Good catch, I will split up the validation and formatting helpers so that validation can happen while editing and it will reformat once editing is finished.

Screencast.from.2025-06-02.13-12-13.webm

* the amount converter doesn't seem to be working as it should:

Screencast.from.2025-06-02.13-14-41.webm

bummer, must have introduced a bug with conversion. I will double check the sats to btc conversion.

> [1e81bb6](https://github.com/bitcoin-core/gui-qml/commit/1e81bb677c35aa599547507e44a3a9f7d82eee54) > > * the UX is better if the verification is done without having to change focus from the field: Good catch, I will split up the validation and formatting helpers so that validation can happen while editing and it will reformat once editing is finished. > > Screencast.from.2025-06-02.13-12-13.webm > > * the amount converter doesn't seem to be working as it should: > > > Screencast.from.2025-06-02.13-14-41.webm bummer, must have introduced a bug with conversion. I will double check the sats to btc conversion.
johnny9 commented 2025-06-03 15:00:23 +00:00 (Migrated from github.com)

Nice addition. A few notes:

  1. Can we restrict the character input altogether, so I can only enter numbers (and periods/commas) in the amount field and only allowed characters in the address field?
    Yes, I can add validators to restrict inputs into this form
  2. We should also add a max length. I think 62 is max for addresses, and 17 for bitcoin amounts (21000000.00000000). Not 100% on those numbers. Either way, right now I can type in infinite
    characters, so some restriction would be good.

I will look at what options there are to restrict the character limit

  1. I was not able to get any address to validate (grabbed a few different address types from here).

Thats interesting. I will double check. Could it be regtest/testnet/mainnet differences in format.

  1. I see the error "Amount exceeds maximum limit". Would be more useful if it states the limit, like "The maximum is 21,000,000." or so - sneak in the supply cap.

I can update the error string to include this

  1. When I enter a huge number and deselect the field, the number changes. Not sure why, and I could not find a pattern how it changes.

This is a precursor to what will end up being the rich formatting of the amount. If you are inputing BTC amounts it will add the satoshi trailing 0's

  1. For an empty wallet, there is the question whether the Send form should be enabled at all.

Always a bit finicky these input fields.

I will consider this.

> Nice addition. A few notes: > > 1. Can we restrict the character input altogether, so I can only enter numbers (and periods/commas) in the amount field and only allowed characters in the address field? Yes, I can add validators to restrict inputs into this form > 2. We should also add a max length. I think 62 is max [for addresses](https://bitcoin.design/guide/glossary/address/), and 17 for bitcoin amounts (21000000.00000000). Not 100% on those numbers. Either way, right now I can type in infinite characters, so some restriction would be good. I will look at what options there are to restrict the character limit > 3. I was not able to get any address to validate (grabbed a few different address types from [here](https://iancoleman.io/bip39/#english)). Thats interesting. I will double check. Could it be regtest/testnet/mainnet differences in format. > 4. I see the error "Amount exceeds maximum limit". Would be more useful if it states the limit, like "The maximum is 21,000,000." or so - sneak in the supply cap. I can update the error string to include this > 5. When I enter a huge number and deselect the field, the number changes. Not sure why, and I could not find a pattern how it changes. This is a precursor to what will end up being the rich formatting of the amount. If you are inputing BTC amounts it will add the satoshi trailing 0's > 6. For an empty wallet, there is the question whether the Send form should be enabled at all. > > Always a bit finicky these input fields. I will consider this.
johnny9 (Migrated from github.com) reviewed 2025-06-03 15:31:24 +00:00
johnny9 (Migrated from github.com) commented 2025-06-03 15:31:24 +00:00

ill take another look at this

ill take another look at this
johnny9 (Migrated from github.com) reviewed 2025-06-03 15:35:25 +00:00
johnny9 (Migrated from github.com) commented 2025-06-03 15:35:25 +00:00

I think this might be a good idea and I can just do this validation when creating the transaction in the wallet model

I think this might be a good idea and I can just do this validation when creating the transaction in the wallet model
johnny9 commented 2025-06-04 04:39:57 +00:00 (Migrated from github.com)

Update from 1e81bb6 to a5aba54

  • rebased with main
Update from [1e81bb6](https://github.com/bitcoin-core/gui-qml/commit/1e81bb677c35aa599547507e44a3a9f7d82eee54) to [a5aba54](https://github.com/bitcoin-core/gui-qml/commit/a5aba54dbc22c5c7fe9e681a3922c41ab1ff649c) - rebased with main -
johnny9 (Migrated from github.com) reviewed 2025-06-04 05:30:42 +00:00
johnny9 (Migrated from github.com) commented 2025-06-04 05:30:42 +00:00

I think im going to leave the circular dependency in for now.and take another look when doing validation with multiple recipients

I think im going to leave the circular dependency in for now.and take another look when doing validation with multiple recipients
MarnixCroes (Migrated from github.com) reviewed 2025-06-04 22:31:05 +00:00
MarnixCroes (Migrated from github.com) left a comment

tested LGTM 3630bc28744b3a2b9f4521af6756c2c9254d15a9

Note that when entering full balance, Review is highlighted but not clickable.

As the GUI won't allow creating tx's with 0 fees, maybe Review should only be highlighted when amount < balance

tested LGTM 3630bc28744b3a2b9f4521af6756c2c9254d15a9 Note that when entering full balance, `Review` is highlighted but not clickable. As the GUI won't allow creating tx's with 0 fees, maybe `Review` should only be highlighted when amount < balance
GBKS commented 2025-06-05 09:59:46 +00:00 (Migrated from github.com)

Looking good.

Address input

  1. I just fixed some of the input logic in the prototype, so it properly breaks into multiple lines and applies for formatting. Not sure if you're referencing that right now or not.

Amount input

  1. Do we need to force the 8 decimals for bitcoin amounts? Seems easier to just have 0.1 rather than 0.10000000.
  2. The unit toggle needs hover states
  3. As I mentioned before, when the amount exceeds the balance, we discussed showing Balance: 0,00348200 ₿. Send max., where Send max is underlined and a button that inserts the full balance into the input field. I have this partially working in the prototype, but need to fix some logic. Gets a little tricky when we also have the Include fee in amount toggle and multiple recipients. Maybe something for a separate PR?
Looking good. **Address input** 1. I just fixed some of the input logic in the [prototype](https://lively-kashata-cfde7e.netlify.app/screen/send), so it properly breaks into multiple lines and applies for formatting. Not sure if you're referencing that right now or not. **Amount input** 1. Do we need to force the 8 decimals for bitcoin amounts? Seems easier to just have `0.1` rather than `0.10000000`. 2. The unit toggle needs hover states 3. As I mentioned before, when the amount exceeds the balance, we discussed showing `Balance: 0,00348200 ₿. Send max.`, where `Send max` is underlined and a button that inserts the full balance into the input field. I have this partially working in the [prototype](https://lively-kashata-cfde7e.netlify.app/screen/send), but need to fix some logic. Gets a little tricky when we also have the `Include fee in amount` toggle and multiple recipients. Maybe something for a separate PR?
johnny9 commented 2025-06-05 19:57:34 +00:00 (Migrated from github.com)

tested LGTM 3630bc2

Note that when entering full balance, Review is highlighted but not clickable.

As the GUI won't allow creating tx's with 0 fees, maybe Review should only be highlighted when amount < balance

This is a good one. I will add an issue to include this in my validation when I add proper fee estimation.

> tested LGTM [3630bc2](https://github.com/bitcoin-core/gui-qml/commit/3630bc28744b3a2b9f4521af6756c2c9254d15a9) > > Note that when entering full balance, `Review` is highlighted but not clickable. > > As the GUI won't allow creating tx's with 0 fees, maybe `Review` should only be highlighted when amount < balance This is a good one. I will add an issue to include this in my validation when I add proper fee estimation.
johnny9 commented 2025-07-10 12:18:39 +00:00 (Migrated from github.com)

Update from 3630bc2 to 29e568c

  • Rebased with main
Update from [3630bc2](https://github.com/bitcoin-core/gui-qml/commit/3630bc28744b3a2b9f4521af6756c2c9254d15a9) to [29e568c](https://github.com/bitcoin-core/gui-qml/commit/29e568cc1dbf0fada047481b7b650090acc392ba) - Rebased with main
MarnixCroes (Migrated from github.com) reviewed 2025-07-18 19:46:25 +00:00
MarnixCroes (Migrated from github.com) left a comment

29e568cc1d
LGTM,

a few minor comments:

  • it's possible to have the Amount exceeds balance while the entry is 0.
    This happens when you delete the full entry by selecting and deleting in full. Using backspace to get to zero works as it should.
    Screenshot from 2025-07-18 13-35-11
29e568cc1dbf0fada047481b7b650090acc392ba LGTM, a few minor comments: - it's possible to have the `Amount exceeds balance` while the entry is 0. This happens when you delete the full entry by selecting and deleting in full. Using backspace to get to zero works as it should. <img width="708" height="545" alt="Screenshot from 2025-07-18 13-35-11" src="https://git.fish.foo/attachments/2b71c867-7c96-4ad4-b30b-bf625fb49801" />
MarnixCroes (Migrated from github.com) commented 2025-07-18 19:43:35 +00:00

I'm able to enter zero without the error.
The error was displayed the first time I entered 0, after that the error wasn't there anymore

image
I'm able to enter zero without the error. The error was displayed the first time I entered 0, after that the error wasn't there anymore <img width="507" height="97" alt="image" src="https://git.fish.foo/attachments/d4e160ed-8623-4ee6-896d-b193727a9eef" />
MarnixCroes (Migrated from github.com) commented 2025-07-18 19:31:30 +00:00

I understand the intention, but I'm not sure if this hard coded value is a good idea.

I understand the intention, but I'm not sure if this hard coded value is a good idea.
MarnixCroes (Migrated from github.com) commented 2025-07-18 19:45:33 +00:00

the placeholderText should probably also be dependent on the unit.
i.e. makes no sense to display 0.0000000 when using sats.

maybe for follow up.

the placeholderText should probably also be dependent on the unit. i.e. makes no sense to display 0.0000000 when using sats. maybe for follow up.
hebasto commented 2025-07-25 20:21:01 +00:00 (Migrated from github.com)

Closing for now.

Feel free to reopen this based on the new default branch.

Closing for now. Feel free to reopen this based on the new [default](https://github.com/bitcoin-core/gui-qml/tree/qt6) branch.
Sign in to join this conversation.
No description provided.