Skip to content

fix: Avoid nonce flicker when transaction is submitted #30193

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

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,8 @@ describe('ConfirmFooter', () => {
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.mockImplementation(() => ({} as any));
const updateCustomNonceSpy = jest
.spyOn(Actions, 'updateCustomNonce')
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.mockImplementation(() => ({} as any));
const setNextNonceSpy = jest
.spyOn(Actions, 'setNextNonce')
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.mockImplementation(() => ({} as any));
fireEvent.click(cancelButton);
expect(rejectSpy).toHaveBeenCalled();
expect(updateCustomNonceSpy).toHaveBeenCalledWith('');
expect(setNextNonceSpy).toHaveBeenCalledWith('');
});

it('invoke required actions when submit button is clicked', () => {
Expand All @@ -149,20 +137,8 @@ describe('ConfirmFooter', () => {
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.mockImplementation(() => ({} as any));
const updateCustomNonceSpy = jest
.spyOn(Actions, 'updateCustomNonce')
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.mockImplementation(() => ({} as any));
const setNextNonceSpy = jest
.spyOn(Actions, 'setNextNonce')
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.mockImplementation(() => ({} as any));
fireEvent.click(submitButton);
expect(resolveSpy).toHaveBeenCalled();
expect(updateCustomNonceSpy).toHaveBeenCalledWith('');
expect(setNextNonceSpy).toHaveBeenCalledWith('');
});

it('displays a danger "Confirm" button there are danger alerts', async () => {
Expand Down
6 changes: 0 additions & 6 deletions ui/pages/confirmations/components/confirm/footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import useAlerts from '../../../../../hooks/useAlerts';
import {
rejectPendingApproval,
resolvePendingApproval,
setNextNonce,
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
updateAndApproveTx,
///: END:ONLY_INCLUDE_IF
updateCustomNonce,
} from '../../../../../store/actions';
import { isSignatureTransactionType } from '../../../utils';
import { useConfirmContext } from '../../../context/confirm';
Expand Down Expand Up @@ -186,8 +184,6 @@ const Footer = () => {
dispatch(
rejectPendingApproval(currentConfirmation.id, serializeError(error)),
);
dispatch(updateCustomNonce(''));
dispatch(setNextNonce(''));
},
[currentConfirmation],
);
Expand Down Expand Up @@ -219,8 +215,6 @@ const Footer = () => {
} else {
dispatch(resolvePendingApproval(currentConfirmation.id, undefined));
}
dispatch(updateCustomNonce(''));
dispatch(setNextNonce(''));
Copy link
Contributor

Choose a reason for hiding this comment

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

These calls were added here as it at times resulted in confirmation using old nonce when switching networks. Can you plz check if removing this does not re-introduce that bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After discussing this with @jpuri, she informed me that there used to be a bug in the legacy confirmations that:

  • if you created confirmation on a network
  • edit the nonce
  • and then switch to another network
  • the confirmation page now would show old nonce.

Thus we added this code to clear the old nonce value after confirmation was submitted.

I tested this scenario a few times and it seems to not be an issue in the new confirmations even when removing this code. I will ask our QA engineer to double check this for us.

}, [currentConfirmation, customNonceValue]);

const onFooterCancel = useCallback(() => {
Expand Down
Loading