@@ -38,6 +38,7 @@ import { useModalContext } from 'src/hooks/useModal';
38
38
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context' ;
39
39
import { useRootStore } from 'src/store/root' ;
40
40
import { getNetworkConfig } from 'src/utils/marketsAndNetworksConfig' ;
41
+ import { useShallow } from 'zustand/shallow' ;
41
42
42
43
import { TxErrorView } from '../FlowCommons/Error' ;
43
44
import { GasEstimationError } from '../FlowCommons/GasEstimationError' ;
@@ -79,7 +80,9 @@ export const EmodeModalContent = ({ user }: { user: ExtendedFormattedUser }) =>
79
80
marketReferencePriceInUsd,
80
81
userReserves,
81
82
} = useAppDataContext ( ) ;
82
- const currentChainId = useRootStore ( ( store ) => store . currentChainId ) ;
83
+ const [ currentChainId , currentMarket ] = useRootStore (
84
+ useShallow ( ( store ) => [ store . currentChainId , store . currentMarket ] )
85
+ ) ;
83
86
const { chainId : connectedChainId , readOnlyModeAddress } = useWeb3Context ( ) ;
84
87
const currentTimestamp = useCurrentTimestamp ( 1 ) ;
85
88
const { gasLimit, mainTxState : emodeTxState , txError } = useModalContext ( ) ;
@@ -95,8 +98,33 @@ export const EmodeModalContent = ({ user }: { user: ExtendedFormattedUser }) =>
95
98
] )
96
99
) ;
97
100
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
+
98
126
const [ selectedEmode , setSelectedEmode ] = useState < EModeCategoryDisplay > (
99
- user . userEmodeCategoryId === 0 ? eModeCategories [ 1 ] : eModeCategories [ user . userEmodeCategoryId ]
127
+ getDefaultEModeCategory ( )
100
128
) ;
101
129
const networkConfig = getNetworkConfig ( currentChainId ) ;
102
130
@@ -296,7 +324,7 @@ export const EmodeModalContent = ({ user }: { user: ExtendedFormattedUser }) =>
296
324
onChange = { ( e ) => selectEMode ( Number ( e . target . value ) ) }
297
325
>
298
326
{ Object . values ( eModeCategories )
299
- . filter ( ( emode ) => emode . id !== 0 )
327
+ . filter ( ( emode ) => emode . id !== 0 && emode . label !== 'USYC GHO' )
300
328
. sort ( ( a , b ) => {
301
329
if ( a . available !== b . available ) {
302
330
return a . available ? - 1 : 1 ;
0 commit comments