Skip to content

Commit 0a59a7e

Browse files
committed
low final HF warning
1 parent 64f350e commit 0a59a7e

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed

src/components/transactions/Switch/BaseSwitchModalContent.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ export const BaseSwitchModalContent = ({
490490
}, [txError]);
491491

492492
// Compute HF effect of withdrawing inputAmount (copied from SwitchModalTxDetails)
493-
const { hfEffectOfFromAmount } = useMemo(() => {
493+
const { hfEffectOfFromAmount, hfAfterSwap } = useMemo(() => {
494494
try {
495495
if (!poolReserve || !userReserve || !extendedUser || !switchRates || !targetReserve)
496496
return { hfEffectOfFromAmount: '0' };
@@ -519,7 +519,7 @@ export const BaseSwitchModalContent = ({
519519
hfAfterSwap: hfAfterSwap.toString(),
520520
};
521521
} catch {
522-
return { hfEffectOfFromAmount: '0' };
522+
return { hfEffectOfFromAmount: '0', hfAfterSwap: undefined };
523523
}
524524
}, [
525525
poolReserve,
@@ -531,6 +531,16 @@ export const BaseSwitchModalContent = ({
531531
safeSlippage,
532532
]);
533533

534+
const isHFLow = useMemo(() => {
535+
if (!hfAfterSwap) return false;
536+
537+
const hfNumber = new BigNumber(hfAfterSwap);
538+
539+
if (hfNumber.lt(0)) return false;
540+
541+
return hfNumber.lt(1.05);
542+
}, [hfAfterSwap]);
543+
534544
const shouldUseFlashloanFn = (healthFactor: string, hfEffectOfFromAmount: string) => {
535545
return (
536546
healthFactor !== '-1' &&
@@ -954,6 +964,17 @@ export const BaseSwitchModalContent = ({
954964
</Warning>
955965
)}
956966

967+
{modalType === ModalType.CollateralSwap && isHFLow && (
968+
<Warning severity="error" icon={false} sx={{ mt: 5 }}>
969+
<Typography variant="caption">
970+
<Trans>
971+
Low health factor after swap. Please select a different asset or lower the
972+
amount.
973+
</Trans>
974+
</Typography>
975+
</Warning>
976+
)}
977+
957978
<SwitchErrors
958979
ratesError={ratesError}
959980
balance={selectedInputToken.balance}
@@ -1057,7 +1078,10 @@ export const BaseSwitchModalContent = ({
10571078
slippageValidation?.severity === ValidationSeverity.ERROR ||
10581079
isSwappingSafetyModuleToken ||
10591080
(requireConfirmation && !highPriceImpactConfirmed) ||
1060-
(shouldUseFlashloan === true && !!poolReserve && !poolReserve.flashLoanEnabled)
1081+
(shouldUseFlashloan === true &&
1082+
!!poolReserve &&
1083+
!poolReserve.flashLoanEnabled) ||
1084+
(modalType === ModalType.CollateralSwap && isHFLow)
10611085
}
10621086
chainId={selectedChainId}
10631087
switchRates={switchRates}

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,6 +2868,10 @@ msgstr "and about SPK program"
28682868
msgid "DAI balance will be converted via DSR contracts and then supplied as sDAI. Switching incurs no additional costs and no slippage."
28692869
msgstr "DAI balance will be converted via DSR contracts and then supplied as sDAI. Switching incurs no additional costs and no slippage."
28702870

2871+
#: src/components/transactions/Switch/BaseSwitchModalContent.tsx
2872+
msgid "Low health factor after swap. Please select a different asset or lower the amount."
2873+
msgstr "Low health factor after swap. Please select a different asset or lower the amount."
2874+
28712875
#: src/components/transactions/DebtSwitch/DebtSwitchModalContent.tsx
28722876
msgid "Select an asset"
28732877
msgstr "Select an asset"

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)