refactor: extract duplicated helpers into shared modules - #3
Merged
Conversation
- client rpc<T>() fetch wrapper (12 copies) -> src/lib/client-rpc.ts - server json() Response helper (12 copies) + readFormData() (6 try/catch blocks) -> src/lib/api-utils.ts - toHexField() (3 copies) -> src/lib/token-utils.ts, next to its inverse hexToText() - ModalOverlay component (3 identical overlay shells) -> src/components/ui/ModalOverlay.tsx - consumeChallengeFromRequest() (verbatim in both passkey verify routes) -> src/lib/passkey.ts; all 4 passkey routes now use the shared json() No behavior changes. Tests updated to mock the new passkey export. 502/502 tests pass; tsc clean. Net -294 lines.
anyxem
approved these changes
Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DRY refactor of duplication identified across components and API routes. No behavior changes intended — every extracted helper is byte-identical (or a strict superset, via default params / optional headers) to the copies it replaces.
Extractions
src/lib/client-rpc.ts—rpc<T>()browser-side RPC wrappersrc/lib/api-utils.ts—json()+readFormData()json()helpers; 6request.formData()try/catch blockssrc/lib/token-utils.ts—toHexField()hexToText()src/components/ui/ModalOverlay.tsxIssueTokenModal,IssueNFTModal,TokenManagePanelviamaxWidth/maxHeightprops)src/lib/passkey.ts—consumeChallengeFromRequest()All 4 passkey routes now use the shared
json()helper (extended with an optionalheadersparam, backward compatible).Deliberately left alone
SyncStatus.tsxraw fetch — tolerates partial RPC failure; the throwing helper would change behaviorrpc.tsjsonError— different response envelope (error: {message, code})IssueTokenButton/IssueNFTButton,ModeToggle— only 2 occurrences; premature abstractionTest plan
consumeChallengeFromRequestexport)tsc --noEmitclean