Skip to content

[LWDM] refactor(wallet-api): split monolithic react.ts and logic.ts into granular modules#15563

Closed
Justkant wants to merge 3 commits intodevelopfrom
refactor/wallet-api
Closed

[LWDM] refactor(wallet-api): split monolithic react.ts and logic.ts into granular modules#15563
Justkant wants to merge 3 commits intodevelopfrom
refactor/wallet-api

Conversation

@Justkant
Copy link
Copy Markdown
Contributor

✅ Checklist

  • npx changeset was attached. I'll add one when opening for review
  • Covered by automatic tests.
  • Impact of the changes:
    • wallet-api, discover, buy/sell, earn, swap, recover, wallet-connect

📝 Description

Replace the monolithic react.ts (~1600 lines) and logic.ts (~530 lines) with a react/ and logic/ folder structure, each containing one file per handler or hook. Split logic.test.ts into isolated per-module test files under logic/__tests__/.

logic/ split:

  • 9 modules: context, receiveOnAccount, signTransaction, signRawTransaction, broadcastTransaction, signMessage, bitcoin, exchange, storage
  • 9 test files + shared testHelpers.ts
  • No barrel file — all imports point to concrete paths

react/ split:

  • 13 handler factory files in react/handlers/ (currencyList, accountList, accountRequest, accountReceive, messageSign, storage, bitcoinSignPsbt, transactionSign, transactionSignRaw, transactionSignAndBroadcast, device, bitcoin, exchange)
  • 10 per-hook files (useWalletAPIServer, useConfig, usePermission, useCategories, useRecentlyUsed, useLocalLiveApp, useCacheBustedLiveApps, useDisclaimerRaw, useDAppManifestCurrencyIds, useSetWalletAPIAccounts)
  • Shared types.ts and safeGetRefValue.ts
  • No barrel file — all 37 consumer files updated to direct imports

Ref-based handler registration:

  • Single handlerDepsRef holds all volatile data (walletState, manifest, accounts, tracking, config, UI callbacks, device transport)
  • All 22 handlers registered once in a single useEffect([server]) via factory functions that read deps at call time through getDeps()
  • Eliminates ~20 useEffect blocks, prevents stale closures, and makes onLoad/onReload/onLoadError callbacks fully stable (empty deps)

❓ Context

  • JIRA or GitHub link:
  • ADR link (if any):

🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.
  • Performance considerations have been taken into account. (changes have been profiled or benchmarked if necessary)

@Justkant Justkant self-assigned this Mar 19, 2026
@live-github-bot live-github-bot Bot added desktop Has changes in LLD mobile Has changes in LLM common Has changes in live-common labels Mar 19, 2026
@live-github-bot live-github-bot Bot changed the title refactor(wallet-api): split monolithic react.ts and logic.ts into granular modules [LWDM] refactor(wallet-api): split monolithic react.ts and logic.ts into granular modules Mar 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 19, 2026

Web Tools Build Status

Build Status Deployment
Web Tools Build ✅ Deployed https://web-tools-jfzb245dz-ledger-hq-prd.vercel.app
Native Storybook Build ⏭️ Skipped
React Storybook Build ⏭️ Skipped

…nular modules

Replace the monolithic `react.ts` (~1600 lines) and `logic.ts` (~530 lines) with
a `react/` and `logic/` folder structure, each containing one file per handler or
hook. Split `logic.test.ts` into isolated per-module test files under `logic/__tests__/`.

**logic/ split:**
- 9 modules: context, receiveOnAccount, signTransaction, signRawTransaction,
  broadcastTransaction, signMessage, bitcoin, exchange, storage
- 9 test files + shared testHelpers.ts
- No barrel file — all imports point to concrete paths

**react/ split:**
- 13 handler factory files in `react/handlers/` (currencyList, accountList,
  accountRequest, accountReceive, messageSign, storage, bitcoinSignPsbt,
  transactionSign, transactionSignRaw, transactionSignAndBroadcast, device,
  bitcoin, exchange)
- 10 per-hook files (useWalletAPIServer, useConfig, usePermission, useCategories,
  useRecentlyUsed, useLocalLiveApp, useCacheBustedLiveApps, useDisclaimerRaw,
  useDAppManifestCurrencyIds, useSetWalletAPIAccounts)
- Shared types.ts and safeGetRefValue.ts
- No barrel file — all 37 consumer files updated to direct imports

**Ref-based handler registration:**
- Single `handlerDepsRef` holds all volatile data (walletState, manifest,
  accounts, tracking, config, UI callbacks, device transport)
- All 22 handlers registered once in a single `useEffect([server])` via
  factory functions that read deps at call time through `getDeps()`
- Eliminates ~20 useEffect blocks, prevents stale closures, and makes
  onLoad/onReload/onLoadError callbacks fully stable (empty deps)
@Justkant Justkant force-pushed the refactor/wallet-api branch from 83a0a5e to 75b5d36 Compare March 19, 2026 13:57
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
37.2% Coverage on New Code (required ≥ 80%)
33 New Code Smells (required ≤ 1)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 4, 2026

There as been no activity on this PR for the last 14 days. Please consider closing this PR.

@github-actions github-actions Bot added the Stale label Apr 4, 2026
@github-actions github-actions Bot closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Has changes in live-common desktop Has changes in LLD mobile Has changes in LLM Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant