Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughModified transaction repayment logic to conditionally set the initial tracking step based on Permit2 settings, and updated withdraw-collateral-and-repay modal to gate repay actions and dynamically compute button labels based on approval and repayment state. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @src/modals/borrow/components/withdraw-collateral-and-repay.tsx:
- Around line 69-81: The buttonLabel logic in the useMemo must mirror the
approval logic in handleRepay: replace the current approval check (needsRepay &&
!isApproved && !permit2Authorized) with the same condition used in handleRepay
((needsRepay && (!permit2Authorized || (!usePermit2Setting && !isApproved)))).
Also add usePermit2Setting to the useMemo dependency array so the label updates
correctly when that setting changes.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/hooks/useRepayTransaction.tssrc/modals/borrow/components/withdraw-collateral-and-repay.tsx
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-09T10:06:39.848Z
Learnt from: antoncoding
Repo: antoncoding/monarch PR: 231
File: src/hooks/useDeployMorphoMarketV1Adapter.ts:3-3
Timestamp: 2025-12-09T10:06:39.848Z
Learning: In Wagmi v3, useConnection is the correct hook to obtain the connected wallet address, chainId, and connection status (isConnected). This replaces the useAccount hook from Wagmi v2. In your code under src/hooks, use: const { address, chainId, isConnected } = useConnection() from 'wagmi' to access the connected wallet information.
Applied to files:
src/hooks/useRepayTransaction.ts
🔇 Additional comments (2)
src/hooks/useRepayTransaction.ts (1)
380-380: LGTM!Correctly aligns the initial tracking step with the available steps for each flow. Permit2 starts at 'signing', non-Permit2 skips to 'repaying'.
src/modals/borrow/components/withdraw-collateral-and-repay.tsx (1)
60-67: LGTM!Good fix. Withdraw-only transactions now skip the approval flow entirely since no loan token transfer is needed.
| const buttonLabel = useMemo(() => { | ||
| const needsRepay = repayAssets > 0n || repayShares > 0n; | ||
| if (needsRepay && !isApproved && !permit2Authorized) { | ||
| return 'Approve & Repay'; | ||
| } | ||
| if (withdrawAmount > 0n && needsRepay) { | ||
| return 'Withdraw & Repay'; | ||
| } | ||
| if (withdrawAmount > 0n) { | ||
| return 'Withdraw'; | ||
| } | ||
| return 'Repay'; | ||
| }, [repayAssets, repayShares, isApproved, permit2Authorized, withdrawAmount]); |
There was a problem hiding this comment.
Button label logic doesn't match handleRepay logic.
The approval check here uses !isApproved && !permit2Authorized, but handleRepay uses !permit2Authorized || (!usePermit2Setting && !isApproved).
This can cause the button to say "Repay" when the action is actually "Approve & Repay" (e.g., when Permit2 is enabled but not authorized, and ERC20 is already approved).
Suggested fix
const buttonLabel = useMemo(() => {
const needsRepay = repayAssets > 0n || repayShares > 0n;
- if (needsRepay && !isApproved && !permit2Authorized) {
+ const needsApproval = !permit2Authorized || (!usePermit2Setting && !isApproved);
+ if (needsRepay && needsApproval) {
return 'Approve & Repay';
}
if (withdrawAmount > 0n && needsRepay) {
return 'Withdraw & Repay';
}
if (withdrawAmount > 0n) {
return 'Withdraw';
}
return 'Repay';
-}, [repayAssets, repayShares, isApproved, permit2Authorized, withdrawAmount]);
+}, [repayAssets, repayShares, isApproved, permit2Authorized, withdrawAmount, usePermit2Setting]);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const buttonLabel = useMemo(() => { | |
| const needsRepay = repayAssets > 0n || repayShares > 0n; | |
| if (needsRepay && !isApproved && !permit2Authorized) { | |
| return 'Approve & Repay'; | |
| } | |
| if (withdrawAmount > 0n && needsRepay) { | |
| return 'Withdraw & Repay'; | |
| } | |
| if (withdrawAmount > 0n) { | |
| return 'Withdraw'; | |
| } | |
| return 'Repay'; | |
| }, [repayAssets, repayShares, isApproved, permit2Authorized, withdrawAmount]); | |
| const buttonLabel = useMemo(() => { | |
| const needsRepay = repayAssets > 0n || repayShares > 0n; | |
| const needsApproval = !permit2Authorized || (!usePermit2Setting && !isApproved); | |
| if (needsRepay && needsApproval) { | |
| return 'Approve & Repay'; | |
| } | |
| if (withdrawAmount > 0n && needsRepay) { | |
| return 'Withdraw & Repay'; | |
| } | |
| if (withdrawAmount > 0n) { | |
| return 'Withdraw'; | |
| } | |
| return 'Repay'; | |
| }, [repayAssets, repayShares, isApproved, permit2Authorized, withdrawAmount, usePermit2Setting]); |
🤖 Prompt for AI Agents
In @src/modals/borrow/components/withdraw-collateral-and-repay.tsx around lines
69 - 81, The buttonLabel logic in the useMemo must mirror the approval logic in
handleRepay: replace the current approval check (needsRepay && !isApproved &&
!permit2Authorized) with the same condition used in handleRepay ((needsRepay &&
(!permit2Authorized || (!usePermit2Setting && !isApproved)))). Also add
usePermit2Setting to the useMemo dependency array so the label updates correctly
when that setting changes.
Summary by CodeRabbit
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.