Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .ralphy/progress.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

2026-01-21: Setup Test Environment (Prerequisite)
- Installed @testing-library/react, @testing-library/jest-dom, redux-saga-test-plan.
- Configured src/setupTests.js with TextEncoder polyfill and jest-dom.
- Configured package.json for Jest (axios transform).
- Created src/test-utils.js.
- Refactored circular dependencies in reducers/sagas/utils to enable store initialization in tests.
- Fixed existing tests (atomicSwap.test.js, ModalPin.test.js) to match environment and library updates.
- Verified setup with src/__tests__/infrastructure_check.test.js.
24 changes: 24 additions & 0 deletions PRD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Hathor Wallet Refactoring PRD

This PRD aggregates the technical debt and bad practices identified in the analysis reports.

## CRITICAL WORKFLOW
1. **Start with Infrastructure**: Complete the [Test Environment Setup](./prd/infrastructure.md) first.
2. **Fork for Refactoring**: All subsequent category tasks MUST be forked from the stable branch containing the test infrastructure.
3. **Test-Driven**: No refactoring should be committed without corresponding tests.

## Task Sources
The tasks are organized into specialized files in the `prd/` directory:

- [ ] [Infrastructure (PREREQUISITE)](./prd/infrastructure.md)
- [ ] [Actions and Store](./prd/actions-store.md)
- [ ] [Components](./prd/components.md)
- [ ] [Modules and General](./prd/modules.md)
- [ ] [Reducers](./prd/reducers.md)
- [ ] [Screens](./prd/screens.md)
- [ ] [Sagas](./prd/sagas.md)
- [ ] [Utils](./prd/utils.md)
- [ ] [Root Files](./prd/root-files.md)
- [ ] [Nano Contract and Reown](./prd/nano-reown.md)
- [ ] [Tokens and Atomic Swap](./prd/tokens-atomic-swap.md)

111 changes: 111 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
"text-summary",
"lcov",
"clover"
]
],
"transformIgnorePatterns": [
"node_modules/(?!axios|@hathor/wallet-lib)"
],
"moduleNameMapper": {
"^axios$": "axios/dist/node/axios.cjs"
}
},
"productName": "Hathor Wallet",
"description": "Light wallet for Hathor Network",
Expand Down Expand Up @@ -106,6 +112,7 @@
"@sentry/browser": "7.99.0",
"@sentry/cli": "2.27.0",
"@testing-library/cypress": "10.0.2",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "14.1.2",
"@testing-library/user-event": "14.5.1",
"buffer": "6.0.3",
Expand All @@ -122,6 +129,7 @@
"nodemon": "3.0.3",
"null-loader": "4.0.1",
"process": "0.11.10",
"redux-saga-test-plan": "^4.0.6",
"sass": "1.70.0"
},
"build": {
Expand Down
16 changes: 16 additions & 0 deletions prd/actions-store.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Actions and Store PRD

**Source Report:** [reports/actions-store-bad-practices.md](../reports/actions-store-bad-practices.md)

## Common Directives
- [ ] **Test-Driven Refactoring**: For every task, create or update unit tests to verify the fix and prevent regressions.

## Tasks
- [ ] Critical: Move functions and promises from Redux state to sagas (actions/index.js: 245, 250, 875-878, 888-891, 901-904, 914-917, 927-930, 940-943)
- [ ] Critical: Re-enable Redux Toolkit serialization check with targeted ignores (store/index.js: 19-23)
- [ ] High: Move hardcoded action type strings to constants object (actions/index.js: 127, 132, 137, 142, 147, 152, 157, 162, 167, 172, 177, 182, 187, 194, 202, 209, 215, 220, 225, 230, 235, 240, 245, 250, 255, 262)
- [ ] High: Make actions FSA-compliant by moving root properties to payload (actions/index.js: 268-272, 278-282, 287-290, 304-308, 355-360, 395-398)
- [ ] Medium: Remove redundant redux-thunk middleware (store/index.js: 9, 15)
- [ ] Medium: Complete migration to types syntax in reducers (reducers/index.js: 377)
- [ ] Low: Modernize state update pattern to use spread instead of Object.assign (reducers/index.js: 318-375)
- [ ] Low: Standardize inconsistent payload structures across actions
17 changes: 17 additions & 0 deletions prd/components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Components PRD

**Source Report:** [reports/components-bad-practices.md](../reports/components-bad-practices.md)

## Common Directives
- [ ] **Test-Driven Refactoring**: For every task, create or update unit tests to verify the fix and prevent regressions.

## Tasks
- [ ] Critical: Add missing dependencies to useEffect/useLayoutEffect arrays (AddressList.js: 81, InputNumber.js: 143, ModalConfirmTestnet.js: 17, ModalError.js: 19, NetworkSettingsForm.js: 57, PinPad.js: 115)
- [ ] Critical: Replace jQuery DOM manipulation with React state/refs for modals and animations (GlobalModal.js: 141-145, ModalAddManyTokens.js: 47-71, ModalAddToken.js: 44-68, ModalBackupWords.js: 52-81, ModalConfirm.js: 25-36, RequestError.js: 130-145, SendTokensOne.js: 157-160, OutputsWrapper.js: 48-51, TxData.js: 301, ModalAddressQRCode.js: 60-65)
- [ ] High: Remove console.log/error statements in production (InputNumber.js: 42, TxData.js: 546)
- [ ] High: Memoize props functions with useCallback to prevent re-renders (AddressList.js: 165, CopyButton.js: 22, ChoosePassword.js: 51, ChoosePin.js: 41, Navigation.js: 41, NetworkSettingsForm.js: 92, PinPasswordWrapper.js: 55, TokenBar.js: 158)
- [ ] High: Replace array index as key in lists with unique identifiers (ModalBackupWords.js: 230, SendTokensOne.js: 177, TxData.js: 506, 895)
- [ ] High: Extract inline object/array creation to useMemo or constants (GlobalModal.js: 225, SendTokensOne.js: 177, ModalBackupWords.js: 264-290)
- [ ] Medium: Implement proper cleanup for event listeners in effects (NetworkSettingsForm.js: 47-57, WalletAddress.js: 49-57)
- [ ] Medium: Fix direct state/instance variable mutations (TxData.js: 88, ModalBackupWords.js: 160-162, SendTokensOne.js: 81-83)
- [ ] Low: Split large components into smaller, focused components (TxData.js, ModalBackupWords.js, GlobalModal.js)
15 changes: 15 additions & 0 deletions prd/infrastructure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Infrastructure PRD

**Source Report:** Technical debt identified during setup.

## Common Directives
- [ ] **Test-Driven Refactoring**: For every task, create or update unit tests to verify the fix and prevent regressions.

## Tasks
- [x] **Setup Test Environment (Prerequisite)**:
- Add `@testing-library/react`, `@testing-library/jest-dom`, and `redux-saga-test-plan` to devDependencies.
- Configure `src/setupTests.js` to include standard matchers.
- Create a `src/test-utils.js` (or similar) that provides a custom `render` function wrapping components in a `Provider` with a real or mocked store.
- Ensure `npm test` works for both components and sagas.
- Create a sample test for a Reducer, a Component, and a Saga to verify the setup.
- **Note**: This task must be completed first. All other refactoring tasks should be based on the branch created for this task.
20 changes: 20 additions & 0 deletions prd/modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Modules and General PRD

**Source Report:** [reports/modules-bad-practices.md](../reports/modules-bad-practices.md)

## Common Directives
- [ ] **Test-Driven Refactoring**: For every task, create or update unit tests to verify the fix and prevent regressions.

## Tasks
- [ ] Critical: Fix double dispatch bug in wallet saga (sagas/wallet.js: 281)
- [ ] High: Remove all console.log/error/debug statements in production (sagas/wallet.js, sagas/helpers.js, sagas/featureToggle.js, sagas/tokens.js, screens/StartHardwareWallet.js, components/GlobalModal.js, components/InputNumber.js)
- [ ] High: Refactor global singletons to use dependency injection or context (modules/wallet.js, modules/reown.js, modules/unleash.js)
- [ ] High: Move hardcoded magic numbers to constants.js (sagas/featureToggle.js: 43-44, sagas/tokens.js: 36-37, components/GlobalModal.js: 150, 155, 175)
- [ ] Medium: Fix memory leaks by adding proper cleanup to event listeners and timers (components/GlobalModal.js, components/InputNumber.js, screens/StartHardwareWallet.js, components/ModalAddressQRCode.js)
- [ ] Medium: Address security concerns by moving secrets to .env (SENTRY_DSN, REOWN_PROJECT_ID in constants.js)
- [ ] Medium: Fix inconsistent error handling and silent errors (sagas/helpers.js: 105, components/InputNumber.js: 42, utils/helpers.js: 318, sagas/reown.js: 442, storage.js: 218-235)
- [ ] Medium: Resolve potential circular dependencies (utils/helpers.js -> store -> reducers, sagas/wallet.js -> helpers -> store)
- [ ] Low: Add JSDoc documentation and type annotations (modules/reown.js, modules/wallet.js, modules/unleash.js)
- [ ] Low: Properly await Promises in async operations (utils/helpers.js: 116-122)
- [ ] Low: Move translation function usage after initialization (constants.js: 46)
- [ ] Low: Address all TODO/FIXME/XXX comments across the codebase
18 changes: 18 additions & 0 deletions prd/nano-reown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Nano Contract and Reown Components PRD

**Source Report:** [reports/components-nano-reown-bad-practices.md](../reports/components-nano-reown-bad-practices.md)

## Common Directives
- [ ] **Test-Driven Refactoring**: For every task, create or update unit tests to verify the fix and prevent regressions.

## Tasks
- [ ] Critical: Add missing dependencies to useEffect arrays (ModalChangeAddress.js: 38-52, ModalConfirmUnregister.js: 15-20, ModalSelectAddressToSignData.js: 44-52, ModalSelectAddressToSignTx.js: 26-33, ModalRegisterNanoContract.js: 38-50, ReownModal.js: 32-34, FeedbackModal.js: 43-45, GenericErrorFeedbackModal.js: 24-26)
- [ ] Critical: Replace jQuery DOM manipulation with React state/refs (ModalChangeAddress.js: 39-44, ModalConfirmUnregister.js: 16-19, ModalSelectAddressToSignData.js: 45-51, ModalSelectAddressToSignTx.js: 27-32, ModalRegisterNanoContract.js: 39-49)
- [ ] High: Replace array index as key in lists with unique identifiers (GetBalanceModal.js: 41-59, SignedDataDisplay.js: 23-26, SendTransactionModal.js: 130, 166)
- [ ] High: Wrap prop functions with useCallback (ModalChangeAddress.js, ModalSelectAddressToSignData.js, ModalSelectAddressToSignTx.js, BaseNanoContractModal.js, SendTransactionModal.js)
- [ ] High: Remove console statements in production (CreateTokenRequestData.js: 73, NanoContractActions.js: 95, ErrorDetailModal.js: 41, CreateTokenModal.js: 39)
- [ ] Medium: Extract inline object/array creation to useMemo or constants (ModalChangeAddress.js, ModalSelectAddressToSignData.js, BaseNanoContractModal.js, DAppInfo.js, CreateTokenRequestData.js, ErrorDetailModal.js)
- [ ] Medium: Split large components into smaller ones (BaseNanoContractModal.js, SendTransactionModal.js, NanoContractHistory.js)
- [ ] Medium: Add missing PropTypes to components
- [ ] Medium: Memoize expensive computations with useMemo (NanoContractActions.js, SendTransactionModal.js, BaseNanoContractModal.js)
- [ ] Medium: Replace hardcoded strings with shared constants (NanoContractHistory.js, BaseNanoContractModal.js)
16 changes: 16 additions & 0 deletions prd/reducers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Reducers PRD

**Source Report:** [reports/reducers-bad-practices.md](../reports/reducers-bad-practices.md)

## Common Directives
- [ ] **Test-Driven Refactoring**: For every task, create or update unit tests to verify the fix and prevent regressions.

## Tasks
- [ ] Critical: Fix parameter name bug in onNanoContractDetailLoaded (index.js: 1485)
- [ ] Critical: Move side effects (lockWalletPromise) from reducer to saga (index.js: 707)
- [ ] High: Complete migration of hardcoded action types to types.* constants (index.js: 317-374)
- [ ] High: Add null checks for array access and undefined data fields (index.js: 547-552, 1223)
- [ ] Medium: Replace Object.assign pattern with spread operator (index.js: 318-375)
- [ ] Medium: Replace delete operator with destructuring or spread (index.js: 643, 651, 1090)
- [ ] Medium: Add action payload validation and type checking
- [ ] Low: Standardize return styles (implicit vs explicit) across reducer functions
21 changes: 21 additions & 0 deletions prd/root-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Root Files PRD

**Source Report:** [reports/root-files-bad-practices.md](../reports/root-files-bad-practices.md)

## Common Directives
- [ ] **Test-Driven Refactoring**: For every task, create or update unit tests to verify the fix and prevent regressions.

## Tasks
- [ ] Critical: Fix error state logic bug in ErrorWrapper (ErrorWrapper.js: 46)
- [ ] High: Add missing dependencies to useEffect hooks (App.js: 182, ErrorWrapper.js: 33)
- [ ] High: Replace jQuery modal manipulation with React state (ErrorWrapper.js: 47)
- [ ] High: Add null checks for DOM elements and context (App.js: 113, index.js: 37)
- [ ] High: Move hardcoded secrets and URLs to .env files (constants.js: 80, 210-211, 310)
- [ ] Medium: Wrap application with root-level Error Boundary (index.js)
- [ ] Medium: Document global polyfills for Buffer and process (index.js: 22-26)
- [ ] Medium: Create ROUTES constant object to replace hardcoded strings (App.js)
- [ ] Medium: Simplify and extract logic from complex nested components (App.js: 275-330)
- [ ] Medium: Remove duplicate CSS imports (ErrorWrapper.js: 14-17)
- [ ] Low: Add PropTypes or TypeScript definitions
- [ ] Low: Organize constants into logical groupings and document magic numbers
- [ ] Low: Add proper error handling and recovery to storage operations (storage.js)
Loading
Loading