Skip to content

Commit 713afae

Browse files
committed
low final HF warning
1 parent 64f350e commit 713afae

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

src/components/transactions/Switch/BaseSwitchModalContent.tsx

Lines changed: 23 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,12 @@ export const BaseSwitchModalContent = ({
531531
safeSlippage,
532532
]);
533533

534+
const isHFLow = useMemo(() => {
535+
if (!hfAfterSwap) return false;
536+
537+
return new BigNumber(hfAfterSwap).lt(1.05);
538+
}, [hfAfterSwap]);
539+
534540
const shouldUseFlashloanFn = (healthFactor: string, hfEffectOfFromAmount: string) => {
535541
return (
536542
healthFactor !== '-1' &&
@@ -954,6 +960,17 @@ export const BaseSwitchModalContent = ({
954960
</Warning>
955961
)}
956962

963+
{modalType === ModalType.CollateralSwap && isHFLow && (
964+
<Warning severity="error" icon={false} sx={{ mt: 5 }}>
965+
<Typography variant="caption">
966+
<Trans>
967+
Low health factor after swap. Please select a different asset or lower the
968+
amount.
969+
</Trans>
970+
</Typography>
971+
</Warning>
972+
)}
973+
957974
<SwitchErrors
958975
ratesError={ratesError}
959976
balance={selectedInputToken.balance}
@@ -1057,7 +1074,10 @@ export const BaseSwitchModalContent = ({
10571074
slippageValidation?.severity === ValidationSeverity.ERROR ||
10581075
isSwappingSafetyModuleToken ||
10591076
(requireConfirmation && !highPriceImpactConfirmed) ||
1060-
(shouldUseFlashloan === true && !!poolReserve && !poolReserve.flashLoanEnabled)
1077+
(shouldUseFlashloan === true &&
1078+
!!poolReserve &&
1079+
!poolReserve.flashLoanEnabled) ||
1080+
(modalType === ModalType.CollateralSwap && isHFLow)
10611081
}
10621082
chainId={selectedChainId}
10631083
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)