Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
grothem committed Oct 26, 2024
1 parent 5df47e1 commit 8f099f6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 121 deletions.
6 changes: 3 additions & 3 deletions src/components/transactions/Emode/EmodeModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Link } from 'src/components/primitives/Link';
import { Row } from 'src/components/primitives/Row';
import { TokenIcon } from 'src/components/primitives/TokenIcon';
import { Warning } from 'src/components/primitives/Warning';
import { EmodeCategory } from 'src/helpers/types';
import {
ExtendedFormattedUser,
useAppDataContext,
Expand All @@ -36,7 +37,6 @@ import { useCurrentTimestamp } from 'src/hooks/useCurrentTimestamp';
import { useModalContext } from 'src/hooks/useModal';
import { useProtocolDataContext } from 'src/hooks/useProtocolDataContext';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { NewEModeCategory } from 'src/store/poolSelectors';
import { getNetworkConfig } from 'src/utils/marketsAndNetworksConfig';

import { TxErrorView } from '../FlowCommons/Error';
Expand All @@ -52,12 +52,12 @@ export enum ErrorType {
CLOSE_POSITIONS_BEFORE_SWITCHING,
}

export type EModeCategoryDisplay = NewEModeCategory & {
export type EModeCategoryDisplay = EmodeCategory & {
available: boolean; // indicates if the user can enter this category
};

// An E-Mode category is available if the user has no borrow positions outside of the category
function isEModeCategoryAvailable(user: ExtendedFormattedUser, eMode: NewEModeCategory): boolean {
function isEModeCategoryAvailable(user: ExtendedFormattedUser, eMode: EmodeCategory): boolean {
const borrowableReserves = eMode.assets
.filter((asset) => asset.borrowable)
.map((asset) => asset.underlyingAsset);
Expand Down
95 changes: 0 additions & 95 deletions src/components/transactions/Emode/EmodeSelect.tsx

This file was deleted.

14 changes: 9 additions & 5 deletions src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ export type Reward = {

export type EmodeCategory = {
id: number;
ltv: number;
liquidationThreshold: number;
liquidationBonus: number;
priceSource: string;
label: string;
assets: string[];
ltv: string;
liquidationThreshold: string;
liquidationBonus: string;
assets: Array<{
underlyingAsset: string;
symbol: string;
collateral: boolean;
borrowable: boolean;
}>;
};

export enum CollateralType {
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/app-data-provider/useAppDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import {
} from '@aave/math-utils';
import { formatUnits } from 'ethers/lib/utils';
import React, { useContext } from 'react';
import { EmodeCategory } from 'src/helpers/types';
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
import { useRootStore } from 'src/store/root';
import { GHO_MINTING_MARKETS } from 'src/utils/ghoUtilities';

import { formatEmodes, NewEModeCategory } from '../../store/poolSelectors';
import { formatEmodes } from '../../store/poolSelectors';
import {
ExtendedFormattedUser as _ExtendedFormattedUser,
useExtendedUserSummaryAndIncentives,
Expand Down Expand Up @@ -53,7 +54,7 @@ export type ExtendedFormattedUser = _ExtendedFormattedUser;
export interface AppDataContextType {
loading: boolean;
reserves: ComputedReserveData[];
eModes: Record<number, NewEModeCategory>;
eModes: Record<number, EmodeCategory>;
user?: ExtendedFormattedUser;
marketReferencePriceInUsd: string;
marketReferenceCurrencyDecimals: number;
Expand Down
18 changes: 2 additions & 16 deletions src/store/poolSelectors.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { EmodeCategory } from 'src/helpers/types';
import { FormattedReservesAndIncentives } from 'src/hooks/pool/usePoolFormattedReserves';
import { CustomMarket, marketsData, NetworkConfig } from 'src/utils/marketsAndNetworksConfig';

import { PoolReserve } from './poolSlice';

// TODO: refactor existing utils type EmodeCategory
export type NewEModeCategory = {
id: number;
label: string;
ltv: string;
liquidationThreshold: string;
liquidationBonus: string;
assets: Array<{
underlyingAsset: string;
symbol: string;
collateral: boolean;
borrowable: boolean;
}>;
};

export const selectCurrentChainIdMarkets = (
chainId: number,
currentNetworkConfig: NetworkConfig
Expand Down Expand Up @@ -65,7 +51,7 @@ export const reserveSortFn = (
};

export const formatEmodes = (reserves: FormattedReservesAndIncentives[]) => {
const eModes: Record<number, NewEModeCategory> = {};
const eModes: Record<number, EmodeCategory> = {};

reserves.forEach((r) => {
r.eModes.forEach((e) => {
Expand Down

0 comments on commit 8f099f6

Please sign in to comment.