Skip to content

Fix: Disable send transaction button while transaction is in progress#94

Open
Rav1Chauhan wants to merge 1 commit intoDjedAlliance:mainfrom
Rav1Chauhan:fix/disable-send-transaction-button
Open

Fix: Disable send transaction button while transaction is in progress#94
Rav1Chauhan wants to merge 1 commit intoDjedAlliance:mainfrom
Rav1Chauhan:fix/disable-send-transaction-button

Conversation

@Rav1Chauhan
Copy link
Copy Markdown

@Rav1Chauhan Rav1Chauhan commented Feb 25, 2026

Addressed Issues:

Fixes #61

Screenshots/Recordings:

Additional Notes:

Problem

The "Send Transaction" button was not disabled while the transaction was being sent to the blockchain.

This allowed users to:

Click the button multiple times

Trigger multiple transaction requests

Potentially pay twice

This is a critical UX and financial safety issue.

Solution

Introduced a new isSending state in TransactionReview.jsx:

Immediately disables the button when transaction starts

Prevents double invocation of handleBuySc

Re-enables only on failure

Keeps disabled after success

Updated logic:

disabled={isSending || txHash !== null}

This ensures safe transaction handling.

Result

Prevents duplicate payments

Prevents duplicate wallet popups

Improves UX safety

Matches expected behavior from Issue #61

Checklist

  • [x ] My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • [ x] My code follows the project's code style and conventions.
  • If applicable, I have made corresponding changes or additions to the documentation.
  • If applicable, I have made corresponding changes or additions to tests.
  • [ x] My changes generate no new warnings or errors.
  • [ x] I have joined the Stability Nexus's Discord server and I will share a link to this PR with the project maintainers there.
  • [x ] I have read the Contribution Guidelines.
  • [x ] Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.

⚠️ AI Notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented duplicate submissions by disabling the send flow during an ongoing transaction.
    • Reset submission state on network/token changes and on failures.
    • Simplified network verification and unified failure handling to avoid confusing wallet-specific messages.
  • User Experience

    • Streamlined error messages for clarity.
    • Simplified transaction flow and UI: clearer action buttons, concise status area, and an inline transaction hash display.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

Adds an isSending guard to prevent double submissions, consolidates transaction preparation and network verification through ensureCorrectNetwork, simplifies UI/messages and transaction-hash rendering, and adds early guards for missing account/txData.

Changes

Cohort / File(s) Summary
Transaction review logic & UI
stablepay-sdk/src/widget/TransactionReview.jsx
Adds isSending state to prevent double submits and disable send button; resets isSending on network/token changes and on failure; unifies txData preparation for native and token transfers; replaces MetaMask-specific chain checks with ensureCorrectNetwork; simplifies UI rendering and error messages; adds early guards for missing account/txData and changes transaction-hash display.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Zahnentferner

Poem

🐰
One hop, one click, no double spend,
I guard your coin till flows amend.
isSending keeps the chaos few,
A tiny hop that sees you through. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The pull request includes significant UI refactoring beyond the button disable requirement, such as removing explorer link rendering, reworking the network verification flow, and simplifying the overall component structure. Isolate changes to only the isSending state management and button disable logic. Move UI refactoring and message simplification into separate pull requests to maintain clear scope.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: disabling the send transaction button while a transaction is in progress, which directly addresses the primary objective.
Linked Issues check ✅ Passed The pull request implements all coding requirements from issue #61: adds isSending state to track transaction status, disables button immediately after clicking, re-enables only on failure, and prevents duplicate submissions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@stablepay-sdk/src/widget/TransactionReview.jsx`:
- Around line 220-234: The outer catch is treating any error from the
onTransactionComplete callback as a transaction failure; wrap the
onTransactionComplete invocation in its own try/catch so a thrown error from the
callback does not trigger setMessage("❌ Transaction failed.") or change
transaction state; call onTransactionComplete({ txHash, network:
selectedNetwork, token: selectedToken?.key, tokenSymbol: selectedToken?.symbol,
amount: contextTransactionDetails?.amount, receivingAddress:
contextTransactionDetails?.receivingAddress }) inside a dedicated try block and
in the callback catch only capture/log the callback error (e.g., via setError or
console.error) without flipping success messaging or setIsSending for the main
transaction flow.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 509e7d3 and e1cc5e9.

📒 Files selected for processing (1)
  • stablepay-sdk/src/widget/TransactionReview.jsx

@Rav1Chauhan Rav1Chauhan force-pushed the fix/disable-send-transaction-button branch from e1cc5e9 to 900189a Compare March 3, 2026 17:54
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
stablepay-sdk/src/widget/TransactionReview.jsx (1)

145-151: ⚠️ Potential issue | 🟡 Minor

Use a bigint fallback for amountToSend in the ERC-20 transfer path.

The amountToSend must be consistently typed as bigint. When truthy, parseUnits() returns bigint, but the fallback "0" is a string. Since encodeFunctionData() passes this to a uint256 parameter, abitype strictly expects bigint (not string), which can cause type errors during ABI encoding. Change the fallback to 0n.

Suggested fix
        const amountToSend = contextTransactionDetails.amount
          ? parseUnits(
              String(contextTransactionDetails.amount),
              contextTransactionDetails.stableCoinDecimals
            )
-          : "0";
+          : 0n;

Also applies to: line 77 (similar pattern with tradeDataBuySc || "0").

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@stablepay-sdk/src/widget/TransactionReview.jsx` around lines 145 - 151, The
fallback value for amountToSend must be a bigint, not a string; change the
ternary in TransactionReview.jsx so the false branch returns 0n instead of "0"
to ensure amountToSend is always a bigint (this affects the ERC-20 transfer path
where parseUnits returns bigint and encodeFunctionData expects uint256); apply
the same change for the similar variable tradeDataBuySc (replace "0" with 0n)
and ensure any downstream usage (e.g., encodeFunctionData calls) receives the
bigint-typed value.
♻️ Duplicate comments (1)
stablepay-sdk/src/widget/TransactionReview.jsx (1)

220-234: ⚠️ Potential issue | 🟠 Major

Isolate onTransactionComplete failures from transaction status.

If the completion callback throws synchronously, the outer catch currently flips UI to “Transaction failed” even after txHash is set. Handle callback errors in a dedicated try/catch.

Suggested fix
       if (onTransactionComplete) {
-        onTransactionComplete({
-          txHash,
-          network: selectedNetwork,
-          token: selectedToken?.key,
-          tokenSymbol: selectedToken?.symbol,
-          amount: contextTransactionDetails?.amount,
-          receivingAddress:
-            contextTransactionDetails?.receivingAddress,
-        });
+        try {
+          await onTransactionComplete({
+            txHash,
+            network: selectedNetwork,
+            token: selectedToken?.key,
+            tokenSymbol: selectedToken?.symbol,
+            amount: contextTransactionDetails?.amount,
+            receivingAddress:
+              contextTransactionDetails?.receivingAddress,
+          });
+        } catch (callbackError) {
+          console.error("onTransactionComplete callback failed:", callbackError);
+        }
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@stablepay-sdk/src/widget/TransactionReview.jsx` around lines 220 - 234, The
onTransactionComplete callback invocation inside the try block can throw and is
currently caught by the outer catch which incorrectly sets the UI to
"Transaction failed"; wrap the onTransactionComplete({...}) call in its own
try/catch so that errors from onTransactionComplete are handled separately
(e.g., catch and setError or console.error) without changing transaction status
or calling setMessage("❌ Transaction failed.")/setIsSending(false) that belong
to real transaction failures; locate the invocation of onTransactionComplete,
txHash, selectedNetwork, selectedToken, contextTransactionDetails and adjust
control flow so the outer catch only handles the actual send/transaction errors
while the inner catch isolates callback errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@stablepay-sdk/src/widget/TransactionReview.jsx`:
- Around line 145-151: The fallback value for amountToSend must be a bigint, not
a string; change the ternary in TransactionReview.jsx so the false branch
returns 0n instead of "0" to ensure amountToSend is always a bigint (this
affects the ERC-20 transfer path where parseUnits returns bigint and
encodeFunctionData expects uint256); apply the same change for the similar
variable tradeDataBuySc (replace "0" with 0n) and ensure any downstream usage
(e.g., encodeFunctionData calls) receives the bigint-typed value.

---

Duplicate comments:
In `@stablepay-sdk/src/widget/TransactionReview.jsx`:
- Around line 220-234: The onTransactionComplete callback invocation inside the
try block can throw and is currently caught by the outer catch which incorrectly
sets the UI to "Transaction failed"; wrap the onTransactionComplete({...}) call
in its own try/catch so that errors from onTransactionComplete are handled
separately (e.g., catch and setError or console.error) without changing
transaction status or calling setMessage("❌ Transaction
failed.")/setIsSending(false) that belong to real transaction failures; locate
the invocation of onTransactionComplete, txHash, selectedNetwork, selectedToken,
contextTransactionDetails and adjust control flow so the outer catch only
handles the actual send/transaction errors while the inner catch isolates
callback errors.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1cc5e9 and 900189a.

📒 Files selected for processing (1)
  • stablepay-sdk/src/widget/TransactionReview.jsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Send transaction button not disabled when sending transaction is in process

1 participant