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
7 changes: 5 additions & 2 deletions src/components/transactions/Borrow/BorrowModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import { useModalContext } from 'src/hooks/useModal';
import { ERC20TokenType } from 'src/libs/web3-data-provider/Web3Provider';
import { useRootStore } from 'src/store/root';
import { GENERAL } from 'src/utils/events';
import { getMaxAmountAvailableToBorrow } from 'src/utils/getMaxAmountAvailableToBorrow';
import {
assetCanBeBorrowedByUser,
getMaxAmountAvailableToBorrow,
} from 'src/utils/getMaxAmountAvailableToBorrow';
import { roundToTokenDecimals } from 'src/utils/utils';

import { CapType } from '../../caps/helper';
Expand Down Expand Up @@ -100,7 +103,7 @@ export const BorrowModalContent = ({
let blockingError: ErrorType | undefined = undefined;
if (valueToBigNumber(amount).gt(poolReserve.formattedAvailableLiquidity)) {
blockingError = ErrorType.NOT_ENOUGH_LIQUIDITY;
} else if (!poolReserve.borrowingEnabled) {
} else if (!assetCanBeBorrowedByUser(poolReserve, user)) {
blockingError = ErrorType.BORROWING_NOT_AVAILABLE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const BorrowAssetsList = () => {
totalBorrows: reserve.totalDebt,
availableBorrows,
availableBorrowsInUSD,
variableBorrowRate: reserve.borrowingEnabled ? Number(reserve.variableBorrowAPY) : -1,
variableBorrowRate: Number(reserve.variableBorrowAPY),
iconSymbol: reserve.iconSymbol,
...(reserve.isWrappedBaseAsset
? fetchIconSymbolAndName({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { Trans } from '@lingui/macro';
import { Box, Button, useMediaQuery, useTheme } from '@mui/material';
import { IncentivesCard } from 'src/components/incentives/IncentivesCard';
import { Row } from 'src/components/primitives/Row';
import { useAppDataContext } from 'src/hooks/app-data-provider/useAppDataProvider';
import { useAssetCaps } from 'src/hooks/useAssetCaps';
import { useModalContext } from 'src/hooks/useModal';
import { useRootStore } from 'src/store/root';
import { DashboardReserve } from 'src/utils/dashboardSortUtils';
import { assetCanBeBorrowedByUser } from 'src/utils/getMaxAmountAvailableToBorrow';
import { displayGhoForMintableMarket } from 'src/utils/ghoUtilities';
import { isFeatureEnabled } from 'src/utils/marketsAndNetworksConfig';
import { showExternalIncentivesTooltip } from 'src/utils/utils';
Expand Down Expand Up @@ -36,15 +38,11 @@ export const BorrowedPositionsListItem = ({
const theme = useTheme();
const downToXSM = useMediaQuery(theme.breakpoints.down('xsm'));
const { openBorrow, openRepay, openDebtSwitch } = useModalContext();
const { user } = useAppDataContext();

const reserve = item.reserve;

const disableBorrow =
!reserve.isActive ||
!reserve.borrowingEnabled ||
reserve.isFrozen ||
reserve.isPaused ||
borrowCap.isMaxed;
const disableBorrow = !assetCanBeBorrowedByUser(reserve, user) || borrowCap.isMaxed;

const disableRepay = !reserve.isActive || reserve.isPaused;

Expand Down
1 change: 1 addition & 0 deletions src/modules/markets/MarketAssetsListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export const MarketAssetsListItem = ({ ...reserve }: ReserveWithProtocolIncentiv
/>
{reserve.borrowInfo?.borrowingState === 'DISABLED' &&
!reserve.isFrozen &&
!reserve.eModeInfo?.some((eMode) => eMode.canBeBorrowed) &&
reserve.borrowInfo.total.amount.value !== '0' && <ReserveSubheader value={'Disabled'} />}
</ListColumn>

Expand Down
1 change: 1 addition & 0 deletions src/modules/markets/MarketAssetsListMobileItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const MarketAssetsListMobileItem = ({ ...reserve }: ReserveWithProtocolIn
/>
{reserve.borrowInfo?.borrowingState === 'DISABLED' &&
!reserve.isFrozen &&
!reserve.eModeInfo?.some((eMode) => eMode.canBeBorrowed) &&
reserve.borrowInfo.total.amount.value !== '0' && <ReserveSubheader value={'Disabled'} />}
</Row>
<Button
Expand Down
7 changes: 5 additions & 2 deletions src/modules/reserve-overview/ReserveActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { BuyWithFiat } from 'src/modules/staking/BuyWithFiat';
import { useRootStore } from 'src/store/root';
import { GENERAL } from 'src/utils/events';
import { getMaxAmountAvailableToBorrow } from 'src/utils/getMaxAmountAvailableToBorrow';
import {
assetCanBeBorrowedByUser,
getMaxAmountAvailableToBorrow,
} from 'src/utils/getMaxAmountAvailableToBorrow';
import { getMaxAmountAvailableToSupply } from 'src/utils/getMaxAmountAvailableToSupply';
import { amountToUsd } from 'src/utils/utils';
import { useShallow } from 'zustand/shallow';
Expand Down Expand Up @@ -150,7 +153,7 @@ export const ReserveActions = ({ reserve }: ReserveActionsProps) => {
disable={disableSupplyButton}
onActionClicked={onSupplyClicked}
/>
{reserve.borrowingEnabled && (
{assetCanBeBorrowedByUser(reserve, user) && (
<BorrowAction
reserve={reserve}
value={maxAmountToBorrow.toString()}
Expand Down
23 changes: 13 additions & 10 deletions src/modules/reserve-overview/ReserveConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,22 @@ export const ReserveConfiguration: React.FC<ReserveConfigurationProps> = ({ rese
</PanelRow>

{(reserve.borrowInfo?.borrowingState === 'ENABLED' ||
Number(reserve.borrowInfo?.total.amount.value) > 0) && (
Number(reserve.borrowInfo?.total.amount.value) > 0 ||
reserve.eModeInfo?.some((eMode) => eMode.canBeBorrowed)) && (
<>
<Divider sx={{ my: { xs: 6, sm: 10 } }} />
<PanelRow>
<PanelTitle>Borrow info</PanelTitle>
<Box sx={{ flexGrow: 1, minWidth: 0, maxWidth: '100%', width: '100%' }}>
{reserve.borrowInfo?.borrowingState === 'DISABLED' && (
<Warning sx={{ mb: '40px' }} severity="error">
<BorrowDisabledWarning
symbol={reserve.underlyingToken.symbol}
currentMarket={currentMarket}
/>
</Warning>
)}
{reserve.borrowInfo?.borrowingState !== 'ENABLED' &&
!reserve.eModeInfo?.some((eMode) => eMode.canBeBorrowed) && (
<Warning sx={{ mb: '40px' }} severity="error">
<BorrowDisabledWarning
symbol={reserve.underlyingToken.symbol}
currentMarket={currentMarket}
/>
</Warning>
)}
<BorrowInfo
reserve={reserve}
currentMarketData={currentMarketData}
Expand All @@ -160,7 +162,8 @@ export const ReserveConfiguration: React.FC<ReserveConfigurationProps> = ({ rese
)}

{(reserve.borrowInfo?.borrowingState === 'ENABLED' ||
Number(reserve.borrowInfo?.total.amount.value) > 0) && (
Number(reserve.borrowInfo?.total.amount.value) > 0 ||
reserve.eModeInfo?.some((eMode) => eMode.canBeBorrowed)) && (
<>
<Divider sx={{ my: { xs: 6, sm: 10 } }} />

Expand Down
5 changes: 3 additions & 2 deletions src/modules/reserve-overview/SupplyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ export const SupplyInfo = ({
</Box>
{renderCharts &&
(reserve.borrowInfo?.borrowingState === 'ENABLED' ||
Number(reserve.borrowInfo?.total.amount.value) > 0) && (
Number(reserve.borrowInfo?.total.amount.value) > 0 ||
reserve.eModeInfo?.some((eMode) => eMode.canBeBorrowed)) && (
<SupplyApyGraph
chain={currentMarketData.chainId}
underlyingToken={reserve.underlyingToken.address}
Expand Down Expand Up @@ -209,7 +210,7 @@ export const SupplyInfo = ({
<Trans>Can be collateral</Trans>
</Typography>
</Box>
) : (
) : reserve.eModeInfo?.some((eMode) => eMode.canBeCollateral) ? null : (
<Box sx={{ pt: '42px', pb: '12px' }}>
<Typography variant="subheader1" color="text.main">
<Trans>Collateral usage</Trans>
Expand Down
6 changes: 4 additions & 2 deletions src/modules/reserve-overview/TokenLinkDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export const TokenLinkDropdown = ({

const showVariableDebtToken =
!hideVariableDebtToken &&
(poolReserve.borrowInfo?.borrowingState === 'ENABLED' ||
Number(poolReserve.borrowInfo?.total.amount.value) > 0);
!!poolReserve.borrowInfo &&
(poolReserve.borrowInfo.borrowingState !== 'DISABLED' ||
Number(poolReserve.borrowInfo.total.amount.value) > 0 ||
!!poolReserve.eModeInfo?.some((eMode) => eMode.canBeBorrowed));

return (
<>
Expand Down
6 changes: 3 additions & 3 deletions src/utils/getMaxAmountAvailableToBorrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ export function assetCanBeBorrowedByUser(
isFrozen,
isPaused,
}: ComputedReserveData,
user: ExtendedFormattedUser
user?: ExtendedFormattedUser
) {
if (!borrowingEnabled || !isActive || isFrozen || isPaused) return false;
if (!isActive || isFrozen || isPaused) return false;
if (user?.isInEmode) {
const reserveEmode = eModes.find((emode) => emode.id === user.userEmodeCategoryId);
if (!reserveEmode) return false;
return reserveEmode.borrowingEnabled;
}
if (user?.isInIsolationMode && !borrowableInIsolation) return false;
return true;
return borrowingEnabled;
}
Loading