Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hooks/useRepayTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export function useRepayTransaction({
amount: repayAssets,
marketId: market.uniqueKey,
},
'signing',
usePermit2Setting ? 'signing' : 'repaying',
);

await executeRepayTransaction();
Expand Down
21 changes: 18 additions & 3 deletions src/modals/borrow/components/withdraw-collateral-and-repay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,27 @@ export function WithdrawCollateralAndRepay({
});

const handleRepay = useCallback(() => {
if (!permit2Authorized || (!usePermit2Setting && !isApproved)) {
const needsRepay = repayAssets > 0n || repayShares > 0n;
if (needsRepay && (!permit2Authorized || (!usePermit2Setting && !isApproved))) {
void approveAndRepay();
} else {
void signAndRepay();
}
}, [permit2Authorized, usePermit2Setting, isApproved, approveAndRepay, signAndRepay]);
}, [repayAssets, repayShares, permit2Authorized, usePermit2Setting, isApproved, approveAndRepay, signAndRepay]);

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


// if max is clicked, set the repayShares to max shares
const setShareToMax = useCallback(() => {
Expand Down Expand Up @@ -301,7 +316,7 @@ export function WithdrawCollateralAndRepay({
variant="primary"
className="min-w-32"
>
{!isApproved && !permit2Authorized ? 'Approve & Repay' : withdrawAmount > 0 ? 'Withdraw & Repay' : 'Repay'}
{buttonLabel}
</ExecuteTransactionButton>
</div>
{(withdrawAmount > 0n || repayAssets > 0n) && (
Expand Down