use withdraw preview signed hex for broadcast#3309
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
|
Visit the preview URL for this PR (updated for commit 1403882): https://walletrc--pull-3309-merge-ftd7uwcn.web.app (expires Thu, 06 Nov 2025 12:38:24 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: f66a4ff03faa546f12f0ae5a841bd9eff2714dcc |
|
|
||
| WithdrawFormBloc({ | ||
| required Asset asset, | ||
| required KomodoDefiSdk sdk, |
There was a problem hiding this comment.
@smk762 Thank you for this PR. Btw, for the future, the SDK has 1:1 type-safe mapping for most RPCs, which is accessible through the SDK, so passing _mm2Api isn't necessary here. e.g. _sdk.rpc.withdraw.withdraw or _sdk.rpc.withdraw.sendRawTransaction.
But in general, we want to avoid having to use RPCs instead of the abstracted/managed SDK features so that devs don't need to learn and understand KDF's API. With the SDK's withdrawal feature now unused, it suggests it doesn't meet our needs, and therefore won't meet the needs of other developers.
Closes #3307 & #3196
To test:
Summary
Avoids calling the withdraw RPC twice by reusing the transaction preview (
tx_hex) for broadcast on confirmation. This eliminates a second device-sign prompt for hardware wallets (Trezor) and removes unnecessary duplicate transaction generation on slow chains (e.g., ZHTLC).Linked Issues
Problem
Current flow generates the transaction twice:
For hardware wallets, this results in two device confirmations for the same transaction. For chains with slower generation (ZHTLC), the duplicate work is visible and wasteful.
Approach
Perform a single withdraw (preview) to generate the transaction and cache it in local state. On confirm, broadcast the cached
tx_hexusingsend_raw_transactioninstead of calling withdraw again.Implementation Details
WithdrawalPreviewinWithdrawFormState.previewwhen the confirmation screen is shown.send_raw_transactionwithpreview.txHexandpreview.coin.WithdrawalResultusing the preview data and the broadcasttxHash.Files Touched (high level)
lib/bloc/withdraw_form/withdraw_form_bloc.dartMm2Apiinto the bloc.send_raw_transactionusing cachedpreview.txHex.lib/views/wallet/coin_details/withdraw_form/withdraw_form.dartMm2ApitoWithdrawFormBlocconstructor.User Impact
Testing Steps
tx_hex.Edge Cases
previewis unexpectedly null on Confirm, an error is surfaced and the transaction fails gracefully.send_raw_transactionreturns an error, the failure is shown on the failed screen with details.Risks and Mitigations
send_raw_transactionafter constructingtx_hex.Checklist
tx_hexfor broadcast on Confirm