Skip to content

Conversation

@smk762
Copy link
Collaborator

@smk762 smk762 commented Oct 30, 2025

closes #3302

  • Avoids activation task duplication from balance request event triggers via coin selection dropdowns.
  • Awaits initial activations to avoid early login double ups.
  • Early exit on pending activation tasks where coin already has activation task in progress.

What changed (high level)

  • Introduced per-asset in-flight activation deduplication so only one activation runs per asset:

    • lib/bloc/coins_bloc/coins_repo.dart: _activationsInFlight map and join-existing behavior inside activateAssetsSync(...).
  • Avoid over-eager activation retries that could spawn new backend tasks:

    • Single activation attempt; on idempotent storage errors (e.g., IndexedDB ConstraintError), wait for availability instead of starting a new task.
  • Added an initial-activation gate and wired it through the app to prevent early auto-activations from UI flows:

    • CoinsRepo: markInitialActivationStart(), markInitialActivationComplete(), waitForInitialActivationToComplete(timeout: 30s)
    • CoinsBloc: marks start/end of initial activation to drive the gate.
    • Applied the gate to Swap/Maker/Bridge/Fiat entry points:
      • lib/views/dex/dex_helpers.dart (Swap helper): waits for gate before activating.
      • lib/bloc/market_maker_bot/market_maker_trade_form/market_maker_trade_form_bloc.dart: waits for gate in _autoActivateCoin.
      • lib/bloc/bridge_form/bridge_bloc.dart: awaits _autoActivateCoin in _onSetSellCoin.
      • lib/bloc/fiat/fiat_onramp_form/fiat_form_bloc.dart: waits for gate before activateAssetsSync.
  • Prevent pre-activation balance calls from spawning backend tasks:

    • CoinsRepo.tryGetBalanceInfo(...) returns zero if asset is not active (no SDK balance RPC).
    • Market Maker form calls SDK getBalance only when the coin is active; otherwise uses zero.

Files touched (key lines)

  • lib/bloc/coins_bloc/coins_repo.dart: in-flight dedup, initial activation gate, idempotent error handling, guarded tryGetBalanceInfo.
  • lib/bloc/coins_bloc/coins_bloc.dart: calls markInitialActivationStart/Complete.
  • lib/views/dex/dex_helpers.dart: gate wait before activation (30s timeout).
  • lib/bloc/market_maker_bot/market_maker_trade_form/market_maker_trade_form_bloc.dart: gate wait and guarded balance reads.
  • lib/bloc/bridge_form/bridge_bloc.dart: await _autoActivateCoin on sell coin set.
  • lib/bloc/fiat/fiat_onramp_form/fiat_form_bloc.dart: gate wait before activation.

Why this matters

These changes eliminate most duplicate activation attempts and the cascading IndexedDB uniqueness errors that were caused by competing tasks when entering Swap before initial activation completed (see issue #3302). Remaining rare duplication observed for BTC-segwit is traced to SDK behavior and will be addressed there.

Reference: Premature Swap page entry prompts competing activations #3302


QA: Quick test plan

Prereqs:

  • Use a mature wallet with KMD or BTC-segwit history.
  • Enable SDK/app debug logs to capture TASK events.
  1. Initial login + immediate Swap navigation
  • Steps:
    • Login via import to a mature wallet.
    • Immediately navigate to Swap before coins appear active.
  • Expect:
    • At most one activation task per asset; no cascade of TASK IDs for the same coin.
    • No IndexedDB ConstraintError logs.
    • “CoinIsAlreadyActivated” may appear once if a second request joins post-activation, but no retries or cascades.
  1. Maker form selection without prior activation
  • Steps:
    • Open Market Maker form.
    • Choose a sell coin that is not yet active.
    • Observe logs during selection.
  • Expect:
    • Form waits behind the initial activation gate (up to 30s).
    • No pre-activation RequestingWalletBalance tasks initiated by the form; balance should be treated as 0 until active.
  1. Bridge sell coin change
  • Steps:
    • Open Bridge form and set a sell coin not yet active.
    • Observe logs.
  • Expect:
    • _onSetSellCoin awaits _autoActivateCoin; activation finishes then fees/volumes are fetched.
    • No duplicate activation tasks for the sell coin.
  1. Fiat coin selection
  • Steps:
    • On Fiat page, change selected coin to one not yet active.
    • Observe logs.
  • Expect:
    • Gate wait occurs; a single activation task, then pubkeys fetch.
    • No early wallet-balance tasks before activation.
  1. Regression: Already-active coins
  • Steps:
    • With coins already active, open Swap, Maker, Bridge, and Fiat forms.
    • Change coins among already-active ones.
  • Expect:
    • No activation tasks; only normal balance/pubkeys/fees operations.
  1. Stress: Repeated toggling during initial activation
  • Steps:
    • During the first 10–20 seconds after login, rapidly switch sell/buy coins in Swap and Maker.
  • Expect:
    • Gate prevents new activations until initial activation completes; no task cascades; no IndexedDB uniqueness errors.
  1. Log inspection checklist
  • No “Error uploading an item: ConstraintError ... wallet_account_id ... uniqueness requirements” during tests.
  • No repeated “ActivatingCoin” for the same coin within seconds from the app layer.
  • If a single “CoinIsAlreadyActivated” for BTC-segwit appears, it should be isolated and not cascade; SDK team will address root cause.

Notes for reviewers

  • Some cases of task duplication may persist (from SDK layer), but should be reduced from previous.

@smk762 smk762 self-assigned this Oct 30, 2025
@smk762 smk762 added P1 Major issue needs to be fixed UX Cosmetic or flow efficiency enhancements for improved User Experience performance Where data sourcing or rendering speed needs improvement labels Oct 30, 2025
@smk762 smk762 linked an issue Oct 30, 2025 that may be closed by this pull request
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 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.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch deduplicate-activation-tasks

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.

@github-actions
Copy link

github-actions bot commented Oct 30, 2025

Visit the preview URL for this PR (updated for commit 6cd343a):

https://walletrc--pull-3304-merge-0g310oev.web.app

(expires Wed, 12 Nov 2025 05:20:43 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: f66a4ff03faa546f12f0ae5a841bd9eff2714dcc

@CharlVS CharlVS added this to the v0.9.3 Release milestone Nov 2, 2025
CharlVS added a commit that referenced this pull request Nov 2, 2025
@smk762 smk762 modified the milestones: v0.9.3 Release, v0.9.4 Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 Major issue needs to be fixed performance Where data sourcing or rendering speed needs improvement UX Cosmetic or flow efficiency enhancements for improved User Experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Premature Swap page entry prompts competing activations

3 participants