beam-ui
beam-ui copied to clipboard
Allow pasting address containing trailing or leading spaces
Task description Allow user to paste addresses to the address field if the pasted address contains trailing or leading space(s).
To Reproduce Pre-conditions: A UI wallet is installed and running. Steps to reproduce the behaviour:
- Copy an address that contains spaces, e.g.
' 736e4958d8e9caf473d8c1091e9f5502696df41e811189d4e6e4373bea372edadf'
or'736e4958d8e9caf473d8c1091e9f5502696df41e811189d4e6e4373bea372edadf '
- In the Send screen - paste it to the address field.
Current behaviour The address is not pasted.
Expected behaviour The address is pasted successfully. If the string contains trailing or leading spaces - we need to ignore them.
Platform and build
- All platforms
- BEAM Build number: Masternet, 5156.
Screenshots (if applicable)
I'd like to work on this
Sure, have fun))
@anatolse I can fix this issue directly in the file: send_regular.qml by simply removing the spaces after the Regular Expression Validator has allowed spaces at start and end of address. I think that is not really the correct way to do it. But it's simple.
Otherwise, I can derive a new validator by subclassing QValidator
and implementing its fixup() method. I could call the class SendAddressValidator
or whatever seems appropriate to you. This way could remove the spaces before being validated - that way would not need to allow spaces in the regular expression at all.
I probably should inherit directly from QRegularExpressionValidator
and just implement or override its fixup()
method. And name the class SendAddressRegularExpressionValidator
. No?
How should I proceed? Simple way or Correct way?
A custom validator sounds good. But I would try to allow leading and trailing spaces in regexp, and trim them in https://github.com/BeamMW/beam-ui/blob/d79b8261567efa2c3af187537e37f32859c4c3dd/ui/viewmodel/send_view.cpp#L238
A custom validator sounds good. But I would try to allow leading and trailing spaces in regexp, and trim them in
I'm not 100% what you meant, but I'll explain my thinking:
The regular expression in the QML file should exactly represent what a valid address is allowed to look like. That means the regular expression should not have spaces allowed at either side. The new class which, inherits from QRegularExpressionValidator, will check if the regular expression is Invalid. If invalid, it will call its fixup() method which only trims spaces at start and end of string, and then recall the parent validate method (because it could have been something other than spaces which made it invalid). Then it will return this final QValidator::State it received from parent validate method. It works perfectly, and makes sense.
I suggest the new class should be named something like WSTrimmingRegularExpressionValidator or WSTrimRegularExpressionValidator, or TrimWSRegularExpressionValidator, rather than name it as SendAddressRegularExpressionValidator, as it could be used more broadly.
And then there is the matter of where to locate the class files. If done as mentioned, and named so, should it be in the viewmodel/helpers folder (or somewhere else) rather than in the viewmodel folder directly ?