@@ -38,6 +38,7 @@ import { useModalContext } from 'src/hooks/useModal';
3838import { useWeb3Context } from 'src/libs/hooks/useWeb3Context' ;
3939import { useRootStore } from 'src/store/root' ;
4040import { getNetworkConfig } from 'src/utils/marketsAndNetworksConfig' ;
41+ import { useShallow } from 'zustand/shallow' ;
4142
4243import { TxErrorView } from '../FlowCommons/Error' ;
4344import { 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