Skip to content

chore(bitcoin): type the Bitcoin handler and use-case leaks - #639

Open
ulissesferreira wants to merge 1 commit into
mainfrom
chore/bitcoin-lint-suppressions-handlers-use-cases-utils
Open

ulissesferreira wants to merge 1 commit into
mainfrom
chore/bitcoin-lint-suppressions-handlers-use-cases-utils

Conversation

@ulissesferreira

Copy link
Copy Markdown
Contributor

Description

Burns down 19 of the Bitcoin Snap's oxlint suppressions across the handler and use-case surface — the smallest of the parallel cleanup units. Everything is type-level or doc-level: the no-throw-literal throws in the tests became named non-Error constants (the tests deliberately throw non-Error values, so the values themselves are unchanged), the in check now uses hasProperty() from @metamask/utils (own-property check, same narrowing), new Array(length) got its element type, the untyped Object.fromEntries helper got an explicit generic implementation with identical output, and the as any test mocks were replaced with the real entity types.

No behaviour changes. The only production logic touched is reverseMapping in caip.ts, which still produces the same own-key mapping in the same insertion order — it now builds a Record<To, From> directly instead of returning the any from Object.fromEntries.

Changes

  • packages/bitcoin-wallet-snap/src/handlers/HandlerMiddleware.ts — narrow StructError.data (any via the library's index signature) to the Record<string, Json> | undefined the error wrapper accepts (no-unsafe-argument)
  • packages/bitcoin-wallet-snap/src/handlers/RpcHandler.ts — element type on the batch results buffer: new Array<T>(items.length) (no-unsafe-assignment)
  • packages/bitcoin-wallet-snap/src/handlers/UserInputHandler.ts — 'value' in event → hasProperty(event, 'value') (internal-snaps/no-in-operator)
  • packages/bitcoin-wallet-snap/src/handlers/caip.ts — reverseMapping returns a typed Record<To, From> instead of Object.fromEntries's any (no-unsafe-return)
  • packages/bitcoin-wallet-snap/src/handlers/mappings.ts — drop the redundant as KeyringAccount['type'] (no-unnecessary-type-assertion)
  • packages/bitcoin-wallet-snap/src/use-cases/AccountUseCases.ts — element type on the batch results buffer (no-unsafe-assignment)
  • packages/bitcoin-wallet-snap/src/use-cases/AccountUseCases.test.ts — named non-Error throwables for the cause-handling tests, drop a redundant assertion on the SLIP-10 derivation path (no-throw-literal, no-unnecessary-type-assertion)
  • packages/bitcoin-wallet-snap/src/use-cases/SendFlowUseCases.test.ts — typed mock payloads (Balance, ScriptBuf, SpotPrice, signPsbt return type) and a return type on the toString stub (no-explicit-any, no-unsafe-argument, explicit-function-return-type)
  • packages/bitcoin-wallet-snap/src/utils/format-btc.test.ts — @vitest-environment as a line directive instead of an unknown JSDoc tag (jsdoc/check-tag-names)
  • oxlint-suppressions.json — regenerated with --prune-suppressions (19 entries removed across these 9 files, nothing hand-edited)

Quality gates

  • yarn lint:oxlint packages/bitcoin-wallet-snap — clean, 19 suppressions entries removed, no stale entries
  • tsc --noEmit — clean
  • vitest run — 28 files / 761 tests pass
  • oxfmt --check — clean

@sonarqubecloud

Copy link
Copy Markdown

This branch was previously deployed

1 inactive deployment
default-branch — 6e46b632 Deployed Nov 17, 2026 by ulissesferreira via Determine whether this PR is a release PR #2419
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant