Skip to content

fix: withdraw flow#291

Merged
antoncoding merged 1 commit intomasterfrom
fix/withdraw
Jan 13, 2026
Merged

fix: withdraw flow#291
antoncoding merged 1 commit intomasterfrom
fix/withdraw

Conversation

@antoncoding
Copy link
Copy Markdown
Owner

@antoncoding antoncoding commented Jan 13, 2026

Summary by CodeRabbit

Bug Fixes

  • Fixed button labeling on withdraw and repay transactions to dynamically display the correct action ("Approve & Repay", "Withdraw & Repay", "Withdraw", or "Repay") based on transaction state.
  • Improved handling of withdrawal transactions that don't require repayment.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Jan 13, 2026

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

Project Deployment Review Updated (UTC)
monarch Ready Ready Preview, Comment Jan 13, 2026 5:47am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

Modified 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

Cohort / File(s) Summary
Tracking & Hook Logic
src/hooks/useRepayTransaction.ts
Conditional tracking step label: uses 'signing' when Permit2 enabled, otherwise 'repaying'
Modal State & Labels
src/modals/borrow/components/withdraw-collateral-and-repay.tsx
Added needsRepay gate to trigger appropriate repay flow, expanded handleRepay dependencies, introduced buttonLabel memo for dynamic action button text based on state

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

ui

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
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.
Title check ❓ Inconclusive The title 'fix: withdraw flow' is vague and doesn't clearly describe the specific changes made. The PR modifies repay transaction tracking and adds repayment gating logic, but the title only mentions 'withdraw flow' without indicating these details. Use a more specific title like 'fix: add repayment check and dynamic labels to withdraw-repay flow' to clarify what aspect of the withdraw flow is being fixed.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/withdraw

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 added the ui User interface label Jan 13, 2026
@antoncoding antoncoding linked an issue Jan 13, 2026 that may be closed by this pull request
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1f6e44c and c37d085.

📒 Files selected for processing (2)
  • src/hooks/useRepayTransaction.ts
  • src/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.

Comment on lines +69 to +81
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]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

@antoncoding antoncoding merged commit 2e334f3 into master Jan 13, 2026
4 checks passed
@antoncoding antoncoding deleted the fix/withdraw branch January 13, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui User interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

potential withdrawal issue for collatearl

1 participant