fix(frontend): stabilize transactionId to fix progress UI and prevent double submission#1260
Merged
ogazboiz merged 1 commit intoJun 27, 2026
Conversation
… UI loss and double submission Closes LabsCrypt#1105 Date.now() was called on every render inside useDepositOperation, useWithdrawalOperation, and useRepaymentOperation, minting a new transactionId each time. Because useTransaction subscribes to the Zustand store, every store write (start/sign/submit/confirm) triggered a re-render which produced a new id. The executeDeposit/executeWithdrawal closure kept writing to the original id while the component read from the new one — so transaction was undefined, OperationProgress showed nothing, and isLoading stayed false, allowing duplicate submissions. Fix: replace Date.now() with React's useId() so the id is stable across all renders for the lifetime of the hook instance. Also extend isLoading in useTransaction to cover the submitted and confirming states so the Deposit/Withdraw buttons remain disabled for the entire in-flight window, not just pending/signing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
In
useDepositOperation,useWithdrawalOperation, anduseRepaymentOperation, the transaction ID was computed withDate.now()on every render:Because
useTransactionsubscribes to the Zustand store, every state write insideexecuteDeposit(start → sign → submit → confirm) triggered a re-render, which minted a new ID. The in-flight closure kept writing to the original ID, but the component was reading from the new one — sotransactionwas alwaysundefined. Consequences:OperationProgresshit itsif (!transaction) return nullguard and showed nothing during signing/submitting/confirmingdepositOp.isLoading/withdrawalOp.isLoadingstayedfalse, so the Deposit/Withdraw buttons were never disabled mid-flight, allowing duplicate submissions with a second clickFix
useRepaymentOperation.ts— replacedDate.now()with React'suseId()in all three hooks (useRepaymentOperation,useDepositOperation,useWithdrawalOperation).useId()returns a stable value across all renders for the lifetime of the hook instance.useOptimisticUI.ts— extendedisLoadinginuseTransactionto coversubmittedandconfirmingstates in addition topendingandsigning, so buttons stay disabled for the entire in-flight window until the operation settles.Files changed
frontend/src/app/hooks/useRepaymentOperation.tsfrontend/src/app/hooks/useOptimisticUI.ts