refactor: centralize constants and eliminate magic strings#4
Open
shivv23 wants to merge 9 commits into
Open
Conversation
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.
Centralizes all magic strings, hardcoded values, and repeated literals into a single
src/constants.tsmodule, eliminating ~110+ scattered occurrences across 10 files.Motivation
The codebase contained dozens of repeated hardcoded strings — IPFS gateway URLs, activity type literals, metric keys, storage key names, connection status strings, route paths, email configuration, and magic numbers. These were scattered across components with no single source of truth, making renaming, configuration changes, and internationalization fragile and error-prone.
Changes
New file:
src/constants.ts— single source of truth for all application constants:IPFS_GATEWAY_URL,PROVIDER_NAMESTORAGE_KEY_BACKUP_HISTORY,STORAGE_KEY_ACTIVITY_LOGS,STORAGE_KEY_METRICSActivityType(typed const enum)MetricKey(typed const enum) +DEFAULT_METRICSDEFAULT_FILE_NAME,RESTORED_INVOICE_DEFAULTROUTES.HOME,ROUTES.MESHKIT,ROUTES.ROOTConnectionStatus(typed const enum)ViewMode(typed const enum)TOAST_DURATION_LONG,TOAST_DURATION_SHORT,TOAST_POSITIONMAX_ACTIVITY_LOGS,MAX_FILENAME_LENGTH,CID_DISPLAY_LENGTH,MAX_ACTIVITY_DISPLAYEMAIL_RECIPIENT,EMAIL_BODY_DEFAULT,EMAIL_ATTACHMENT_NAMEREPORT_FILENAME,REPORT_HEADERRefactored files:
LocalStorage.ts— storage keys, activity type union, metric defaults, activity limit all use constantsMeshkitService.ts— provider name usesPROVIDER_NAMEDashboard.tsx— gateway URL, activity types, metric keys, file sentinels, connection status, report config, toast config, route paths, CID display length, activity display limitMenu.tsx— email configuration, file sentinels, filename length limit, toast duration/positionNewFile.tsx— default file name sentinelHome.tsx— view mode enum, default file nameMeshKit.tsx— connection status, metric keys, gateway URL, CID display length, toast config, route pathsBackupSuccessModal.tsx— gateway URLApp.tsx— route pathsType safety:
All string union types (
ActivityType,MetricKey,ConnectionStatus,ViewMode) are defined asas constobjects with companion type exports, providing both runtime values and compile-time type checking.Type infrastructure:
src/types/meshkit-ionic.d.tstype declaration stub for@meshkit/ionicBefore / After
Verification
npx tsc --noEmitpasses with zero errors.