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

fix: Update tx flow form when selecting a replacement nonce #2520

Merged
merged 5 commits into from
Sep 25, 2023

Conversation

usame-algan
Copy link
Member

@usame-algan usame-algan commented Sep 18, 2023

What it solves

Part of #2383

The form mode for the nonce form changed to onTouched with #2383 but selecting a nonce now doesn't update the form unless the user blurs the nonce input. This change calls onBlur() whenever the user selects something from the nonce replacement dropdown.

How to test it

  1. Open a safe with at least one transaction in queue
  2. Create a new transaction
  3. Go to the review screen
  4. Observe seeing the Sign flow
  5. Select the existing nonce from the nonce form
  6. Observe seeing the Execute flow

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 Sep 18, 2023

Branch preview

✅ Deploy successful!

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

@github-actions
Copy link

github-actions bot commented Sep 18, 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

Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

Good catch!

Copy link
Member

@schmanu schmanu left a comment

Choose a reason for hiding this comment

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

💯 Nice one!

@francovenica
Copy link
Contributor

So the main flow works fine, if the nonce is the next one to be executed the form allows execution, if is not only signing is possible.

Small issue:
There used to be a skeleton in the input that allow the load of the nonce without flickering. In this PR that skeleton is missing, so you can see the lowest nonces for a couple of seconds until it changes to the next nonce in the queue:
nonce input

@usame-algan
Copy link
Member Author

usame-algan commented Sep 20, 2023

I've reverted part of #2383 to have the previous validation UX (input is checked without having to blur) and instead added an effect to update the form value when the recommended nonce changes and IF the user has not touched the field yet. I've also added back the loading state. @schmanu @katspaugh can you check if this is the desired behaviour?

@@ -42,11 +42,12 @@ const SafeTxProvider = ({ children }: { children: ReactNode }): ReactElement =>
const isSigned = safeTx && safeTx.signatures.size > 0

// Recommended nonce and safeTxGas
const recommendedNonce = Math.max(safe.nonce, useRecommendedNonce() ?? 0)
const recommendedNonce = useRecommendedNonce()
const safeRecommendedNonce = recommendedNonce ? Math.max(safe.nonce, recommendedNonce) : undefined
Copy link
Member

Choose a reason for hiding this comment

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

IMHO this should be part of useRecommendedNonce

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I've moved it into the hook.

useEffect(() => {
if (formMethods.formState.touchedFields[TxNonceFormFieldNames.NONCE]) return

formMethods.setValue(TxNonceFormFieldNames.NONCE, recommendedNonce)
Copy link
Member

@katspaugh katspaugh Sep 20, 2023

Choose a reason for hiding this comment

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

Why is this needed? Can’t the input just be a controlled input? SafeTxContext returns a finalNonce which already contains the logic that differentiates user input and background updates.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I think the issue is that the validate calls setNonce automatically without user input so that the controlled input value nonce will never update to the recommended nonce. I've added an early return inside the validate function to skip validation if the input value is the same as nonce to avoid initial validation. This fixes the issue too and since we know that nonce is always valid it is ok to skip validation if the input value is the same.

Copy link
Member

@schmanu schmanu left a comment

Choose a reason for hiding this comment

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

I tried it out and it works fine.

@francovenica
Copy link
Contributor

Looks good to me.
The skeleton to hide the nonce loading is working fine
Changing the nonce (by writing, by selecting from the dropdown or using the circular arrow) changes the form to execution or only-siging just fine.

@usame-algan usame-algan merged commit 8256390 into dev Sep 25, 2023
9 checks passed
@usame-algan usame-algan deleted the fix-nonce-update branch September 25, 2023 07:40
@github-actions github-actions bot locked and limited conversation to collaborators Sep 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants