Skip to content

fix: resolve TypeScript compilation errors and replace ethers with viem#58

Open
kushbosamiya wants to merge 1 commit into
StabilityNexus:mainfrom
kushbosamiya:fix/typescript-errors
Open

fix: resolve TypeScript compilation errors and replace ethers with viem#58
kushbosamiya wants to merge 1 commit into
StabilityNexus:mainfrom
kushbosamiya:fix/typescript-errors

Conversation

@kushbosamiya

@kushbosamiya kushbosamiya commented Feb 27, 2026

Copy link
Copy Markdown

Problem

Three categories of TypeScript errors existed in the codebase:

  1. Type mismatch in dashboard/page.tsx (3 locations): .filter(auction => auction != null) does not narrow the type from (Auction | undefined)[] to Auction[] in TypeScript, causing compilation errors at lines 42, 62, and 82.

  2. ethers module referenced in 3 files: parseEther and formatEther were imported from ethers (~800KB), while viem (already a project dependency) provides identical functions.

Changes

Type predicate fix

  • app/dashboard/page.tsx: Added (auction): auction is Auction type predicates to all 3 .filter() calls

ethers → viem migration

  • lib/services/english-auction-service.ts: parseEther from viem
  • lib/services/allpay-auction-service.ts: parseEther from viem
  • components/auction/vickrey-commit-form.tsx: formatEther from viem
  • package.json: removed ethers dependency

Verification

npx tsc --noEmit passes with zero errors.

Summary by CodeRabbit

  • Refactor

    • Updated internal dependencies to improve type safety and code maintainability.
    • Enhanced filtering logic with stricter type checks.
  • Chores

    • Removed unused dependency from project configuration.

- Add type predicates to .filter() calls in dashboard/page.tsx to
  properly narrow (Auction | undefined)[] to Auction[] (3 locations)
- Replace all ethers imports with viem equivalents:
  - english-auction-service.ts: parseEther
  - allpay-auction-service.ts: parseEther
  - vickrey-commit-form.tsx: formatEther
- Remove ethers (~800KB) from package.json since viem already
  provides parseEther and formatEther
@coderabbitai

coderabbitai Bot commented Feb 27, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request migrates Ether parsing and formatting utilities from the ethers library to viem across multiple service files, updates the dashboard to use type-guard filters for better compile-time type inference, and removes the ethers dependency from package.json.

Changes

Cohort / File(s) Summary
Library Migration to Viem
components/auction/vickrey-commit-form.tsx, lib/services/allpay-auction-service.ts, lib/services/english-auction-service.ts
Replaced ethers imports for formatEther and parseEther with equivalent imports from viem library.
Type Refinement
app/dashboard/page.tsx
Replaced simple null checks with type-guard filter functions to narrow auction arrays to Auction[] type at compile time for improved type safety.
Dependency Cleanup
package.json
Removed ethers package from project dependencies.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • Zahnentferner

Poem

🐰 A rabbit hops through code so bright,
Swapping ethers for viem's light,
Type guards tighten filters clean,
Cleaner imports, best we've seen!
Dependencies trimmed with care,
Better code floats in the air! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures both main changes: resolving TypeScript compilation errors through type predicates and replacing ethers with viem to reduce bundle size.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
components/auction/vickrey-commit-form.tsx (1)

82-82: Consider using parseEther from viem for consistency.

Since you've already imported from viem, consider replacing the manual conversion with parseEther. It handles decimal string parsing more robustly and avoids floating-point precision issues with parseFloat and Math.floor.

♻️ Proposed refactor
+import { formatEther, parseEther } from "viem";
-import { formatEther } from "viem";
-      const bidAmountWei = BigInt(Math.floor(parseFloat(bidAmount) * 1e18));
+      const bidAmountWei = parseEther(bidAmount);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/auction/vickrey-commit-form.tsx` at line 82, Replace the manual
float-based conversion for bidAmountWei with viem's parseEther: import
parseEther from 'viem' (or add to the existing viem import) and set bidAmountWei
= parseEther(bidAmount) (ensuring bidAmount is the decimal string you expect).
Update any surrounding code that assumes BigInt construction to use the
parseEther bigint result and keep input validation/trim on bidAmount as needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@components/auction/vickrey-commit-form.tsx`:
- Line 82: Replace the manual float-based conversion for bidAmountWei with
viem's parseEther: import parseEther from 'viem' (or add to the existing viem
import) and set bidAmountWei = parseEther(bidAmount) (ensuring bidAmount is the
decimal string you expect). Update any surrounding code that assumes BigInt
construction to use the parseEther bigint result and keep input validation/trim
on bidAmount as needed.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 096d20f and b9cfdb4.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • app/dashboard/page.tsx
  • components/auction/vickrey-commit-form.tsx
  • lib/services/allpay-auction-service.ts
  • lib/services/english-auction-service.ts
  • package.json
💤 Files with no reviewable changes (1)
  • package.json

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