diff --git a/src/components/Modals/BorrowModal.tsx b/src/components/Modals/BorrowModal.tsx
index 3e95a768..f131c7b2 100644
--- a/src/components/Modals/BorrowModal.tsx
+++ b/src/components/Modals/BorrowModal.tsx
@@ -8,7 +8,7 @@ import Card from 'components/Card'
import DisplayCurrency from 'components/DisplayCurrency'
import Divider from 'components/Divider'
import { FormattedNumber } from 'components/FormattedNumber'
-import { ArrowRight } from 'components/Icons'
+import { ArrowRight, InfoCircle } from 'components/Icons'
import Modal from 'components/Modal'
import Switch from 'components/Switch'
import Text from 'components/Text'
@@ -28,6 +28,11 @@ import { formatPercent, formatValue } from 'utils/formatters'
import { BN } from 'utils/helpers'
import { getDebtAmountWithInterest } from 'utils/tokens'
+interface Props {
+ account: Account
+ modal: BorrowModal
+}
+
function getDebtAmount(modal: BorrowModal) {
return BN((modal.marketData as BorrowMarketTableData)?.debt ?? 0).toString()
}
@@ -37,9 +42,21 @@ function getAssetLogo(modal: BorrowModal) {
return
}
-interface Props {
- account: Account
- modal: BorrowModal
+function RepayNotAvailable(props: { asset: Asset }) {
+ return (
+
+
+
+
+ No funds for repay
+ {`Unfortunately you don't have any ${props.asset.symbol} in your Credit Account to repay the debt.`}
+
+
+
+ )
}
export default function BorrowModalController() {
@@ -69,11 +86,24 @@ function BorrowModal(props: Props) {
const { computeMaxBorrowAmount } = useHealthComputer(account)
const totalDebt = BN(getDebtAmount(modal))
+ const [depositBalance, lendBalance] = useMemo(
+ () => [
+ account.deposits.find(byDenom(asset.denom))?.amount ?? BN_ZERO,
+ account.lends.find(byDenom(asset.denom))?.amount ?? BN_ZERO,
+ ],
+ [account, asset.denom],
+ )
+
const totalDebtRepayAmount = useMemo(
() => getDebtAmountWithInterest(totalDebt, Number(apr)),
[totalDebt, apr],
)
+ const maxRepayAmount = useMemo(() => {
+ const maxBalance = depositBalance.plus(lendBalance)
+ return isRepay ? BigNumber.min(maxBalance, totalDebtRepayAmount) : BN_ZERO
+ }, [depositBalance, lendBalance, isRepay, totalDebtRepayAmount])
+
function resetState() {
setAmount(BN_ZERO)
}
@@ -131,26 +161,20 @@ function BorrowModal(props: Props) {
useEffect(() => {
if (!account || isRepay) return
- if (maxBorrow !== max) setMax(maxBorrow)
+ if (maxBorrow.isEqualTo(max)) return
+ setMax(maxBorrow)
}, [account, isRepay, maxBorrow, max])
useEffect(() => {
- if (!account) return
- if (isRepay) {
- const depositBalance = account.deposits.find(byDenom(asset.denom))?.amount ?? BN_ZERO
- const lendBalance = account.lends.find(byDenom(asset.denom))?.amount ?? BN_ZERO
- const maxBalance = depositBalance.plus(lendBalance)
- const maxRepayAmount = BigNumber.min(maxBalance, totalDebtRepayAmount)
- setMax(maxRepayAmount)
- return
- }
- }, [account, asset.denom, isRepay, totalDebtRepayAmount])
+ if (!isRepay) return
+ if (maxRepayAmount.isEqualTo(max)) return
+ setMax(maxRepayAmount)
+ }, [isRepay, max, maxRepayAmount])
useEffect(() => {
- if (amount.isGreaterThan(max)) {
- handleChange(max)
- setAmount(max)
- }
+ if (amount.isLessThanOrEqualTo(max)) return
+ handleChange(max)
+ setAmount(max)
}, [amount, max, handleChange])
useEffect(() => {
@@ -223,9 +247,11 @@ function BorrowModal(props: Props) {
onChange={handleChange}
amount={amount}
max={max}
+ disabled={max.isZero()}
className='w-full'
maxText='Max'
/>
+ {isRepay && maxRepayAmount.isZero() && }
{!isRepay && (
<>
diff --git a/src/components/Slider.tsx b/src/components/Slider.tsx
index c1cc675b..8b2208d3 100644
--- a/src/components/Slider.tsx
+++ b/src/components/Slider.tsx
@@ -128,32 +128,34 @@ export default function Slider(props: Props) {
disabled={props.disabled}
/>
-
-
setIsDragging(false)}
- position={{ x: (sliderRect.width / 100) * props.value, y: 0 }}
- >
-
-
- {(showTooltip || isDragging) && (
-
-
- {props.value.toFixed(0)}%
-
- )}
-
-
-
+ {!props.disabled && (
+
+
setIsDragging(false)}
+ position={{ x: (sliderRect.width / 100) * props.value, y: 0 }}
+ >
+
+
+ {(showTooltip || isDragging) && (
+
+
+ {props.value.toFixed(0)}%
+
+ )}
+
+
+
+ )}
)
}
@@ -170,7 +172,9 @@ function Mark(props: MarkProps) {