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

[TX flow] Adds nonce validation #2175

Merged
merged 9 commits into from
Jun 29, 2023
Merged

[TX flow] Adds nonce validation #2175

merged 9 commits into from
Jun 29, 2023

Conversation

usame-algan
Copy link
Member

@usame-algan usame-algan commented Jun 26, 2023

What it solves

Resolves #2110

How this PR fixes it

  • Displays an error message in a tooltip around the nonce form
  • Always displays the reset button but in a disabled state to prevent the input from jumping

How to test it

  1. Open the Safe
  2. Create a new transaction
  3. Choose a nonce lower than the current safe nonce
  4. Observe an error inside a tooltip

Screenshots

Screenshot 2023-06-26 at 17 08 10

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

@github-actions
Copy link

github-actions bot commented Jun 26, 2023

Branch preview

✅ Deploy successful!

https://nonce_validation--walletweb.review-wallet-web.5afe.dev

@usame-algan
Copy link
Member Author

We should also think about disabling the "Next" and "Submit" button if the nonce is invalid. Previously this was covered since the nonce was edited in a separate modal and the user couldn't leave without entering a valid input there. I suggest we add another state nonceError to the context but it would have to be added to every component that has Next or Submit buttons.

@github-actions
Copy link

github-actions bot commented Jun 26, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@usame-algan
Copy link
Member Author

Should we also limit the maximum number the user can enter or additionally show another warning/error if the input is much higher than the current nonce? Currently, if the user keeps typing the number changes to "Infinity" at some point which is handled as a valid input.

@@ -224,7 +224,7 @@ const CreateTokenTransfer = ({
</FormControl>

{isDisabled && (
<Box mt={1} display="flex" alignItems="center">
<Box display="flex" alignItems="center" mt={-2} mb={3}>
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes the issue that the safe error is too close to the divider

@katspaugh
Copy link
Member

katspaugh commented Jun 26, 2023

We should also think about disabling the "Next" and "Submit" button if the nonce is invalid. Previously this was covered since the nonce was edited in a separate modal and the user couldn't leave without entering a valid input there. I suggest we add another state nonceError to the context but it would have to be added to every component that has Next or Submit buttons.

How about just not letting the user choose an incorrect nonce? I assumed this validation would do that.

@usame-algan
Copy link
Member Author

After our discussion:

  1. We don't set the nonce if there is a validation error. Once the user blurs the input it will reset back to the previous value that was valid
  2. Add a max number input validation so it doesn't flip to "Infinity"

Copy link
Member

@iamacook iamacook left a comment

Choose a reason for hiding this comment

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

I'm not sure about preventing the deletion of the value. I was initially confused why I couldn't backspace. (Here I'm trying to delete the value:)

nonce

}

if (nonce >= Number.MAX_SAFE_INTEGER) {
return 'Nonce is too big'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return 'Nonce is too big'
return 'Nonce is too high'

Comment on lines 83 to 86
const isNotValid = validateInput(value)

if (isNotValid) {
setError(validateInput(value))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const isNotValid = validateInput(value)
if (isNotValid) {
setError(validateInput(value))
const error = validateInput(value)
if (error) {
setError(error)

)

const handleBlur = useCallback(() => {
setError(undefined)
Copy link
Member

@iamacook iamacook Jun 27, 2023

Choose a reason for hiding this comment

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

What if the current nonce is erroneous?

Edit: this ties in with my review summary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we don't save the nonce if its incorrect the current nonce must be correct so we can safely remove the error.

@iamacook
Copy link
Member

For visibility (as per our discussion) two thoughts:

  1. A Tooltip inside a Tooltip seemed initially wrong. However, MUI mounts a Popper outside of the children so that's ok.
  2. When replacing a transaction, we should disable nonce editing:
    image

@usame-algan
Copy link
Member Author

usame-algan commented Jun 28, 2023

I'm not sure about preventing the deletion of the value. I was initially confused why I couldn't backspace. (Here I'm trying to delete the value:)

I agree its not ideal but since we use the same value for controlling the input we can't easily let the user remove and not update it.

When replacing a transaction, we should disable nonce editing:

Thanks for catching this. I updated both the replace and reject flow to work now. For replacing a transaction we need to call setTxNonce to overwrite the state with the nonce that is passed. For simple rejections we can just disable the nonce field. I've added a helper function to detect reject txs so we don't have to pass a flag anymore like we did in the old tx flow.

@iamacook
Copy link
Member

iamacook commented Jun 28, 2023

I agree its not ideal but since we use the same value for controlling the input we can't easily let the user remove and not update it.

We could save the new nonce if validation fails and not return early or have a local state that saves the nonce onBlur, for example.

iamacook and others added 3 commits June 29, 2023 14:21
# Conflicts:
#	src/components/tx-flow/common/TxNonce/index.tsx
#	src/components/tx-flow/flows/TokenTransfer/CreateTokenTransfer.tsx
@iamacook iamacook linked an issue Jun 29, 2023 that may be closed by this pull request
@usame-algan usame-algan merged commit 75f142d into epic-tx-flow Jun 29, 2023
6 of 7 checks passed
@usame-algan usame-algan deleted the nonce-validation branch June 29, 2023 13:53
@github-actions github-actions bot locked and limited conversation to collaborators Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TX flow] Nonce form
3 participants