Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vkulinich-cl committed Dec 30, 2024
1 parent d3c2653 commit e98b663
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import SettingsIcon from "assets/icons/SettingsIcon.svg?react"
import { Icon } from "components/Icon/Icon"
import { useAppDataContext } from "sections/lending/hooks/app-data-provider/useAppDataProvider"
import { getEmodeMessage } from "./EmodeNaming"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"

export const EmodeButton = () => {
const { openEmode } = useModalContext()
const { account } = useAccount()
const { user, eModes } = useAppDataContext()

const isEModeDisabled = user.userEmodeCategoryId === 0
Expand All @@ -28,6 +30,7 @@ export const EmodeButton = () => {
</Text>
<Button
size="micro"
disabled={!account || account.isExternalWalletConnected}
onClick={() =>
openEmode(
isEModeDisabled ? EmodeModalType.ENABLE : EmodeModalType.SWITCH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { Switch } from "components/Switch/Switch"
export enum ErrorType {
EMODE_DISABLED_LIQUIDATION,
CLOSE_POSITIONS_BEFORE_SWITCHING,
CLOSE_POSITIONS_BEFORE_DISABLING,
}

export enum EmodeModalType {
Expand Down Expand Up @@ -117,7 +118,11 @@ export const EmodeModalContent = ({ mode }: EmodeModalContentProps) => {
userReserve.reserve.eModeCategoryId !== selectedEmode?.id,
)
if (hasIncompatiblePositions) {
blockingError = ErrorType.CLOSE_POSITIONS_BEFORE_SWITCHING
if (disableMode) {
blockingError = ErrorType.CLOSE_POSITIONS_BEFORE_DISABLING
} else {
blockingError = ErrorType.CLOSE_POSITIONS_BEFORE_SWITCHING
}
}
}
// render error messages
Expand All @@ -136,6 +141,20 @@ export const EmodeModalContent = ({ mode }: EmodeModalContentProps) => {
</Text>
</Alert>
)
case ErrorType.CLOSE_POSITIONS_BEFORE_DISABLING:
return (
<Alert variant="info" sx={{ mt: 12, align: "center" }}>
<Text>
<span>
To disable E-mode for the{" "}
{selectedEmode &&
getEmodeMessage(eModes[user.userEmodeCategoryId].label)}{" "}
category, all borrow positions within this category must be
closed.
</span>
</Text>
</Alert>
)
case ErrorType.EMODE_DISABLED_LIQUIDATION:
return (
<Alert variant="error" sx={{ mt: 12, align: "center" }}>
Expand Down Expand Up @@ -325,7 +344,8 @@ export const EmodeModalContent = ({ mode }: EmodeModalContentProps) => {
)}
</TxModalDetails>
)}
{blockingError === ErrorType.CLOSE_POSITIONS_BEFORE_SWITCHING && (
{(blockingError === ErrorType.CLOSE_POSITIONS_BEFORE_SWITCHING ||
blockingError === ErrorType.CLOSE_POSITIONS_BEFORE_DISABLING) && (
<Blocked />
)}
{txError && <GasEstimationError txError={txError} sx={{ mt: 12 }} />}
Expand Down

0 comments on commit e98b663

Please sign in to comment.