Skip to content

Commit f909932

Browse files
foodakamgrabina
andauthored
WIP: feat: horizon market (#2493)
Co-authored-by: Martin Grabina <[email protected]>
1 parent 1f0b8d5 commit f909932

File tree

19 files changed

+221
-117
lines changed

19 files changed

+221
-117
lines changed

public/icons/markets/horizon.svg

Lines changed: 1 addition & 0 deletions
Loading

public/icons/other/velora.svg

Lines changed: 1 addition & 12 deletions
Loading

public/icons/tokens/buidl.svg

Lines changed: 1 addition & 0 deletions
Loading

public/icons/tokens/jaaa.svg

Lines changed: 1 addition & 0 deletions
Loading

public/icons/tokens/jtrsy.svg

Lines changed: 1 addition & 0 deletions
Loading

public/icons/tokens/uscc.svg

Lines changed: 1 addition & 0 deletions
Loading

public/icons/tokens/ustb.svg

Lines changed: 1 addition & 0 deletions
Loading

public/icons/tokens/usyc.svg

Lines changed: 1 addition & 0 deletions
Loading

src/components/transactions/Emode/EmodeModalContent.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { useModalContext } from 'src/hooks/useModal';
3838
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
3939
import { useRootStore } from 'src/store/root';
4040
import { getNetworkConfig } from 'src/utils/marketsAndNetworksConfig';
41+
import { useShallow } from 'zustand/shallow';
4142

4243
import { TxErrorView } from '../FlowCommons/Error';
4344
import { GasEstimationError } from '../FlowCommons/GasEstimationError';
@@ -79,7 +80,9 @@ export const EmodeModalContent = ({ user }: { user: ExtendedFormattedUser }) =>
7980
marketReferencePriceInUsd,
8081
userReserves,
8182
} = useAppDataContext();
82-
const currentChainId = useRootStore((store) => store.currentChainId);
83+
const [currentChainId, currentMarket] = useRootStore(
84+
useShallow((store) => [store.currentChainId, store.currentMarket])
85+
);
8386
const { chainId: connectedChainId, readOnlyModeAddress } = useWeb3Context();
8487
const currentTimestamp = useCurrentTimestamp(1);
8588
const { gasLimit, mainTxState: emodeTxState, txError } = useModalContext();
@@ -95,8 +98,33 @@ export const EmodeModalContent = ({ user }: { user: ExtendedFormattedUser }) =>
9598
])
9699
);
97100

101+
// For Horizon markets, use the next available category after [1]
102+
// For all other markets, use eModeCategories[1] (eth correlanted) as default when user has no eMode enabled (userEmodeCategoryId === 0)
103+
const getDefaultEModeCategory = () => {
104+
if (user.userEmodeCategoryId !== 0) {
105+
return eModeCategories[user.userEmodeCategoryId];
106+
}
107+
108+
const isHorizonMarket =
109+
currentMarket.includes('proto_horizon_v3') ||
110+
currentMarket.includes('fork_proto_horizon_v3') ||
111+
currentMarket.includes('proto_sepolia_horizon_v3');
112+
113+
if (isHorizonMarket) {
114+
// Find the next available category after [1], excluding USYC GHO
115+
// TODO: Add USYC when its available
116+
const availableCategories = Object.values(eModeCategories)
117+
.filter((emode) => emode.id !== 0 && emode.id !== 1 && emode.label !== 'USYC GHO')
118+
.sort((a, b) => a.id - b.id);
119+
120+
return availableCategories.length > 0 ? availableCategories[0] : eModeCategories[1];
121+
}
122+
123+
return eModeCategories[1];
124+
};
125+
98126
const [selectedEmode, setSelectedEmode] = useState<EModeCategoryDisplay>(
99-
user.userEmodeCategoryId === 0 ? eModeCategories[1] : eModeCategories[user.userEmodeCategoryId]
127+
getDefaultEModeCategory()
100128
);
101129
const networkConfig = getNetworkConfig(currentChainId);
102130

@@ -296,7 +324,7 @@ export const EmodeModalContent = ({ user }: { user: ExtendedFormattedUser }) =>
296324
onChange={(e) => selectEMode(Number(e.target.value))}
297325
>
298326
{Object.values(eModeCategories)
299-
.filter((emode) => emode.id !== 0)
327+
.filter((emode) => emode.id !== 0 && emode.label !== 'USYC GHO')
300328
.sort((a, b) => {
301329
if (a.available !== b.available) {
302330
return a.available ? -1 : 1;

0 commit comments

Comments
 (0)