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: Nonce form #2120

Merged
merged 7 commits into from
Jun 20, 2023
Merged

fix: Nonce form #2120

merged 7 commits into from
Jun 20, 2023

Conversation

usame-algan
Copy link
Member

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

What it solves

Resolves #2110

How this PR fixes it

  • Uses the previous nonce input field with queued txs dropdown and reset to recommended nonce button

How to test it

  1. Open the new tx flow
  2. Observe a nonce input in the top right corner
  3. Change the value
  4. Observe a reset button appearing
  5. Click into the input field
  6. Observe a dropdown that shows all queued txs

Screenshots

Screenshot 2023-06-19 at 09 30 06 Screenshot 2023-06-19 at 09 30 17 Screenshot 2023-06-19 at 09 30 29 Screenshot 2023-06-19 at 13 39 57

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 19, 2023

Branch preview

✅ Deploy successful!

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

Comment on lines 81 to 87
const validateInput = (value: string) => {
if (!Number.isInteger(value)) {
return false
} else if (Number(value) < safeNonce) {
return false
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously we displayed error messages but with the new input field there is no room for it.

@github-actions
Copy link

github-actions bot commented Jun 19, 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

Comment on lines 62 to 78
const queuedTxs = useMemo(() => {
if (!page || page.results.length === 0) {
return []
}

const txs = page.results.filter(isTransactionListItem).map((item) => item.transaction)

return uniqBy(txs, (tx) => {
return isMultisigExecutionInfo(tx.executionInfo) ? tx.executionInfo.nonce : ''
})
}, [page])

const options = useMemo(() => {
return queuedTxs
.map((tx) => (isMultisigExecutionInfo(tx.executionInfo) ? tx.executionInfo.nonce : undefined))
.filter((nonce) => nonce !== undefined) as number[]
}, [queuedTxs])
Copy link
Member

Choose a reason for hiding this comment

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

Could you move this into a hook? Like usePreviousNonces?

const { nonce, setNonce, safeTx } = useContext(SafeTxContext)
const { page } = useTxQueue()
const { safe } = useSafeInfo()
const safeNonce = safe.nonce || 0
Copy link
Member

Choose a reason for hiding this comment

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

You can use the hook useIsValidNonce instead (don't rememeber the exact name).

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we have useValidateNonce but it returns a boolean. Not sure why we have this fallback here since safe.nonce can't be undefined but is -1 by default. Since we only use the value for validation I suggest we remove this fallback and use safe.nonce directly.

@usame-algan usame-algan requested a review from schmanu June 19, 2023 08:01
const readonly = !isEditable

const queuedTxs = useMemo(() => {
if (!page || page.results.length === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove page.results.length === 0 here as that is an empty array which also return in this case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! I also wrote some unit tests to validate this.

setNonce(newNonce)
const handleChange = useCallback(
(e: SyntheticEvent, value: string | AutocompleteValue<unknown, false, false, false>) => {
const nonce = Number(value)
Copy link
Member

Choose a reason for hiding this comment

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

To me personally it always feels a bit weird if an Input puts in "0" when I clear it.
But Number("") is 0. It still works fine but feels weird if my nonce is "9" and I want to put in "10" for instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I think having the cursor on the right of the 0 is also confusing even if the 0 is replaced once I start typing another number. Previously it was possible to have the input empty. I will look into restoring that behaviour

Copy link
Member Author

Choose a reason for hiding this comment

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

I looked into this and it seems we are storing the nonce as a number now and use undefined as the loading state so the current context doesn't give us the option to set the nonce to something other than a number. The input field is controlled by the context value so we would have to adjust the context i.e. store the nonce as a string but I am not sure if we want this. Wdyt @katspaugh

Copy link
Member

@katspaugh katspaugh Jun 19, 2023

Choose a reason for hiding this comment

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

The input can operate on strings and the context can operate on numbers.
You can probably do something like:

<Input
  value={String(nonce || '')}
  onChange={(e) => {
    setNonce(e.target.valueAsNumber)
  }}
/>

Copy link
Member Author

@usame-algan usame-algan Jun 19, 2023

Choose a reason for hiding this comment

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

Problem is that nonce will always be defined so String(nonce || '') would never result in an empty string. We can either change how we store nonce in the Context or make a copy of it for the nonce form and operate on that. The latter option was how we had it before where we copied the nonce value into RHF but it adds more complexity to the form since we have to keep it up to date depending on the queue.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added an additional isEmpty flag in the form now to achieve this.

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.

It's working well now for me :)

@katspaugh katspaugh merged commit ae65632 into epic-tx-flow Jun 20, 2023
@katspaugh katspaugh deleted the nonce-form branch June 20, 2023 14:39
@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 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.

3 participants