Skip to content

Commit 753499e

Browse files
committed
any zero ltv guard for collateral swap
1 parent f0eab11 commit 753499e

File tree

8 files changed

+25
-17
lines changed

8 files changed

+25
-17
lines changed

src/components/transactions/Swap/errors/SwapErrors.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Dispatch, useEffect } from 'react';
2+
import { useZeroLTVBlockingWithdraw } from 'src/hooks/useZeroLTVBlockingWithdraw';
23

34
import { useModalContext } from '../../../../hooks/useModal';
45
import { TrackAnalyticsHandlers } from '../analytics/useTrackAnalytics';
@@ -35,6 +36,7 @@ export const SwapErrors = ({
3536
trackingHandlers: TrackAnalyticsHandlers;
3637
}) => {
3738
const { txError } = useModalContext();
39+
const assetsBlockingWithdraw = useZeroLTVBlockingWithdraw();
3840

3941
useEffect(() => {
4042
if (txError) {
@@ -78,7 +80,7 @@ export const SwapErrors = ({
7880
);
7981
}
8082

81-
if (hasZeroLTVBlocking(state, [])) {
83+
if (hasZeroLTVBlocking(state, assetsBlockingWithdraw)) {
8284
return (
8385
<ZeroLTVBlockingGuard
8486
state={state}

src/components/transactions/Swap/errors/shared/ZeroLTVBlockingError.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export const ZeroLTVBlockingError = ({ sx }: { sx?: SxProps }) => {
77
<Warning severity="error" sx={{ mt: 4, ...sx }} icon={false}>
88
<Typography variant="caption">
99
<Trans>
10-
You have assets with zero LTV that are blocking this operation. Please disable them as
11-
collateral first.
10+
You have assets with zero LTV that are blocking this operation. Please withdraw them or
11+
disable them as collateral first.
1212
</Trans>
1313
</Typography>
1414
</Warning>

src/components/transactions/Swap/errors/shared/ZeroLTVBlockingGuard.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ import { ActionsBlockedReason, SwapError, SwapState, SwapType } from '../../type
66
import { ZeroLTVBlockingError } from './ZeroLTVBlockingError';
77

88
export const hasZeroLTVBlocking = (state: SwapState, blockingAssets: string[]) => {
9-
return (
10-
blockingAssets.length > 0 &&
11-
!blockingAssets.includes(state.sourceToken.symbol) &&
12-
state.swapType !== SwapType.RepayWithCollateral
13-
);
9+
// Never block RepayWithCollateral
10+
if (state.swapType === SwapType.RepayWithCollateral) {
11+
return false;
12+
}
13+
// For CollateralSwap, block if the user has any zero-LTV collateral enabled
14+
if (state.swapType === SwapType.CollateralSwap) {
15+
return blockingAssets.length > 0;
16+
}
17+
// For other swap types, block if there are zero-LTV assets enabled
18+
// and the source token is not one of those (existing behavior)
19+
return blockingAssets.length > 0 && !blockingAssets.includes(state.sourceToken.symbol);
1420
};
1521

1622
export const ZeroLTVBlockingGuard = ({
@@ -38,7 +44,7 @@ export const ZeroLTVBlockingGuard = ({
3844
const blockingError: SwapError = {
3945
rawError: new Error('ZeroLTVBlockingError'),
4046
message:
41-
'You have assets with zero LTV that are blocking this operation. Please disable them as collateral first.',
47+
'You have assets with zero LTV that are blocking this operation. Please withdraw them or disable them as collateral first.',
4248
actionBlocked: true,
4349
};
4450
setState({

src/locales/el/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,10 @@ msgstr "Costs & Fees"
12511251
msgid "deposited"
12521252
msgstr "deposited"
12531253

1254+
#: src/components/transactions/Swap/errors/shared/ZeroLTVBlockingError.tsx
1255+
msgid "You have assets with zero LTV that are blocking this operation. Please withdraw them or disable them as collateral first."
1256+
msgstr "You have assets with zero LTV that are blocking this operation. Please withdraw them or disable them as collateral first."
1257+
12541258
#: src/components/incentives/MeritIncentivesTooltipContent.tsx
12551259
#: src/components/incentives/MeritIncentivesTooltipContent.tsx
12561260
#: src/components/incentives/MerklIncentivesTooltipContent.tsx
@@ -3280,10 +3284,6 @@ msgstr "Cooldown to unstake"
32803284
msgid "User does not have outstanding variable rate debt on this reserve"
32813285
msgstr "User does not have outstanding variable rate debt on this reserve"
32823286

3283-
#: src/components/transactions/Swap/errors/shared/ZeroLTVBlockingError.tsx
3284-
msgid "You have assets with zero LTV that are blocking this operation. Please disable them as collateral first."
3285-
msgstr "You have assets with zero LTV that are blocking this operation. Please disable them as collateral first."
3286-
32873287
#: src/modules/faucet/FaucetAssetsList.tsx
32883288
msgid "Test Assets"
32893289
msgstr "Test Assets"

src/locales/es/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/fr/messages.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)