Skip to content

Commit

Permalink
Feat/emode debt switch (#2161)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaquinBattilana authored Aug 20, 2024
1 parent 4df494a commit b94aa39
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const head = [
];

export const BorrowedPositionsList = () => {
const { user, loading, eModes } = useAppDataContext();
const { user, loading, eModes, reserves } = useAppDataContext();
const { currentMarketData, currentNetworkConfig } = useProtocolDataContext();
const [sortName, setSortName] = useState('');
const [sortDesc, setSortDesc] = useState(false);
Expand All @@ -70,6 +70,9 @@ export const BorrowedPositionsList = () => {
const showEModeButton = currentMarketData.v3 && Object.keys(eModes).length > 1;
const [tooltipOpen, setTooltipOpen] = useState<boolean>(false);

if (loading || !user)
return <ListLoader title={<Trans>Your borrows</Trans>} head={head.map((c) => c.title)} />;

let borrowPositions =
user?.userReservesData.reduce((acc, userReserve) => {
if (userReserve.variableBorrows !== '0') {
Expand Down Expand Up @@ -131,6 +134,12 @@ export const BorrowedPositionsList = () => {
true
);

const disableEModeSwitch =
user.isInEmode &&
reserves.filter(
(reserve) => reserve.eModeCategoryId === user.userEmodeCategoryId && reserve.borrowingEnabled
).length < 2;

const RenderHeader: React.FC = () => {
return (
<ListHeaderWrapper>
Expand All @@ -157,9 +166,6 @@ export const BorrowedPositionsList = () => {
);
};

if (loading)
return <ListLoader title={<Trans>Your borrows</Trans>} head={head.map((c) => c.title)} />;

return (
<ListWrapper
tooltipOpen={tooltipOpen}
Expand Down Expand Up @@ -220,6 +226,7 @@ export const BorrowedPositionsList = () => {
<BorrowedPositionsListItemWrapper
item={item}
key={item.underlyingAsset + item.borrowRateMode}
disableEModeSwitch={disableEModeSwitch}
/>
))}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ import { ListItemWrapper } from '../ListItemWrapper';
import { ListMobileItemWrapper } from '../ListMobileItemWrapper';
import { ListValueColumn } from '../ListValueColumn';
import { ListValueRow } from '../ListValueRow';
import { BorrowedPositionsListItemWrapperProps } from './BorrowedPositionsListItemWrapper';

export const BorrowedPositionsListItem = ({ item }: { item: DashboardReserve }) => {
export const BorrowedPositionsListItem = ({
item,
disableEModeSwitch,
}: BorrowedPositionsListItemWrapperProps) => {
const { borrowCap } = useAssetCaps();
const { currentMarket, currentMarketData } = useProtocolDataContext();
const theme = useTheme();
Expand All @@ -40,7 +44,8 @@ export const BorrowedPositionsListItem = ({ item }: { item: DashboardReserve })
const disableRepay = !reserve.isActive || reserve.isPaused;

const showSwitchButton = !!isFeatureEnabled.debtSwitch(currentMarketData);
const disableSwitch = reserve.isPaused || !reserve.isActive || reserve.symbol == 'stETH';
const disableSwitch =
reserve.isPaused || !reserve.isActive || reserve.symbol == 'stETH' || disableEModeSwitch;

const props: BorrowedPositionsListItemProps = {
...item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ import { displayGhoForMintableMarket } from 'src/utils/ghoUtilities';
import { BorrowedPositionsListItem } from './BorrowedPositionsListItem';
import { GhoBorrowedPositionsListItem } from './GhoBorrowedPositionsListItem';

export const BorrowedPositionsListItemWrapper = ({ item }: { item: DashboardReserve }) => {
export interface BorrowedPositionsListItemWrapperProps {
item: DashboardReserve;
disableEModeSwitch: boolean;
}

export const BorrowedPositionsListItemWrapper = ({
item,
disableEModeSwitch,
}: BorrowedPositionsListItemWrapperProps) => {
const { currentMarket } = useProtocolDataContext();

return (
<AssetCapsProvider asset={item.reserve}>
{displayGhoForMintableMarket({ symbol: item.reserve.symbol, currentMarket }) ? (
<GhoBorrowedPositionsListItem {...item} />
) : (
<BorrowedPositionsListItem item={item} />
<BorrowedPositionsListItem item={item} disableEModeSwitch={disableEModeSwitch} />
)}
</AssetCapsProvider>
);
Expand Down

2 comments on commit b94aa39

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

Please sign in to comment.