fix: resolve TypeScript compilation errors and replace ethers with viem#58
fix: resolve TypeScript compilation errors and replace ethers with viem#58kushbosamiya wants to merge 1 commit into
Conversation
- 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
📝 WalkthroughWalkthroughThis 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
components/auction/vickrey-commit-form.tsx (1)
82-82: Consider usingparseEtherfrom 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 withparseFloatandMath.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
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (5)
app/dashboard/page.tsxcomponents/auction/vickrey-commit-form.tsxlib/services/allpay-auction-service.tslib/services/english-auction-service.tspackage.json
💤 Files with no reviewable changes (1)
- package.json
Problem
Three categories of TypeScript errors existed in the codebase:
Type mismatch in dashboard/page.tsx (3 locations):
.filter(auction => auction != null)does not narrow the type from(Auction | undefined)[]toAuction[]in TypeScript, causing compilation errors at lines 42, 62, and 82.ethersmodule referenced in 3 files:parseEtherandformatEtherwere imported fromethers(~800KB), whileviem(already a project dependency) provides identical functions.Changes
Type predicate fix
app/dashboard/page.tsx: Added(auction): auction is Auctiontype predicates to all 3.filter()callsethers → viem migration
lib/services/english-auction-service.ts:parseEtherfrom viemlib/services/allpay-auction-service.ts:parseEtherfrom viemcomponents/auction/vickrey-commit-form.tsx:formatEtherfrom viempackage.json: removedethersdependencyVerification
npx tsc --noEmitpasses with zero errors.Summary by CodeRabbit
Refactor
Chores