Skip to content

refactor(wallet-toolbox): address S7059 async constructors in Monitor/SimpleWallet/CWIStyle#106

Open
sirdeggen wants to merge 2 commits intomainfrom
sonar/w6-s7059-wallet
Open

refactor(wallet-toolbox): address S7059 async constructors in Monitor/SimpleWallet/CWIStyle#106
sirdeggen wants to merge 2 commits intomainfrom
sonar/w6-s7059-wallet

Conversation

@sirdeggen
Copy link
Copy Markdown
Contributor

Summary

  • Fixes Sonar S7059 (async work in constructors) across three classes in @bsv/wallet-toolbox
  • Monitor: moves subscribeReorgs/subscribeHeaders calls from the constructor into a ready: Promise<void> using an async IIFE; subscriptions awaited concurrently via Promise.all
  • SimpleWalletManager: constructor previously silently dropped the loadSnapshot promise; now assigned to ready
  • CWIStyleWalletManager: constructor called loadSnapshot(...).catch(...) inline; refactored to ready so callers can track completion
  • Updates the one test that accessed currentUMPToken without awaiting the snapshot load to await manager.ready first

Refs #38 #45

Test plan

  • pnpm --filter @bsv/wallet-toolbox run build — clean
  • pnpm --filter @bsv/wallet-toolbox exec jest --runInBand 'CWIStyleWalletManager' — 38 passed
  • pnpm --filter @bsv/wallet-toolbox exec jest --runInBand 'test/monitor/Monitor' — 14 passed
  • No new lint errors introduced in the three modified source files

🤖 Generated with Claude Code

…/SimpleWallet/CWIStyle

Resolve Sonar S7059 (async work in constructors) for Monitor, SimpleWalletManager,
and CWIStyleWalletManager by adopting the .ready: Promise<void> pattern. Each class
now exposes a public `ready` property that resolves once async initialization (chain
subscriptions or snapshot loading) completes, keeping the constructor itself
synchronous. Monitor uses Promise.all for concurrent subscription awaiting.
Update CWIStyleWalletManager test to await ready before inspecting loaded state. Refs #38 #45.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sonar still flagged \`this.ready = this.loadSnapshot(...)\` because
the assignment invokes an async method from the constructor body.
Switch to lazy memoized getter: constructor stores init args, ready
getter triggers init on first access. Public API unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 8, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

1 participant