This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 975
/
preferences.js
1444 lines (1354 loc) · 55.1 KB
/
preferences.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
// Note that these are webpack requires, not CommonJS node requiring requires
const React = require('react')
const ImmutableComponent = require('../components/immutableComponent')
const Immutable = require('immutable')
const SwitchControl = require('../components/switchControl')
const ModalOverlay = require('../components/modalOverlay')
const cx = require('../lib/classSet.js')
const { getZoomValuePercentage } = require('../lib/zoom')
const config = require('../constants/config')
const appConfig = require('../constants/appConfig')
const preferenceTabs = require('../constants/preferenceTabs')
const messages = require('../constants/messages')
const settings = require('../constants/settings')
const {passwordManagers, extensionIds} = require('../constants/passwordManagers')
const aboutActions = require('./aboutActions')
const getSetting = require('../settings').getSetting
const SortableTable = require('../components/sortableTable')
const Button = require('../components/button')
const searchProviders = require('../data/searchProviders')
const adblock = appConfig.resourceNames.ADBLOCK
const cookieblock = appConfig.resourceNames.COOKIEBLOCK
const adInsertion = appConfig.resourceNames.AD_INSERTION
const trackingProtection = appConfig.resourceNames.TRACKING_PROTECTION
const httpsEverywhere = appConfig.resourceNames.HTTPS_EVERYWHERE
const safeBrowsing = appConfig.resourceNames.SAFE_BROWSING
const noScript = appConfig.resourceNames.NOSCRIPT
const flash = appConfig.resourceNames.FLASH
const isDarwin = navigator.platform === 'MacIntel'
const isWindows = navigator.platform && navigator.platform.includes('Win')
const ipc = window.chrome.ipc
// TODO: Determine this from the l20n file automatically
const hintCount = 3
// Stylesheets
require('../../less/switchControls.less')
require('../../less/about/preferences.less')
require('../../less/button.less')
require('../../node_modules/font-awesome/css/font-awesome.css')
const permissionNames = {
'mediaPermission': ['boolean'],
'geolocationPermission': ['boolean'],
'notificationsPermission': ['boolean'],
'midiSysexPermission': ['boolean'],
'pointerLockPermission': ['boolean'],
'fullscreenPermission': ['boolean'],
'openExternalPermission': ['boolean'],
'protocolRegistrationPermission': ['boolean'],
'flash': ['boolean', 'number']
}
const changeSetting = (cb, key, e) => {
if (e.target.type === 'checkbox') {
cb(key, e.target.value)
} else {
let value = e.target.value
if (e.target.dataset && e.target.dataset.type === 'number') {
value = parseInt(value, 10)
} else if (e.target.dataset && e.target.dataset.type === 'float') {
value = parseFloat(value)
}
if (e.target.type === 'number') {
value = value.replace(/\D/g, '')
value = parseInt(value, 10)
if (Number.isNaN(value)) {
return
}
value = Math.min(e.target.getAttribute('max'), Math.max(value, e.target.getAttribute('min')))
}
cb(key, value)
}
}
class SettingsList extends ImmutableComponent {
render () {
return <div className='settingsListContainer'>
{
this.props.dataL10nId
? <div className='settingsListTitle' data-l10n-id={this.props.dataL10nId} />
: null
}
<div className='settingsList'>
{this.props.children}
</div>
</div>
}
}
class SettingItem extends ImmutableComponent {
render () {
return <div className='settingItem'>
{
this.props.dataL10nId
? <span data-l10n-id={this.props.dataL10nId} />
: null
}
{this.props.children}
</div>
}
}
class SettingCheckbox extends ImmutableComponent {
constructor () {
super()
this.onClick = this.onClick.bind(this)
}
onClick (e) {
if (this.props.disabled) {
return
}
return this.props.onChange ? this.props.onChange(e) : changeSetting(this.props.onChangeSetting, this.props.prefKey, e)
}
render () {
return <div style={this.props.style} className='settingItem'>
<SwitchControl id={this.props.prefKey}
disabled={this.props.disabled}
onClick={this.onClick}
checkedOn={this.props.checked !== undefined ? this.props.checked : getSetting(this.props.prefKey, this.props.settings)} />
<label data-l10n-id={this.props.dataL10nId} htmlFor={this.props.prefKey} />
{this.props.options}
</div>
}
}
class SiteSettingCheckbox extends ImmutableComponent {
constructor () {
super()
this.onClick = this.onClick.bind(this)
}
onClick (e) {
if (this.props.disabled || !this.props.hostPattern) {
return
} else {
const value = !!e.target.value
value === this.props.defaultValue
? aboutActions.removeSiteSetting(this.props.hostPattern,
this.props.prefKey)
: aboutActions.changeSiteSetting(this.props.hostPattern,
this.props.prefKey, value)
}
}
render () {
return <div style={this.props.style} className='settingItem siteSettingItem'>
<SwitchControl
disabled={this.props.disabled}
onClick={this.onClick}
checkedOn={this.props.checked} />
</div>
}
}
class LedgerTable extends ImmutableComponent {
get synopsis () {
return this.props.ledgerData.get('synopsis')
}
getFormattedTime (synopsis) {
var d = synopsis.get('daysSpent')
var h = synopsis.get('hoursSpent')
var m = synopsis.get('minutesSpent')
var s = synopsis.get('secondsSpent')
if (d << 0 > 364) {
return '>1y'
}
d = (d << 0 === 0) ? '' : (d + 'd ')
h = (h << 0 === 0) ? '' : (h + 'h ')
m = (m << 0 === 0) ? '' : (m + 'm ')
s = (s << 0 === 0) ? '' : (s + 's ')
return (d + h + m + s + '')
}
getHostPattern (synopsis) {
return `https?://${synopsis.get('site')}`
}
enabledForSite (synopsis) {
const hostSettings = this.props.siteSettings.get(this.getHostPattern(synopsis))
if (hostSettings) {
const result = hostSettings.get('ledgerPayments')
if (typeof result === 'boolean') {
return result
}
}
return true
}
getRow (synopsis) {
if (!synopsis || !synopsis.get) {
return []
}
const faviconURL = synopsis.get('faviconURL') || appConfig.defaultFavicon
const rank = synopsis.get('rank')
const views = synopsis.get('views')
const duration = synopsis.get('duration')
const publisherURL = synopsis.get('publisherURL')
const percentage = synopsis.get('percentage')
const site = synopsis.get('site')
const defaultSiteSetting = true
return [
rank,
{
html: <a href={publisherURL} target='_blank'><img src={faviconURL} alt={site} /><span>{site}</span></a>,
value: site
},
{
html: <SiteSettingCheckbox hostPattern={this.getHostPattern(synopsis)} defaultValue={defaultSiteSetting} prefKey='ledgerPayments' siteSettings={this.props.siteSettings} checked={this.enabledForSite(synopsis)} />,
value: this.enabledForSite(synopsis) ? 1 : 0
},
views,
{
html: this.getFormattedTime(synopsis),
value: duration
},
percentage
]
}
render () {
if (!this.synopsis || !this.synopsis.size) {
return null
}
return <div id='ledgerTable'>
<SortableTable
headings={['rank', 'publisher', 'include', 'views', 'timeSpent', 'percentage']}
defaultHeading='rank'
overrideDefaultStyle
columnClassNames={['alignRight', '', '', 'alignRight', 'alignRight', 'alignRight']}
rowClassNames={
this.synopsis.map((item) =>
this.enabledForSite(item) ? '' : 'paymentsDisabled').toJS()
}
onContextMenu={aboutActions.contextMenu}
rows={this.synopsis.map((synopsis) => this.getRow(synopsis)).toJS()} />
</div>
}
}
class BitcoinDashboard extends ImmutableComponent {
constructor () {
super()
this.buyCompleted = false
}
get ledgerData () {
return this.props.ledgerData
}
get bitcoinOverlayContent () {
return <iframe src={this.ledgerData.get('buyURL')} />
}
get qrcodeOverlayContent () {
return <div>
<img src={this.ledgerData.get('paymentIMG')} title='Brave wallet QR code' />
<div className='bitcoinQRTitle' data-l10n-id='bitcoinQR' />
</div>
}
get qrcodeOverlayFooter () {
return <div>
<div id='coinbaseLogo' />
<div id='appstoreLogo' />
<div id='playstoreLogo' />
</div>
}
get currency () {
return this.props.ledgerData.get('currency') || 'USD'
}
get amount () {
return getSetting(settings.PAYMENTS_CONTRIBUTION_AMOUNT, this.props.settings) || 0
}
get canUseCoinbase () {
return this.currency === 'USD' && this.amount < 6
}
get userInAmerica () {
const countryCode = this.props.ledgerData.get('countryCode')
return !(countryCode && countryCode !== 'US')
}
get coinbasePanel () {
if (this.canUseCoinbase) {
return <div className='panel'>
<div className='settingsPanelDivider'>
<span className='fa fa-credit-card' />
<div className='settingsListTitle' data-l10n-id='moneyAdd' />
<div className='settingsListSubTitle' data-l10n-id='moneyAddSubTitle' />
</div>
<div className='settingsPanelDivider'>
<Button l10nId='add' className='primaryButton' onClick={this.props.showOverlay.bind(this)} />
<div className='settingsListSubTitle' data-l10n-id='transferTime' />
</div>
</div>
} else {
return <div className='panel disabledPanel'>
<div className='settingsPanelDivider'>
<span className='fa fa-credit-card' />
<div className='settingsListTitle' data-l10n-id='moneyAdd' />
<div className='settingsListSubTitle' data-l10n-id='moneyAddSubTitle' />
</div>
<div className='settingsPanelDivider'>
<div data-l10n-id='coinbaseNotAvailable' />
</div>
</div>
}
}
get exchangePanel () {
const url = this.props.ledgerData.getIn(['exchangeInfo', 'exchangeURL'])
const name = this.props.ledgerData.getIn(['exchangeInfo', 'exchangeName'])
// Call coinbasePanel if we don't have the URL or Name
if (!url || !name) {
return this.coinbasePanel
} else {
return <div className='panel'>
<div className='settingsPanelDivider'>
<span className='fa fa-credit-card' />
<div className='settingsListTitle' data-l10n-id='outsideUSAPayment' />
</div>
<div className='settingsPanelDivider'>
<span className='visitText' data-l10n-id='visit' />
<a target='_blank' className='browserButton primaryButton' href={url}>
{name}
</a>
</div>
</div>
}
}
get smartphonePanel () {
return <div className='panel'>
<div className='settingsPanelDivider'>
<span className='fa fa-mobile' />
<div className='settingsListTitle' data-l10n-id='smartphoneTitle' />
</div>
<div className='settingsPanelDivider'>
<Button l10nId='displayQRCode' className='primaryButton' onClick={this.props.showQRcode.bind(this)} />
</div>
</div>
}
get panelFooter () {
return <div className='panelFooter'>
<div id='coinbaseLogo' />
<span className='coinbaseMessage' data-l10n-id='coinbaseMessage' />
<Button l10nId='done' className='pull-right whiteButton' onClick={this.props.hideParentOverlay} />
</div>
}
copyToClipboard (text) {
aboutActions.setClipboard(text)
}
onMessage (e) {
if (!e.data || e.origin !== config.coinbaseOrigin) {
return
}
if (e.data.event === 'modal_closed') {
if (this.buyCompleted) {
this.props.hideParentOverlay()
this.buyCompleted = false
} else {
this.props.hideOverlay()
}
} else if (e.data.event === 'buy_completed') {
this.buyCompleted = true
}
}
render () {
window.addEventListener('message', this.onMessage.bind(this), false)
var emptyDialog = true
return <div id='bitcoinDashboard'>
{
this.props.bitcoinOverlayVisible
? <ModalOverlay title={'bitcoinBuy'} content={this.bitcoinOverlayContent} customTitleClasses={'coinbaseOverlay'} emptyDialog={emptyDialog} onHide={this.props.hideOverlay.bind(this)} />
: null
}
{
this.props.qrcodeOverlayVisible
? <ModalOverlay content={this.qrcodeOverlayContent} customTitleClasses={'qrcodeOverlay'} footer={this.qrcodeOverlayFooter} onHide={this.props.hideQRcode.bind(this)} />
: null
}
<div className='board'>
{
this.userInAmerica
? this.coinbasePanel
: this.exchangePanel
}
<div className='panel'>
<div className='settingsPanelDivider'>
<span className='bitcoinIcon fa-stack fa-lg'>
<span className='fa fa-circle fa-stack-2x' />
<span className='fa fa-bitcoin fa-stack-1x' />
</span>
<div className='settingsListTitle' data-l10n-id='bitcoinAdd' />
<div className='settingsListSubTitle' data-l10n-id='bitcoinAddDescription' />
</div>
{
this.ledgerData.get('address')
? <div className='settingsPanelDivider'>
{
this.ledgerData.get('hasBitcoinHandler') && this.ledgerData.get('paymentURL')
? <div>
<a href={this.ledgerData.get('paymentURL')} target='_blank'>
<Button l10nId='bitcoinVisitAccount' className='primaryButton' />
</a>
<div data-l10n-id='bitcoinAddress' className='labelText' />
</div>
: <div>
<div data-l10n-id='bitcoinPaymentURL' className='labelText' />
</div>
}
<span className='smallText'>{this.ledgerData.get('address')}</span>
<Button className='primaryButton' l10nId='copyToClipboard' onClick={this.copyToClipboard.bind(this, this.ledgerData.get('address'))} />
</div>
: <div className='settingsPanelDivider'>
<div data-l10n-id='bitcoinWalletNotAvailable' />
</div>
}
</div>
{this.smartphonePanel}
{this.panelFooter}
</div>
</div>
}
}
class PaymentHistory extends ImmutableComponent {
get ledgerData () {
return this.props.ledgerData
}
render () {
const transactions = this.props.ledgerData.get('transactions')
return <div id='paymentHistory'>
<table className='sort'>
<thead>
<tr>
<th className='sort-header' data-l10n-id='date' />
<th className='sort-header' data-l10n-id='totalAmount' />
</tr>
</thead>
<tbody>
{
transactions.map(function (row) {
return <PaymentHistoryRow transaction={row} ledgerData={this.props.ledgerData} />
}.bind(this))
}
</tbody>
</table>
</div>
}
}
class PaymentHistoryRow extends ImmutableComponent {
get transaction () {
return this.props.transaction
}
get timestamp () {
return this.transaction.get('submissionStamp')
}
get formattedDate () {
return formattedDateFromTimestamp(this.timestamp)
}
get numericDateStr () {
return (new Date(this.timestamp)).toLocaleDateString().replace(/\//g, '-')
}
get ledgerData () {
return this.props.ledgerData
}
get satoshis () {
return this.transaction.getIn(['contribution', 'satoshis'])
}
get currency () {
return this.transaction.getIn(['contribution', 'fiat', 'currency'])
}
get totalAmount () {
var fiatAmount = this.transaction.getIn(['contribution', 'fiat', 'amount'])
return (fiatAmount && typeof fiatAmount === 'number' ? fiatAmount.toFixed(2) : '0.00')
}
render () {
var date = this.formattedDate
var totalAmountStr = `${this.totalAmount} ${this.currency}`
return <tr>
<td data-sort={this.timestamp}>{date}</td>
<td data-sort={this.satoshis}>{totalAmountStr}</td>
</tr>
}
}
class GeneralTab extends ImmutableComponent {
enabled (keyArray) {
return keyArray.every((key) => getSetting(key, this.props.settings) === true)
}
render () {
var languageOptions = this.props.languageCodes.map(function (lc) {
return (
<option data-l10n-id={lc} value={lc} />
)
})
const defaultLanguage = this.props.languageCodes.find((lang) => lang.includes(navigator.language)) || 'en-US'
return <SettingsList>
<div className='sectionTitle' data-l10n-id='generalSettings' />
<SettingsList>
<SettingItem dataL10nId='startsWith'>
<select value={getSetting(settings.STARTUP_MODE, this.props.settings)}
onChange={changeSetting.bind(null, this.props.onChangeSetting, settings.STARTUP_MODE)} >
<option data-l10n-id='startsWithOptionLastTime' value='lastTime' />
<option data-l10n-id='startsWithOptionHomePage' value='homePage' />
<option data-l10n-id='startsWithOptionNewTabPage' value='newTabPage' />
</select>
</SettingItem>
<SettingItem dataL10nId='myHomepage'>
<input spellCheck='false'
data-l10n-id='homepageInput'
value={getSetting(settings.HOMEPAGE, this.props.settings)}
onChange={changeSetting.bind(null, this.props.onChangeSetting, settings.HOMEPAGE)} />
</SettingItem>
<SettingItem dataL10nId='selectedLanguage'>
<select value={getSetting(settings.LANGUAGE, this.props.settings) || defaultLanguage}
onChange={changeSetting.bind(null, this.props.onChangeSetting, settings.LANGUAGE)} >
{languageOptions}
</select>
</SettingItem>
</SettingsList>
<div className='sectionTitle' data-l10n-id='bookmarkToolbarSettings' />
<SettingsList>
<SettingCheckbox dataL10nId='bookmarkToolbar' prefKey={settings.SHOW_BOOKMARKS_TOOLBAR} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='bookmarkToolbarShowFavicon' style={{ display: this.enabled([settings.SHOW_BOOKMARKS_TOOLBAR]) ? 'block' : 'none' }} prefKey={settings.SHOW_BOOKMARKS_TOOLBAR_FAVICON} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='bookmarkToolbarShowOnlyFavicon' style={{ display: this.enabled([settings.SHOW_BOOKMARKS_TOOLBAR, settings.SHOW_BOOKMARKS_TOOLBAR_FAVICON]) ? 'block' : 'none' }} prefKey={settings.SHOW_BOOKMARKS_TOOLBAR_ONLY_FAVICON} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
</SettingsList>
<div className='sectionTitle' data-l10n-id='appearanceSettings' />
<SettingsList>
<SettingCheckbox dataL10nId='showHomeButton' prefKey={settings.SHOW_HOME_BUTTON} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
{
isDarwin ? null : <SettingCheckbox dataL10nId='autoHideMenuBar' prefKey={settings.AUTO_HIDE_MENU} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
}
<SettingCheckbox dataL10nId='disableTitleMode' prefKey={settings.DISABLE_TITLE_MODE} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
</SettingsList>
</SettingsList>
}
}
class SearchSelectEntry extends ImmutableComponent {
render () {
return <div>
{getSetting(settings.DEFAULT_SEARCH_ENGINE, this.props.settings) === this.props.name
? <span className='fa fa-check-square' id='searchSelectIcon' /> : null}
</div>
}
}
class SearchEntry extends ImmutableComponent {
render () {
return <div>
<span style={this.props.iconStyle} />
<span style={{paddingLeft: '5px', verticalAlign: 'middle'}}>{this.props.name}</span>
</div>
}
}
class SearchShortcutEntry extends ImmutableComponent {
render () {
return <div style={{paddingLeft: '5px', verticalAlign: 'middle'}}>
{this.props.shortcut}
</div>
}
}
class SearchTab extends ImmutableComponent {
get searchProviders () {
let entries = searchProviders.providers
let array = []
const iconSize = 16
entries.forEach((entry) => {
let iconStyle = {
backgroundImage: `url(${entry.image})`,
minWidth: iconSize,
width: iconSize,
backgroundSize: iconSize,
height: iconSize,
display: 'inline-block',
verticalAlign: 'middle'
}
array.push([
{
html: <SearchSelectEntry name={entry.name} settings={this.props.settings} />,
value: entry.name
},
{
html: <SearchEntry name={entry.name} iconStyle={iconStyle} onChangeSetting={this.props.onChangeSetting} />,
value: entry.name
},
{
html: <SearchShortcutEntry shortcut={entry.shortcut} />,
value: entry.shortcut
}
])
})
return array
}
hoverCallback (rows) {
this.props.onChangeSetting(settings.DEFAULT_SEARCH_ENGINE, rows[1].props.children.props.name)
}
render () {
return <div>
<div className='sectionTitle' data-l10n-id='searchSettings' />
<SortableTable headings={['default', 'searchEngine', 'engineGoKey']} rows={this.searchProviders}
defaultHeading='searchEngine'
addHoverClass onClick={this.hoverCallback.bind(this)} />
<div className='sectionTitle' data-l10n-id='locationBarSettings' />
<SettingsList>
<SettingCheckbox dataL10nId='showOpenedTabMatches' prefKey={settings.OPENED_TAB_SUGGESTIONS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='showHistoryMatches' prefKey={settings.HISTORY_SUGGESTIONS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='showBookmarkMatches' prefKey={settings.BOOKMARK_SUGGESTIONS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='offerSearchSuggestions' prefKey={settings.OFFER_SEARCH_SUGGESTIONS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
</SettingsList>
</div>
}
}
class TabsTab extends ImmutableComponent {
render () {
return <div>
<div className='sectionTitle' data-l10n-id='tabSettings' />
<SettingsList>
<SettingItem dataL10nId='tabsPerTabPage'>
<select
value={getSetting(settings.TABS_PER_PAGE, this.props.settings)}
data-type='number'
onChange={changeSetting.bind(null, this.props.onChangeSetting, settings.TABS_PER_PAGE)}>
{
// Sorry, Brad says he hates primes :'(
[6, 8, 10, 20].map((x) =>
<option value={x} key={x}>{x}</option>)
}
</select>
</SettingItem>
<SettingCheckbox dataL10nId='switchToNewTabs' prefKey={settings.SWITCH_TO_NEW_TABS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='paintTabs' prefKey={settings.PAINT_TABS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingCheckbox dataL10nId='showTabPreviews' prefKey={settings.SHOW_TAB_PREVIEWS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
</SettingsList>
</div>
}
}
class PaymentsTab extends ImmutableComponent {
constructor () {
super()
this.createWallet = this.createWallet.bind(this)
}
createWallet () {
if (!this.props.ledgerData.get('created')) {
aboutActions.createWallet()
}
}
get enabled () {
return getSetting(settings.PAYMENTS_ENABLED, this.props.settings)
}
get fundsAmount () {
if (!this.props.ledgerData.get('created')) {
return null
}
return <div>
{
!(this.props.ledgerData.get('balance') === undefined || this.props.ledgerData.get('balance') === null)
? <input className='fundsAmount' readOnly value={this.btcToCurrencyString(this.props.ledgerData.get('balance'))} />
: <span><span data-l10n-id='accountBalanceLoading' /></span>
}
<a href='https://brave.com/Payments_FAQ.html' target='_blank'>
<span className='fa fa-question-circle fundsFAQ' />
</a>
</div>
}
get walletButton () {
const buttonText = this.props.ledgerData.get('created')
? 'addFundsTitle'
: (this.props.ledgerData.get('creating') ? 'creatingWallet' : 'createWallet')
const onButtonClick = this.props.ledgerData.get('created')
? this.props.showOverlay.bind(this, 'addFunds')
: (this.props.ledgerData.get('creating') ? () => {} : this.createWallet)
return <Button l10nId={buttonText} className='primaryButton addFunds' onClick={onButtonClick.bind(this)} disabled={this.props.ledgerData.get('creating')} />
}
get paymentHistoryButton () {
const walletCreated = this.props.ledgerData.get('created') && !this.props.ledgerData.get('creating')
const walletTransactions = this.props.ledgerData.get('transactions')
const walletHasTransactions = walletTransactions && walletTransactions.size
if (!walletCreated || !walletHasTransactions) {
return null
}
const buttonText = 'viewPaymentHistory'
const onButtonClick = this.props.showOverlay.bind(this, 'paymentHistory')
return <Button className='paymentHistoryButton' l10nId={buttonText} onClick={onButtonClick.bind(this)} disabled={this.props.ledgerData.get('creating')} />
}
get walletStatus () {
let status = {}
if (this.props.ledgerData.get('created')) {
const transactions = this.props.ledgerData.get('transactions')
const pendingFunds = Number(this.props.ledgerData.get('unconfirmed') || 0)
if (pendingFunds + Number(this.props.ledgerData.get('balance') || 0) <
0.9 * Number(this.props.ledgerData.get('btc') || 0)) {
status.id = 'insufficientFundsStatus'
} else if (pendingFunds > 0) {
status.id = 'pendingFundsStatus'
status.args = {funds: this.btcToCurrencyString(pendingFunds)}
} else if (transactions && transactions.size > 0) {
status.id = 'defaultWalletStatus'
} else {
status.id = 'createdWalletStatus'
}
} else if (this.props.ledgerData.get('creating')) {
status.id = 'creatingWalletStatus'
} else {
status.id = 'createWalletStatus'
}
return status
}
get tableContent () {
// TODO: This should be sortable. #2497
return <LedgerTable ledgerData={this.props.ledgerData}
siteSettings={this.props.siteSettings} />
}
get overlayContent () {
return <BitcoinDashboard ledgerData={this.props.ledgerData}
settings={this.props.settings}
bitcoinOverlayVisible={this.props.bitcoinOverlayVisible}
qrcodeOverlayVisible={this.props.qrcodeOverlayVisible}
showOverlay={this.props.showOverlay.bind(this, 'bitcoin')}
hideOverlay={this.props.hideOverlay.bind(this, 'bitcoin')}
showQRcode={this.props.showOverlay.bind(this, 'qrcode')}
hideQRcode={this.props.hideOverlay.bind(this, 'qrcode')}
hideParentOverlay={this.props.hideOverlay.bind(this, 'addFunds')} />
}
get paymentHistoryContent () {
return <PaymentHistory ledgerData={this.props.ledgerData} />
}
get paymentHistoryFooter () {
let ledgerData = this.props.ledgerData
if (!ledgerData.get('reconcileStamp')) {
return null
}
let nextReconcileDate = formattedDateFromTimestamp(ledgerData.get('reconcileStamp'))
let l10nDataArgs = {
reconcileDate: nextReconcileDate
}
return <div className='paymentHistoryFooter'>
<div className='nextPaymentSubmission'>
<span data-l10n-id='paymentHistoryFooterText' data-l10n-args={JSON.stringify(l10nDataArgs)} />
</div>
<Button l10nId='paymentHistoryOKText' className='okButton primaryButton' onClick={this.props.hideOverlay.bind(this, 'paymentHistory')} />
</div>
}
get nextReconcileDate () {
const ledgerData = this.props.ledgerData
if (!ledgerData.get('reconcileStamp')) {
return null
}
const nextReconcileDate = formattedDateFromTimestamp(ledgerData.get('reconcileStamp'))
const l10nDataArgs = {
reconcileDate: nextReconcileDate
}
return <div className='nextReconcileDate' data-l10n-args={JSON.stringify(l10nDataArgs)} data-l10n-id='statusNextReconcileDate' />
}
btcToCurrencyString (btc) {
const balance = Number(btc || 0)
const currency = this.props.ledgerData.get('currency') || 'USD'
if (balance === 0) {
return `0 ${currency}`
}
if (this.props.ledgerData.get('btc') && typeof this.props.ledgerData.get('amount') === 'number') {
const btcValue = this.props.ledgerData.get('btc') / this.props.ledgerData.get('amount')
return `${(balance / btcValue).toFixed(2)} ${currency}`
}
return `${balance} BTC`
}
get sidebarContent () {
return <div id='paymentsSidebar'>
<h2 data-l10n-id='paymentsSidebarText1' />
<div data-l10n-id='paymentsSidebarText2' />
<a href='https://www.privateinternetaccess.com/' target='_blank'><div className='paymentsSidebarPIA' /></a>
<div data-l10n-id='paymentsSidebarText3' />
<a href='https://www.bitgo.com/' target='_blank'><div className='paymentsSidebarBitgo' /></a>
<div data-l10n-id='paymentsSidebarText4' />
<a href='https://www.coinbase.com/' target='_blank'><div className='paymentsSidebarCoinbase' /></a>
</div>
}
get enabledContent () {
// TODO: report when funds are too low
// TODO: support non-USD currency
return <div>
<div className='walletBar'>
<table>
<thead>
<tr>
<th data-l10n-id='monthlyBudget' />
<th data-l10n-id='accountBalance' />
<th data-l10n-id='status' />
</tr>
</thead>
<tbody>
<tr>
<td>
<SettingsList>
<SettingItem>
<select id='fundsSelectBox'
value={getSetting(settings.PAYMENTS_CONTRIBUTION_AMOUNT,
this.props.settings)}
onChange={changeSetting.bind(null, this.props.onChangeSetting, settings.PAYMENTS_CONTRIBUTION_AMOUNT)} >
{
[5, 10, 15, 20].map((amount) =>
<option value={amount}>{amount} {this.props.ledgerData.get('currency') || 'USD'}</option>
)
}
</select>
</SettingItem>
</SettingsList>
</td>
<td>
{
this.props.ledgerData.get('error') && this.props.ledgerData.get('error').get('caller') === 'getWalletProperties'
? <span data-l10n-id='accountBalanceConnectionError' />
: <span>
<SettingsList>
<SettingItem>
{this.fundsAmount}
{this.walletButton}
{this.paymentHistoryButton}
</SettingItem>
</SettingsList>
</span>
}
</td>
<td>
<div id='walletStatus' data-l10n-id={this.walletStatus.id} data-l10n-args={this.walletStatus.args ? JSON.stringify(this.walletStatus.args) : null} />
{this.nextReconcileDate}
</td>
</tr>
</tbody>
</table>
</div>
{this.tableContent}
</div>
}
render () {
return <div id='paymentsContainer'>
{
this.enabled && this.props.addFundsOverlayVisible
? <ModalOverlay title={'addFunds'} content={this.overlayContent} onHide={this.props.hideOverlay.bind(this, 'addFunds')} />
: null
}
{
this.enabled && this.props.paymentHistoryOverlayVisible
? <ModalOverlay title={'paymentHistoryTitle'} customTitleClasses={'paymentHistory'} content={this.paymentHistoryContent} footer={this.paymentHistoryFooter} onHide={this.props.hideOverlay.bind(this, 'paymentHistory')} />
: null
}
<div className='titleBar'>
<div className='sectionTitleWrapper pull-left'>
<span className='sectionTitle'>Brave Payments</span>
<span className='sectionSubTitle'>beta</span>
</div>
<div className='pull-left' id='paymentsSwitches'>
<div className='enablePaymentsSwitch'>
<span data-l10n-id='off' />
<SettingCheckbox dataL10nId='on' prefKey={settings.PAYMENTS_ENABLED} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
</div>
{this.enabled ? <SettingCheckbox dataL10nId='notifications' prefKey={settings.PAYMENTS_NOTIFICATIONS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} /> : null}
</div>
</div>
{
this.enabled
? this.enabledContent
: <div className='paymentsMessage'>
<h3 data-l10n-id='paymentsWelcomeTitle' />
<div data-l10n-id='paymentsWelcomeText1' />
<div className='boldText' data-l10n-id='paymentsWelcomeText2' />
<div data-l10n-id='paymentsWelcomeText3' />
<div data-l10n-id='paymentsWelcomeText4' />
<div data-l10n-id='paymentsWelcomeText5' />
<div>
<span data-l10n-id='paymentsWelcomeText6' />
<a href='https://brave.com/Payments_FAQ.html' target='_blank' data-l10n-id='paymentsWelcomeLink' />
<span data-l10n-id='paymentsWelcomeText7' />
</div>
</div>
}
{this.enabled ? null : this.sidebarContent}
</div>
}
}
class SyncTab extends ImmutableComponent {
render () {
return <div>
Sync settings coming soon
</div>
}
}
class SitePermissionsPage extends React.Component {
hasEntryForPermission (name) {
return this.props.siteSettings.some((value) => {
return value.get && permissionNames[name] ? permissionNames[name].includes(typeof value.get(name)) : false
})
}
isPermissionsNonEmpty () {
// Check whether there is at least one permission set
return this.props.siteSettings.some((value) => {
if (value && value.get) {
for (let name in permissionNames) {
if (permissionNames[name].includes(typeof value.get(name))) {
return true
}
}
}
return false
})
}
deletePermission (name, hostPattern) {
aboutActions.removeSiteSetting(hostPattern, name)
}
render () {
return this.isPermissionsNonEmpty()
? <div id='sitePermissionsPage'>
<div className='sectionTitle' data-l10n-id='sitePermissions' />
<ul className='sitePermissions'>
{
Object.keys(permissionNames).map((name) =>
this.hasEntryForPermission(name)
? <li>
<div data-l10n-id={name} className='permissionName' />
<ul>
{
this.props.siteSettings.map((value, hostPattern) => {
if (!value.size) {
return null
}
const granted = value.get(name)
if (permissionNames[name].includes(typeof granted)) {
let statusText
let statusArgs
if (name === 'flash') {
if (granted === 1) {
// Flash is allowed just one time
statusText = 'flashAllowOnce'
} else if (granted === false) {
// Flash installer is never intercepted
statusText = 'alwaysDeny'
} else {
// Show the number of days/hrs/min til expiration
statusText = 'flashAllowAlways'
statusArgs = {
time: new Date(granted).toLocaleString()
}
}
} else {
statusText = granted ? 'alwaysAllow' : 'alwaysDeny'
}
return <div className='permissionItem'>
<span className='fa fa-times permissionAction'
onClick={this.deletePermission.bind(this, name, hostPattern)} />
<span className='permissionHost'>{hostPattern + ': '}</span>
<span className='permissionStatus'