Skip to content

Improve error handling: surface transaction errors, validate inputs, add loading states#2

Open
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1782167166-improve-error-handling
Open

Improve error handling: surface transaction errors, validate inputs, add loading states#2
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1782167166-improve-error-handling

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 22, 2026

Copy link
Copy Markdown

Summary

Previously, all writeContract calls in the frontend silently discarded errors — users got no feedback on rejected transactions, on-chain reverts, or invalid input. Configuration issues (missing contract address, missing WalletConnect project ID) also failed silently at runtime. The deploy script had no pre-flight checks. The build itself was broken on main due to missing tsconfig.json.

Frontend (page.tsx):

  • Destructure { error, isPending, data: txHash, reset } from useWriteContract and track confirmation via useWaitForTransactionReceipt
  • Wire all states into a StatusMessage banner (error/pending/success) with auto-dismiss
  • Wrap parseUnits(rewardPerUser, 6) and BigInt(maxParticipants) in try-catch with user-friendly messages
  • Validate reward > 0, participants in [1, 10000] before submitting
  • Guard the cost-preview section against NaN from invalid numeric input
  • Disable and relabel buttons during pending/confirming states
  • extractErrorMessage() maps common contract revert strings to human-readable text

Frontend (contract.ts): console.warn when NEXT_PUBLIC_CONTRACT_ADDRESS is unset and falls back to zero address.

Frontend (providers.tsx): Read NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID from env with a non-empty placeholder fallback (required by RainbowKit at build time); warn in browser when using placeholder.

Frontend config (new files): Add missing tsconfig.json (target es2020, @/* path alias) and next.config.js — fixes pre-existing build failure where @/lib/contract couldn't resolve.

Deploy script (deploy.js): Validate signer exists, deployer has non-zero balance, USDC address is valid and non-zero before deploying. Print next-step instructions on success.

Smart contract (FCFSCampaign.sol): require(_usdc != address(0)) in constructor.

Link to Devin session: https://app.devin.ai/sessions/9292c3c9be21402d9a8e57b5f85f099f
Requested by: @fcfsprojects


Open in Devin Review

…ract

- page.tsx: Surface writeContract errors/success via status banner, add
  input validation with try-catch around parseUnits/BigInt, add loading
  states to buttons, track tx confirmation, guard NaN in cost preview
- contract.ts: Log console.warn when contract address falls back to zero
- providers.tsx: Read WalletConnect project ID from env var instead of
  hardcoded placeholder, warn when missing
- deploy.js: Validate deployer account exists and has balance, validate
  USDC address format and non-zero, print next-step instructions
- FCFSCampaign.sol: Add require(_usdc != address(0)) in constructor

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fcfsprojects fcfsprojects self-assigned this Jun 22, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
fcfsproject Ready Ready Preview, Comment Jun 22, 2026 10:40pm

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Open in Devin Review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🚩 OpenZeppelin v5 used with v4 import path for ReentrancyGuard

The project depends on @openzeppelin/contracts: ^5.0.0 (per contracts/package.json), but the import at contracts/FCFSCampaign.sol:6 uses @openzeppelin/contracts/security/ReentrancyGuard.sol, which is the v4 path. In OpenZeppelin v5, ReentrancyGuard was moved to @openzeppelin/contracts/utils/ReentrancyGuard.sol. This is a pre-existing issue unrelated to this PR's one-line constructor change, but it would cause a compilation failure if ^5.0.0 resolves to an actual v5 release.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread frontend/src/app/page.tsx
Comment on lines 142 to 144
functionName: 'createCampaign',
args: [tweetUrl, taskType, reward, max],
})

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🚩 Missing ERC20 approve flow before createCampaign

The createCampaign contract function calls usdc.safeTransferFrom(msg.sender, address(this), totalAmount) at contracts/FCFSCampaign.sol:108, which requires the caller to have previously approved the contract to spend their USDC. The frontend's handleCreate at frontend/src/app/page.tsx:139 calls createCampaign directly without first calling approve on the USDC token. The ABI in frontend/src/lib/contract.ts also doesn't include the USDC approve function (it wouldn't — that's on a separate contract). This means every createCampaign call will revert unless the user has independently approved the contract. The error handler at line 38 does catch 'ERC20: insufficient allowance', but this is a poor UX — the frontend should prompt for and execute an approval transaction first. This is a pre-existing issue not introduced by this PR, but the PR's improved error handling now makes it more visible.

(Refers to lines 139-144)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

- Add tsconfig.json with target es2020 and @/* path alias (was missing,
  causing build failure on main too)
- Add next.config.js (required by Next.js)
- Fix providers.tsx: keep non-empty placeholder projectId to prevent
  RainbowKit from throwing at build time; only warn in browser context

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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