@@ -6,60 +6,113 @@ import Box from '@mui/material/Box';
66import Button from '@mui/material/Button' ;
77import Toolbar from '@mui/material/Toolbar' ;
88import Typography from '@mui/material/Typography' ;
9+ import { useRouter } from 'next/router' ;
910import { ReactNode , useEffect , useState } from 'react' ;
1011import { MarketLogo } from 'src/components/MarketSwitcher' ;
1112import { Link } from 'src/components/primitives/Link' ;
1213import { useRootStore } from 'src/store/root' ;
1314
14- interface TopBarNotifyProps {
15+ export type ButtonAction =
16+ | { type : 'url' ; value : string ; target ?: '_blank' | '_self' }
17+ | { type : 'function' ; value : ( ) => void }
18+ | { type : 'route' ; value : string }
19+ | { type : 'modal' ; value : string ; params ?: Record < string , unknown > } ;
20+
21+ interface CampaignConfig {
1522 notifyText : ReactNode ;
1623 learnMoreLink ?: string | ( ( ) => void ) ;
1724 buttonText ?: string ;
25+ buttonAction ?: ButtonAction ;
1826 bannerVersion : string ;
1927 icon ?: string ;
2028 customIcon ?: ReactNode ;
2129}
2230
23- export default function TopBarNotify ( {
24- notifyText,
25- learnMoreLink,
26- buttonText,
27- bannerVersion,
28- icon,
29- customIcon,
30- } : TopBarNotifyProps ) {
31+ interface NetworkCampaigns {
32+ [ chainId : number ] : CampaignConfig ;
33+ }
34+
35+ interface TopBarNotifyProps {
36+ campaigns : NetworkCampaigns ;
37+ }
38+
39+ export default function TopBarNotify ( { campaigns } : TopBarNotifyProps ) {
3140 const { breakpoints } = useTheme ( ) ;
3241 const md = useMediaQuery ( breakpoints . down ( 'md' ) ) ;
3342 const sm = useMediaQuery ( breakpoints . down ( 'sm' ) ) ;
43+ const router = useRouter ( ) ;
44+
45+ const currentChainId = useRootStore ( ( store ) => store . currentChainId ) ;
46+ const mobileDrawerOpen = useRootStore ( ( state ) => state . mobileDrawerOpen ) ;
47+
48+ const getCurrentCampaign = ( ) : CampaignConfig | null => {
49+ return campaigns [ currentChainId ] || null ;
50+ } ;
51+
52+ const currentCampaign = getCurrentCampaign ( ) ;
3453
3554 const [ showWarning , setShowWarning ] = useState ( ( ) => {
36- const storedBannerVersion = localStorage . getItem ( 'bannerVersion' ) ;
37- const warningBarOpen = localStorage . getItem ( 'warningBarOpen' ) ;
55+ if ( ! currentCampaign ) return false ;
3856
39- if ( storedBannerVersion !== bannerVersion ) {
57+ const storedBannerVersion = localStorage . getItem ( `bannerVersion_${ currentChainId } ` ) ;
58+ const warningBarOpen = localStorage . getItem ( `warningBarOpen_${ currentChainId } ` ) ;
59+
60+ if ( storedBannerVersion !== currentCampaign . bannerVersion ) {
4061 return true ;
4162 }
4263
4364 return warningBarOpen !== 'false' ;
4465 } ) ;
4566
46- const mobileDrawerOpen = useRootStore ( ( state ) => state . mobileDrawerOpen ) ;
47-
4867 useEffect ( ( ) => {
49- const storedBannerVersion = localStorage . getItem ( 'bannerVersion' ) ;
68+ if ( ! currentCampaign ) return ;
5069
51- if ( storedBannerVersion !== bannerVersion ) {
52- localStorage . setItem ( 'bannerVersion' , bannerVersion ) ;
53- localStorage . setItem ( 'warningBarOpen' , 'true' ) ;
70+ const storedBannerVersion = localStorage . getItem ( `bannerVersion_${ currentChainId } ` ) ;
71+
72+ if ( storedBannerVersion !== currentCampaign . bannerVersion ) {
73+ localStorage . setItem ( `bannerVersion_${ currentChainId } ` , currentCampaign . bannerVersion ) ;
74+ localStorage . setItem ( `warningBarOpen_${ currentChainId } ` , 'true' ) ;
5475 setShowWarning ( true ) ;
5576 }
56- } , [ bannerVersion ] ) ;
77+ } , [ currentCampaign , currentChainId ] ) ;
78+
79+ // If no campaign is configured for the current network, don't show anything
80+ if ( ! currentCampaign ) {
81+ return null ;
82+ }
5783
5884 const handleClose = ( ) => {
59- localStorage . setItem ( 'warningBarOpen' , 'false' ) ;
85+ localStorage . setItem ( `warningBarOpen_ ${ currentChainId } ` , 'false' ) ;
6086 setShowWarning ( false ) ;
6187 } ;
6288
89+ const handleButtonAction = ( ) => {
90+ if ( ! currentCampaign . buttonAction ) return ;
91+
92+ switch ( currentCampaign . buttonAction . type ) {
93+ case 'url' :
94+ if ( currentCampaign . buttonAction . target === '_blank' ) {
95+ window . open ( currentCampaign . buttonAction . value , '_blank' ) ;
96+ } else {
97+ window . location . href = currentCampaign . buttonAction . value ;
98+ }
99+ break ;
100+ case 'function' :
101+ currentCampaign . buttonAction . value ( ) ;
102+ break ;
103+ case 'route' :
104+ router . push ( currentCampaign . buttonAction . value ) ;
105+ break ;
106+ // case 'modal':
107+ // console.log(
108+ // 'Modal action:',
109+ // currentCampaign.buttonAction.value,
110+ // currentCampaign.buttonAction.params
111+ // );
112+ break ;
113+ }
114+ } ;
115+
63116 // Note: hide warnings when mobile menu is open
64117 if ( mobileDrawerOpen ) return null ;
65118
@@ -92,20 +145,25 @@ export default function TopBarNotify({
92145 sx = { { display : 'flex' , alignContent : 'center' , alignItems : 'center' } }
93146 component = "div"
94147 >
95- < Trans > { notifyText } </ Trans >
148+ < Trans > { currentCampaign . notifyText } </ Trans >
96149
97- { customIcon ? customIcon : null }
150+ { currentCampaign . customIcon ? currentCampaign . customIcon : null }
98151
99- { icon && ! sm ? < MarketLogo sx = { { ml : 2 } } size = { 32 } logo = { icon } /> : '' }
152+ { currentCampaign . icon && ! sm ? (
153+ < MarketLogo sx = { { ml : 2 } } size = { 32 } logo = { currentCampaign . icon } />
154+ ) : (
155+ ''
156+ ) }
100157
101- { learnMoreLink && md ? (
102- typeof learnMoreLink === 'string' ? (
158+ { currentCampaign . learnMoreLink && md ? (
159+ typeof currentCampaign . learnMoreLink === 'string' ? (
103160 < Link
104161 sx = { { color : 'white' , textDecoration : 'underline' , paddingLeft : 2 } }
105- // target={'_blank'} Todo option to pass as prop
106- href = { learnMoreLink }
162+ href = { currentCampaign . learnMoreLink }
107163 >
108- < Trans > { buttonText ? buttonText : `Learn more` } </ Trans >
164+ < Trans >
165+ { currentCampaign . buttonText ? currentCampaign . buttonText : `Learn more` }
166+ </ Trans >
109167 </ Link >
110168 ) : (
111169 < Button
@@ -119,48 +177,32 @@ export default function TopBarNotify({
119177 padding : 0 ,
120178 marginLeft : 2 ,
121179 } }
122- onClick = { learnMoreLink }
180+ onClick = { currentCampaign . learnMoreLink }
123181 >
124- < Trans > { buttonText ? buttonText : `Swap Now` } </ Trans >
182+ < Trans >
183+ { currentCampaign . buttonText ? currentCampaign . buttonText : `Learn more` }
184+ </ Trans >
125185 </ Button >
126186 )
127187 ) : null }
128188 </ Typography >
129189 </ Box >
130190
131191 < Box >
132- { ! md && learnMoreLink ? (
133- typeof learnMoreLink === 'string' ? (
134- < Button
135- component = "a"
136- // target={'_blank'} Todo option to pass as prop
137- size = "small"
138- href = { learnMoreLink }
139- sx = { {
140- minWidth : '90px' ,
141- marginLeft : 5 ,
142- height : '24px' ,
143- background : '#383D51' ,
144- color : '#EAEBEF' ,
145- } }
146- >
147- < Trans > { buttonText ? buttonText . toUpperCase ( ) : `LEARN MORE` } </ Trans >
148- </ Button >
149- ) : (
150- < Button
151- size = "small"
152- onClick = { learnMoreLink }
153- sx = { {
154- minWidth : '90px' ,
155- marginLeft : 5 ,
156- height : '24px' ,
157- background : '#383D51' ,
158- color : '#EAEBEF' ,
159- } }
160- >
161- < Trans > { buttonText ? buttonText . toUpperCase ( ) : `Swap Now` } </ Trans >
162- </ Button >
163- )
192+ { ! md && currentCampaign . buttonText && currentCampaign . buttonAction ? (
193+ < Button
194+ size = "small"
195+ onClick = { handleButtonAction }
196+ sx = { {
197+ minWidth : '90px' ,
198+ marginLeft : 5 ,
199+ height : '24px' ,
200+ background : '#383D51' ,
201+ color : '#EAEBEF' ,
202+ } }
203+ >
204+ < Trans > { currentCampaign . buttonText . toUpperCase ( ) } </ Trans >
205+ </ Button >
164206 ) : null }
165207 </ Box >
166208 < Button
0 commit comments