refactor: extract duplicated code into shared utilities#4
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
refactor: extract duplicated code into shared utilities#4devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
- Add lib/constants.ts: protocol fee, USDC decimals, task types, reusable styles - Add lib/fees.ts: calculateCampaignCost (display) and calculateCampaignAmounts (on-chain) - Add components/FormInput.tsx: reusable styled input with label - Add components/CampaignCard.tsx: campaign list item card - Add components/CostSummary.tsx: fee breakdown display using shared calculation - Add hooks/useCampaignContract.ts: encapsulates contract reads/writes - Refactor page.tsx to consume shared modules (230 -> 150 lines) - Add tsconfig.json with path aliases and next.config.js for build Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Identified 5 duplicated code patterns in the frontend and refactored them into reusable shared modules:
New shared modules:
lib/constants.ts— single source of truth forPROTOCOL_FEE_PERCENT,USDC_DECIMALS,TASK_TYPES, and reusable Tailwind class strings (styles.input,styles.card,styles.buttonPrimary)lib/fees.ts—calculateCampaignCost()for display andcalculateCampaignAmounts()for on-chain BigInt values (previously duplicated 3× inline in the cost summary + separately inhandleCreate)hooks/useCampaignContract.ts—useCampaignCount()anduseCampaignActions()encapsulating repeatedaddress + abi + functionNameconfigcomponents/FormInput.tsx— reusable styled input (eliminates 3× repeated input class string)components/CampaignCard.tsx/CostSummary.tsx— extracted card and fee breakdown displayResult:
page.tsxreduced from 230 → 150 lines; all magic numbers and repeated styling consolidated. No behavioral changes.Link to Devin session: https://app.devin.ai/sessions/d9f50441c19f4cd88146bcfdc96c9664
Requested by: @fcfsprojects