Skip to content

refactor(withdraw): use SDK executeWithdrawal() to avoid duplicate transaction signing#3325

Merged
smk762 merged 6 commits into
devfrom
fix/avoid-multi-signing-withdraws
Nov 23, 2025
Merged

refactor(withdraw): use SDK executeWithdrawal() to avoid duplicate transaction signing#3325
smk762 merged 6 commits into
devfrom
fix/avoid-multi-signing-withdraws

Conversation

@CharlVS
Copy link
Copy Markdown
Collaborator

@CharlVS CharlVS commented Oct 31, 2025

Overview

Updated the main application to use the new SDK executeWithdrawal() method, replacing the manual workaround that was calling sendRawTransaction() directly.

Problem

The app was implementing a workaround to avoid double signing by manually calling sendRawTransaction() with the preview's txHex. This bypassed the SDK abstraction and duplicated logic.

Solution

Updated WithdrawFormBloc to use the new SDK executeWithdrawal() method which:

  • Provides proper SDK abstraction
  • Includes consistent progress tracking
  • Maintains the same behavior (no double signing)
  • Removes the need for direct RPC calls from the BLoC

Changes Made

WithdrawFormBloc

  • Replaced manual sendRawTransaction() call with SDK executeWithdrawal()
  • Removed unused mm2Api dependency and import
  • Simplified code by using proper SDK abstraction
  • Maintains existing behavior while following SDK best practices

Before

final response = await _mm2Api.sendRawTransaction(
  SendRawTransactionRequest(
    coin: preview.coin,
    txHex: preview.txHex,
  ),
);

After

await for (final progress in _sdk.withdrawals.executeWithdrawal(
  preview,
  state.asset.id.id,
)) {
  if (progress.status == WithdrawalStatus.complete) {
    result = progress.withdrawalResult;
    break;
  }
}

Benefits

  1. Cleaner Code: Uses proper SDK abstraction instead of manual RPC calls
  2. Better Progress Tracking: Leverages SDK's built-in progress reporting
  3. Consistency: Follows SDK patterns across the application
  4. Maintainability: Reduces direct coupling to RPC layer

Dependencies

Testing

  • ✅ No linter errors
  • ✅ Existing behavior maintained (transaction only signed once)
  • ✅ Withdrawal preview-then-execute flow works as expected

Files Modified

  • lib/bloc/withdraw_form/withdraw_form_bloc.dart
  • sdk (submodule pointer update)

Note

Replace manual sendRawTransaction flow with _sdk.withdrawals.executeWithdrawal() and update SDK submodule.

  • Withdraw Flow:
    • Replace direct _mm2Api.sendRawTransaction(...) with streaming _sdk.withdrawals.executeWithdrawal(preview, state.asset.id.id); handle complete/error statuses and null-result fallback.
    • Remove unused _mm2Api field and send_raw_transaction_request import; keep constructor param but no longer used.
    • Preserve no re-signing behavior by broadcasting the pre-signed preview transaction.
  • State Handling:
    • Update success path to set WithdrawFormStep.success, clear preview, and surface errors via transactionError when execution fails or yields no result.
  • Dependencies:
    • Update sdk submodule to 6576c4c.

Written by Cursor Bugbot for commit b67732d. This will update automatically on new commits. Configure here.

…ansaction signing

- Replace manual sendRawTransaction() call with SDK executeWithdrawal()
- Remove unused mm2Api dependency and import
- Simplifies code by using proper SDK abstraction
- Maintains existing behavior while following SDK best practices
- Ensures transaction is only signed once during preview phase
Updates SDK to commit 6576c4c which includes:
- New executeWithdrawal() method for preview-then-execute workflow
- Deprecation of direct withdraw() method
- Prevention of duplicate transaction signing
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 31, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/avoid-multi-signing-withdraws

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.

@CharlVS CharlVS requested review from Copilot and smk762 October 31, 2025 14:39
@CharlVS CharlVS self-assigned this Oct 31, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This refactor updates the withdrawal execution flow to use the SDK's executeWithdrawal() method instead of manually calling sendRawTransaction(), improving code maintainability and following proper SDK abstraction patterns.

Key changes:

  • Replaced direct RPC call with SDK's withdrawal execution method
  • Removed unused mm2Api dependency from WithdrawFormBloc
  • Updated SDK submodule to version 6576c4c which includes the new executeWithdrawal() method

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
sdk Updated submodule pointer to commit 6576c4c containing the new SDK withdrawal execution method
lib/bloc/withdraw_form/withdraw_form_bloc.dart Refactored withdrawal execution to use SDK method, removed mm2Api dependency and related imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/bloc/withdraw_form/withdraw_form_bloc.dart Outdated
Comment thread lib/bloc/withdraw_form/withdraw_form_bloc.dart Outdated
Copy link
Copy Markdown
Collaborator

@smk762 smk762 left a comment

Choose a reason for hiding this comment

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

Confirm single sig only on trezor and zhtlc withdraws, thanks for the update!

CharlVS and others added 2 commits November 2, 2025 14:23
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@CharlVS CharlVS modified the milestones: v0.9.3 Release, v0.9.4 Nov 2, 2025
@smk762 smk762 merged commit d771a4e into dev Nov 23, 2025
2 of 12 checks passed
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.

3 participants