Skip to content

Refactor: Extract duplicate code, add TDD test coverage, standardize on pnpm - #2

Merged
fedosov merged 4 commits into
mainfrom
refactor/code-duplication-tdd-pnpm
Oct 28, 2025
Merged

Refactor: Extract duplicate code, add TDD test coverage, standardize on pnpm#2
fedosov merged 4 commits into
mainfrom
refactor/code-duplication-tdd-pnpm

Conversation

@fedosov

@fedosov fedosov commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR refactors the codebase to eliminate duplicate code, adds comprehensive test coverage using TDD methodology, and standardizes the project on pnpm package manager.

Code Duplication Eliminated

  • decimal-converter.js: Extracted P3D decimal multiplier handling

    • Removed 44 lines of duplicate code from BridgeForm.js
    • Centralized conversion between actual (contract) and display amounts
    • Added 27 comprehensive tests
  • error-parser.js: Centralized transaction error categorization

    • Removed 101 lines from Expatriation.js
    • Removed 76 lines from Repatriation.js
    • Unified error handling across all transaction components
    • Added 32 comprehensive tests
  • network-switcher.js: Extracted MetaMask network switching logic

    • Removed 68 lines from BridgeForm.js
    • Removed 43 lines from AssistantsList.js
    • Handles network switching with automatic fallback to add network
    • Added 16 comprehensive tests

Test Coverage

  • All utilities implemented following TDD (Test-Driven Development) methodology
  • RED-GREEN-REFACTOR cycle applied consistently
  • 75 new tests added (27 + 32 + 16)
  • 100% test pass rate (88/88 tests passing)
  • Fixed 7 pre-existing test failures

Package Manager Migration

  • Standardized on pnpm for better dependency management and faster installs
  • Added .mise.toml for Node 18 + pnpm environment setup
  • Added .npmrc with hoisting configuration for React compatibility
  • Updated all documentation (README.md, CLAUDE.md) to use pnpm commands
  • Added Makefile with test target for CI/CD workflows
  • Resolved ESLint plugin conflict by creating .eslintrc.json

Test Plan

  • All 88 tests pass with make test
  • pnpm install completes successfully
  • pnpm start runs without ESLint conflicts
  • pnpm test runs all tests successfully
  • Pre-existing test failures fixed
  • No regressions in existing functionality
  • Decimal conversion works correctly for P3D tokens
  • Error parsing correctly categorizes all transaction errors
  • Network switching works with automatic fallback

Changes

New Files:

  • src/utils/decimal-converter.js + tests
  • src/utils/error-parser.js + tests
  • src/utils/network-switcher.js + tests
  • .mise.toml (Node + pnpm config)
  • .npmrc (pnpm config)
  • .eslintrc.json (ESLint config)
  • Makefile (test target)
  • CLAUDE.md (developer documentation)

Modified Files:

  • src/components/BridgeForm.js (-112 lines of duplicate code)
  • src/components/AssistantsList.js (-43 lines of duplicate code)
  • src/components/Expatriation.js (-101 lines of duplicate code)
  • src/components/Repatriation.js (-76 lines of duplicate code)
  • src/utils/provider-manager.js (exported ProviderManager class)
  • src/utils/__tests__/retry-with-fallback.test.js (fixed expectation)
  • README.md (updated to pnpm)
  • package.json (added packageManager field, removed eslintConfig)
  • .gitignore (added package-lock.json)

Total Impact:

  • +1277 insertions, -359 deletions
  • Net reduction of ~332 lines while adding comprehensive test coverage

🤖 Generated with Claude Code

fedosov and others added 4 commits October 28, 2025 14:31
…on pnpm

Extract duplicate code into centralized utilities:
- decimal-converter.js: P3D decimal multiplier handling (44 lines removed from BridgeForm)
- error-parser.js: transaction error categorization (177 lines removed from Expatriation/Repatriation)
- network-switcher.js: MetaMask network switching (111 lines removed from BridgeForm/AssistantsList)

Add comprehensive test coverage using TDD methodology:
- 27 tests for decimal-converter
- 32 tests for error-parser
- 16 tests for network-switcher
- All tests passing (88/88)

Fix pre-existing test failures:
- Export ProviderManager class for settings-consistency tests
- Correct health status expectation in retry-with-fallback tests

Standardize on pnpm package manager:
- Add .mise.toml for Node 18 + pnpm
- Add .npmrc with hoisting config for React compatibility
- Update all docs (README, CLAUDE.md) to use pnpm commands
- Add Makefile with test target
- Add packageManager field to package.json
- Resolve ESLint plugin conflict with .eslintrc.json

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Resolve merge conflicts:
- Makefile: Keep main's comprehensive version, replace npm with pnpm
- retry-with-fallback.test.js: Keep both test scenarios (rate limiting + degraded state)
- provider-manager.js: Accept main's grammatically correct comment

All 89 tests passing.
…ageManager

The pnpm/action-setup@v4 action auto-detects version from package.json's packageManager field.
Having both causes ERR_PNPM_BAD_PM_VERSION conflict.
@fedosov
fedosov merged commit 165eaca into main Oct 28, 2025
1 check passed
@fedosov
fedosov deleted the refactor/code-duplication-tdd-pnpm branch October 28, 2025 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant