@@ -99,13 +99,6 @@ class NewTabPage extends React.Component<Props, State> {
99
99
if ( GetShouldShowBrandedWallpaperNotification ( this . props ) ) {
100
100
this . trackBrandedWallpaperNotificationAutoDismiss ( )
101
101
}
102
-
103
- // Migratory check in the event that rewards is off
104
- // when receiving the upgrade with the Binance widget.
105
- const { showRewards } = this . props . newTabData
106
- if ( ! showRewards ) {
107
- this . props . actions . setCurrentStackWidget ( 'binance' )
108
- }
109
102
}
110
103
111
104
componentDidUpdate ( prevProps : Props ) {
@@ -136,13 +129,13 @@ class NewTabPage extends React.Component<Props, State> {
136
129
const { showRewards, showBinance } = this . props . newTabData
137
130
138
131
if ( ! oldShowRewards && showRewards ) {
139
- this . props . actions . setCurrentStackWidget ( 'rewards' )
132
+ this . props . actions . setForegroundStackWidget ( 'rewards' )
140
133
} else if ( ! oldShowBinance && showBinance ) {
141
- this . props . actions . setCurrentStackWidget ( 'binance' )
134
+ this . props . actions . setForegroundStackWidget ( 'binance' )
142
135
} else if ( oldShowRewards && ! showRewards ) {
143
- this . props . actions . setCurrentStackWidget ( 'binance ')
136
+ this . props . actions . removeStackWidget ( 'rewards ')
144
137
} else if ( oldShowBinance && ! showBinance ) {
145
- this . props . actions . setCurrentStackWidget ( 'rewards ')
138
+ this . props . actions . removeStackWidget ( 'binance ')
146
139
}
147
140
}
148
141
@@ -207,36 +200,24 @@ class NewTabPage extends React.Component<Props, State> {
207
200
}
208
201
209
202
toggleShowRewards = ( ) => {
210
- const {
211
- currentStackWidget,
212
- showBinance,
213
- showRewards
214
- } = this . props . newTabData
215
-
216
- if ( currentStackWidget === 'rewards' && showRewards ) {
217
- this . props . actions . setCurrentStackWidget ( 'binance' )
218
- } else if ( ! showBinance ) {
219
- this . props . actions . setCurrentStackWidget ( 'rewards' )
220
- } else if ( ! showRewards ) {
221
- this . props . actions . setCurrentStackWidget ( 'rewards' )
203
+ const { showRewards } = this . props . newTabData
204
+
205
+ if ( showRewards ) {
206
+ this . removeStackWidget ( 'rewards' )
207
+ } else {
208
+ this . setForegroundStackWidget ( 'rewards' )
222
209
}
223
210
224
211
this . props . saveShowRewards ( ! showRewards )
225
212
}
226
213
227
214
toggleShowBinance = ( ) => {
228
- const {
229
- currentStackWidget,
230
- showBinance,
231
- showRewards
232
- } = this . props . newTabData
233
-
234
- if ( currentStackWidget === 'binance' && showBinance ) {
235
- this . props . actions . setCurrentStackWidget ( 'rewards' )
236
- } else if ( ! showRewards ) {
237
- this . props . actions . setCurrentStackWidget ( 'binance' )
238
- } else if ( ! showBinance ) {
239
- this . props . actions . setCurrentStackWidget ( 'binance' )
215
+ const { showBinance } = this . props . newTabData
216
+
217
+ if ( showBinance ) {
218
+ this . removeStackWidget ( 'binance' )
219
+ } else {
220
+ this . setForegroundStackWidget ( 'binance' )
240
221
}
241
222
242
223
this . props . saveShowBinance ( ! showBinance )
@@ -339,8 +320,12 @@ class NewTabPage extends React.Component<Props, State> {
339
320
this . setState ( { showSettingsMenu : ! this . state . showSettingsMenu } )
340
321
}
341
322
342
- toggleStackWidget = ( widgetId : NewTab . StackWidget ) => {
343
- this . props . actions . setCurrentStackWidget ( widgetId )
323
+ setForegroundStackWidget = ( widget : NewTab . StackWidget ) => {
324
+ this . props . actions . setForegroundStackWidget ( widget )
325
+ }
326
+
327
+ removeStackWidget = ( widget : NewTab . StackWidget ) => {
328
+ this . props . actions . removeStackWidget ( widget )
344
329
}
345
330
346
331
setInitialAmount = ( amount : string ) => {
@@ -451,30 +436,31 @@ class NewTabPage extends React.Component<Props, State> {
451
436
}
452
437
453
438
getCryptoContent ( ) {
454
- const { currentStackWidget } = this . props . newTabData
439
+ const { widgetStackOrder } = this . props . newTabData
440
+ const renderLookup = {
441
+ 'rewards' : this . renderRewardsWidget . bind ( this ) ,
442
+ 'binance' : this . renderBinanceWidget . bind ( this )
443
+ }
455
444
456
445
return (
457
446
< >
458
- {
459
- currentStackWidget === 'rewards'
460
- ? < >
461
- { this . renderBinanceWidget ( false ) }
462
- { this . renderRewardsWidget ( true ) }
463
- </ >
464
- : < >
465
- { this . renderRewardsWidget ( false ) }
466
- { this . renderBinanceWidget ( true ) }
467
- </ >
468
- }
447
+ { widgetStackOrder . map ( ( widget : NewTab . StackWidget , i : number ) => {
448
+ const isForeground = i === widgetStackOrder . length - 1
449
+ return (
450
+ < div key = { `widget-${ widget } ` } >
451
+ { renderLookup [ widget ] ( isForeground ) }
452
+ </ div >
453
+ )
454
+ } ) }
469
455
</ >
470
456
)
471
457
}
472
458
473
459
renderCryptoContent ( ) {
474
460
const { newTabData } = this . props
475
- const { showRewards , showBinance } = newTabData
461
+ const { widgetStackOrder } = newTabData
476
462
477
- if ( ! showRewards && ! showBinance ) {
463
+ if ( ! widgetStackOrder . length ) {
478
464
return null
479
465
}
480
466
@@ -512,7 +498,7 @@ class NewTabPage extends React.Component<Props, State> {
512
498
preventFocus = { false }
513
499
hideWidget = { this . toggleShowRewards }
514
500
showContent = { showContent }
515
- onShowContent = { this . toggleStackWidget . bind ( this , 'rewards' ) }
501
+ onShowContent = { this . setForegroundStackWidget . bind ( this , 'rewards' ) }
516
502
onCreateWallet = { this . createWallet }
517
503
onEnableAds = { this . enableAds }
518
504
onEnableRewards = { this . enableRewards }
@@ -561,7 +547,7 @@ class NewTabPage extends React.Component<Props, State> {
561
547
onValidAuthCode = { this . onValidAuthCode }
562
548
onBuyCrypto = { this . buyCrypto }
563
549
onBinanceUserTLD = { this . onBinanceUserTLD }
564
- onShowContent = { this . toggleStackWidget . bind ( this , 'binance' ) }
550
+ onShowContent = { this . setForegroundStackWidget . bind ( this , 'binance' ) }
565
551
onSetInitialAmount = { this . setInitialAmount }
566
552
onSetInitialAsset = { this . setInitialAsset }
567
553
onSetInitialFiat = { this . setInitialFiat }
0 commit comments