@@ -5,7 +5,10 @@ import config from 'config';
55import { useTranslation } from 'libs/translations' ;
66import { chains , useChainId , useSwitchChain } from 'libs/wallet' ;
77import type { ChainId } from 'types' ;
8+ import { isSunsetChain } from 'utilities/isSunsetChain' ;
89import { GaslessStatus } from './GaslessStatus' ;
10+ import { SunsetIndicator , SunsetModal } from './SunsetIndicator' ;
11+ import { useSunsetModalStore } from './sunsetModalStore' ;
912
1013export interface ChainSelectProps
1114 extends Omit < SelectProps , 'value' | 'onChange' | 'options' | 'optionClassName' > {
@@ -16,37 +19,56 @@ export const ChainSelect: React.FC<ChainSelectProps> = props => {
1619 const { t } = useTranslation ( ) ;
1720 const { chainId } = useChainId ( ) ;
1821 const { switchChain } = useSwitchChain ( ) ;
22+ const openSunsetModal = useSunsetModalStore ( state => state . open ) ;
23+
24+ const handleChange = ( newChainId : ChainId | string | number ) => {
25+ const id = Number ( newChainId ) as ChainId ;
26+ if ( isSunsetChain ( id ) && id !== chainId ) {
27+ openSunsetModal ( ) ;
28+ }
29+ switchChain ( { chainId : id } ) ;
30+ } ;
1931
2032 const options = chains . map < SelectOption < ChainId > > ( chain => ( {
2133 label : ( { isRenderedInButton } ) => {
22- const metadata = chainMetadata [ chain . id as ChainId ] ;
34+ const optionChainId = chain . id as ChainId ;
35+ const metadata = chainMetadata [ optionChainId ] ;
36+ const showSunsetIndicator = isSunsetChain ( optionChainId ) ;
37+ const isActiveChain = optionChainId === chainId ;
38+
2339 return (
2440 < div className = "flex items-center" >
2541 < img src = { metadata . iconSrc } alt = { metadata . name } className = "w-6 max-w-none flex-none" />
2642
2743 { ! isRenderedInButton && (
28- < span className = { cn ( 'flex ml-2 grow items-center gap-x-1' ) } >
44+ < span className = { cn ( 'flex ml-2 items-center gap-x-1' ) } >
2945 < span > { metadata . name } </ span >
3046
31- < GaslessStatus chainId = { chain . id } displayLabel />
47+ < GaslessStatus chainId = { optionChainId } displayLabel />
3248 </ span >
3349 ) }
50+
51+ { showSunsetIndicator && < SunsetIndicator className = "ml-2" interactive = { ! isActiveChain } /> }
3452 </ div >
3553 ) ;
3654 } ,
3755 value : chain . id ,
3856 } ) ) ;
3957
4058 return (
41- < Select
42- // When running in Safe Wallet app, it is responsible for the active chain
43- disabled = { config . isSafeApp }
44- value = { chainId }
45- onChange = { newChainId => switchChain ( { chainId : Number ( newChainId ) } ) }
46- options = { options }
47- menuPosition = "right"
48- menuTitle = { t ( 'layout.chainSelect.label' ) }
49- { ...props }
50- />
59+ < >
60+ < Select
61+ // When running in Safe Wallet app, it is responsible for the active chain
62+ disabled = { config . isSafeApp }
63+ value = { chainId }
64+ onChange = { handleChange }
65+ options = { options }
66+ menuPosition = "right"
67+ menuTitle = { t ( 'layout.chainSelect.label' ) }
68+ { ...props }
69+ />
70+
71+ < SunsetModal />
72+ </ >
5173 ) ;
5274} ;
0 commit comments