@@ -76,6 +76,7 @@ export interface SidebarContainerProps {
76
76
connectedNetwork ?: number | string
77
77
supportedNetworks ?: readonly ( ChainId | NonStandardChainId ) [ ]
78
78
unsupportedNetworkHref ?: string
79
+ onSelect ?: ( ( network : ChainId | NonStandardChainId ) => void ) | null
79
80
}
80
81
81
82
export const SidebarContainer : FC < SidebarContainerProps > = ( {
@@ -85,6 +86,7 @@ export const SidebarContainer: FC<SidebarContainerProps> = ({
85
86
connectedNetwork,
86
87
supportedNetworks,
87
88
unsupportedNetworkHref,
89
+ onSelect,
88
90
} ) => {
89
91
const { isOpen } = useSidebar ( )
90
92
@@ -94,6 +96,7 @@ export const SidebarContainer: FC<SidebarContainerProps> = ({
94
96
selectedNetwork = { selectedNetwork }
95
97
connectedNetwork = { connectedNetwork }
96
98
supportedNetworks = { supportedNetworks }
99
+ onSelect = { onSelect }
97
100
unsupportedNetworkHref = { unsupportedNetworkHref }
98
101
/>
99
102
< div
@@ -113,6 +116,7 @@ const Sidebar: FC<Omit<SidebarContainerProps, 'children' | 'shiftContent'>> = ({
113
116
connectedNetwork,
114
117
supportedNetworks = SUPPORTED_NETWORKS ,
115
118
unsupportedNetworkHref,
119
+ onSelect : _onSelect ,
116
120
} ) => {
117
121
const { isOpen } = useSidebar ( )
118
122
@@ -127,19 +131,18 @@ const Sidebar: FC<Omit<SidebarContainerProps, 'children' | 'shiftContent'>> = ({
127
131
128
132
const onSelect = useCallback (
129
133
( value : string ) => {
130
- const network = value . split ( '__' ) [ 1 ]
131
-
132
- push (
133
- replaceNetworkSlug (
134
- isChainId ( + network )
135
- ? ( + network as ChainId )
136
- : ( network as NonStandardChainId ) ,
137
- pathname ,
138
- ) ,
139
- { scroll : false } ,
140
- )
134
+ const _network = value . split ( '__' ) [ 1 ]
135
+
136
+ const network = isChainId ( + _network )
137
+ ? ( + _network as ChainId )
138
+ : ( _network as NonStandardChainId )
139
+
140
+ if ( _onSelect === null ) return
141
+ if ( typeof _onSelect === 'function' ) return _onSelect ( network )
142
+
143
+ push ( replaceNetworkSlug ( network , pathname ) , { scroll : false } )
141
144
} ,
142
- [ pathname , push ] ,
145
+ [ pathname , push , _onSelect ] ,
143
146
)
144
147
145
148
return ! isOpen ? null : (
0 commit comments