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 972
/
Copy pathpaymentsTab.js
467 lines (420 loc) · 15 KB
/
paymentsTab.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
/* 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/. */
const React = require('react')
const Immutable = require('immutable')
const {StyleSheet, css} = require('aphrodite/no-important')
// Components
const cx = require('../../../../js/lib/classSet')
const ImmutableComponent = require('../immutableComponent')
const ModalOverlay = require('../common/modalOverlay')
const {SettingCheckbox} = require('../common/settings')
const {
sectionTitleStyles,
SectionTitleWrapper,
AboutPageSectionTitle,
SectionLabelTitle
} = require('../common/sectionTitle')
const DisabledContent = require('./payment/disabledContent')
const EnabledContent = require('./payment/enabledContent')
const AddFundsDialog = require('./payment/addFundsDialog/addFundsDialog')
const AddFundsDialogFooter = require('./payment/addFundsDialog/addFundsDialogFooter')
const {AdvancedSettingsContent, AdvancedSettingsFooter} = require('./payment/advancedSettings')
const {HistoryContent, HistoryFooter} = require('./payment/history')
const {LedgerBackupContent, LedgerBackupFooter} = require('./payment/ledgerBackup')
const {LedgerRecoveryContent, LedgerRecoveryFooter} = require('./payment/ledgerRecovery')
// Actions
const appActions = require('../../../../js/actions/appActions')
// Style
const globalStyles = require('../styles/global')
const {paymentStylesVariables} = require('../styles/payment')
const settingsIcon = require('../../../extensions/brave/img/ledger/icon_settings.svg')
const historyIcon = require('../../../extensions/brave/img/ledger/icon_history.svg')
const batIcon = require('../../../extensions/brave/img/ledger/cryptoIcons/BAT_icon.svg')
// Other
const getSetting = require('../../../../js/settings').getSetting
const settings = require('../../../../js/constants/settings')
const {formatCurrentBalance, batToCurrencyString} = require('../../../common/lib/ledgerUtil')
class PaymentsTab extends ImmutableComponent {
constructor () {
super()
this.state = {
recoveryKey: ''
}
this.handleRecoveryKeyChange = this.handleRecoveryKeyChange.bind(this)
this.hideOverlay = this.hideOverlay.bind(this)
}
handleRecoveryKeyChange (key) {
this.setState({recoveryKey: key})
this.forceUpdate()
}
get hasWalletTransaction () {
const ledgerData = this.props.ledgerData
const walletCreated = ledgerData.get('created') && !ledgerData.get('creating')
const walletTransactions = ledgerData.get('transactions')
const walletHasReconcile = ledgerData.get('reconcileStamp')
const walletHasTransactions = walletTransactions && walletTransactions.size
return !(!walletCreated || !walletHasTransactions || !walletHasReconcile)
}
get enabled () {
return getSetting(settings.PAYMENTS_ENABLED, this.props.settings)
}
get overlayContent () {
const ledgerData = this.props.ledgerData || Immutable.Map()
const addresses = ledgerData.get('addresses') || Immutable.List()
const walletQR = ledgerData.get('walletQR') || Immutable.List()
const wizardData = ledgerData.get('wizardData') || Immutable.Map()
const funds = formatCurrentBalance(ledgerData)
const budget = getSetting(settings.PAYMENTS_CONTRIBUTION_AMOUNT, this.props.settings)
const minAmount = batToCurrencyString(budget, ledgerData)
return <AddFundsDialog
addFundsDialog={wizardData}
funds={funds}
minAmount={minAmount}
addresses={addresses}
walletQR={walletQR}
/>
}
get overlayFooter () {
const ledgerData = this.props.ledgerData || Immutable.Map()
const wizardData = ledgerData.get('wizardData') || Immutable.Map()
return (
<AddFundsDialogFooter
addFundsDialog={wizardData}
onHide={this.props.hideOverlay.bind(this, 'addFunds')}
/>
)
}
get getOverlayFounds () {
const ledgerData = this.props.ledgerData || Immutable.Map()
return formatCurrentBalance(ledgerData)
}
hideOverlay () {
this.props.hideOverlay('addFunds')
appActions.onChangeAddFundsDialogStep('addFundsWizardMain')
}
render () {
const enabled = this.props.ledgerData.get('created')
const inTransition = this.props.ledgerData.getIn(['migration', 'btc2BatTransitionPending']) === true
const enableSettings = enabled && !inTransition
return <div className={cx({
paymentsContainer: true,
[css(styles.paymentsContainer)]: true
})} data-test-id='paymentsContainer'>
{
this.enabled && this.props.addFundsOverlayVisible
? <ModalOverlay
title={'addFundsHeader'}
subTitle={'balance'}
subTitleArgs={this.getOverlayFounds}
content={this.overlayContent}
footer={this.overlayFooter}
onHide={this.hideOverlay}
/>
: null
}
{
this.enabled && this.props.paymentHistoryOverlayVisible
? <ModalOverlay
title={'paymentHistoryTitle'}
customDialogClasses={'paymentHistory'}
customDialogHeaderClasses={css(styles.paymentHistoryOverlay__header)}
customDialogBodyClasses={css(styles.paymentHistoryOverlay__body)}
customDialogFooterClasses={css(styles.paymentHistoryOverlay__footer)}
customTitleClasses={css(styles.paymentHistoryOverlay__title)}
content={<HistoryContent
ledgerData={this.props.ledgerData}
/>}
footer={<HistoryFooter
ledgerData={this.props.ledgerData}
hideOverlay={this.props.hideOverlay}
/>}
onHide={this.props.hideOverlay.bind(this, 'paymentHistory')}
/>
: null
}
{
this.enabled && this.props.advancedSettingsOverlayVisible
? <ModalOverlay
title={'advancedSettingsTitle'}
content={<AdvancedSettingsContent
ledgerData={this.props.ledgerData}
settings={this.props.settings}
onChangeSetting={this.props.onChangeSetting}
/>}
footer={<AdvancedSettingsFooter
showOverlay={this.props.showOverlay}
hideOverlay={this.props.hideOverlay}
/>}
onHide={this.props.hideOverlay.bind(this, 'advancedSettings')}
/>
: null
}
{
this.enabled && this.props.ledgerBackupOverlayVisible
? <ModalOverlay
title={'ledgerBackupTitle'}
content={<LedgerBackupContent
ledgerData={this.props.ledgerData}
/>}
footer={<LedgerBackupFooter
hideOverlay={this.props.hideOverlay}
/>}
onHide={this.props.hideOverlay.bind(this, 'ledgerBackup')} />
: null
}
{
this.enabled && this.props.ledgerRecoveryOverlayVisible
? <ModalOverlay title={'ledgerRecoveryTitle'}
content={<LedgerRecoveryContent
ledgerData={this.props.ledgerData}
hideAdvancedOverlays={this.props.hideAdvancedOverlays.bind(this)}
handleRecoveryKeyChange={this.handleRecoveryKeyChange.bind(this)}
/>}
footer={<LedgerRecoveryFooter
state={this.state}
hideOverlay={this.props.hideOverlay}
/>}
onHide={this.props.hideOverlay.bind(this, 'ledgerRecovery')}
/>
: null
}
<SectionTitleWrapper>
<section className={css(styles.titleWrapper)}>
{ /* Note: This div cannot be replaced with SectionTitleLabelWrapper */ }
<div className={css(
gridStyles.row1col1,
styles.titleWrapper__title,
sectionTitleStyles.beta
)}>
<img className={css(styles.titleWrapper__logo)} src={batIcon} />
<AboutPageSectionTitle>Brave Payments</AboutPageSectionTitle>
<SectionLabelTitle>beta</SectionLabelTitle>
</div>
<div data-test-id='enablePaymentsSwitch' className={css(
gridStyles.row1col2,
styles.titleWrapper__switchWrap
)}>
<SettingCheckbox
dataL10nId='on'
dataL10nIdLeft='off'
prefKey={settings.PAYMENTS_ENABLED}
settings={this.props.settings}
onChangeSetting={this.props.onChangeSetting}
switchClassName={css(styles.switchWrap__switchControl)}
leftLabelClassName={css(styles.switchWrap__label, styles.switchWrap__label_left)}
rightLabelClassName={css(styles.switchWrap__label, styles.switchWrap__label_right)}
/>
<a className={cx({
fa: true,
'fa-question-circle': true,
[css(styles.autoSuggestSwitch__moreInfo, styles.autoSuggestSwitch__moreInfoBtnSuggest)]: true
})}
href='https://brave.com/Payments_FAQ.html'
data-l10n-id='paymentsFAQLink'
rel='noopener' target='_blank'
/>
</div>
<div className={css(gridStyles.row1col3)}>
{
this.enabled
? <div className={css(
styles.switchWrap,
styles.switchWrap__right
)}>
<div className={css(styles.switchWrap__autoSuggestSwitch)}>
<div className={css(styles.flexAlignCenter, styles.autoSuggestSwitch__subtext)}>
<SettingCheckbox
dataL10nId='autoSuggestSites'
prefKey={settings.PAYMENTS_SITES_AUTO_SUGGEST}
settings={this.props.settings}
disabled={!enabled}
onChangeSetting={this.props.onChangeSetting}
switchClassName={css(styles.switchWrap__switchControl)}
/>
</div>
</div>
<div className={css(styles.switchWrap__mainIconsRight)}>
<a className={css(
styles.switchWrap__mainIcons,
styles.mainIcons__historyIcon,
!this.hasWalletTransaction && styles.mainIcons__historyDisabled
)}
data-test-id={this.hasWalletTransaction ? 'paymentHistoryButton' : 'disabledPaymentHistoryButton'}
data-l10n-id='paymentHistoryIcon'
onClick={(enabled && this.hasWalletTransaction) ? this.props.showOverlay.bind(this, 'paymentHistory') : () => {}}
/>
<a className={css(
styles.switchWrap__mainIcons,
styles.mainIcons__settingsIcon,
!enableSettings && styles.mainIcons__settingsIconDisabled
)}
data-test-id={!enableSettings ? 'advancedSettingsButtonLoading' : 'advancedSettingsButton'}
data-l10n-id='advancedSettingsIcon'
onClick={enableSettings ? this.props.showOverlay.bind(this, 'advancedSettings') : () => {}}
/>
</div>
</div>
: null
}
</div>
</section>
</SectionTitleWrapper>
{
this.enabled
? <EnabledContent settings={this.props.settings}
onChangeSetting={this.props.onChangeSetting}
ledgerData={this.props.ledgerData}
showOverlay={this.props.showOverlay}
siteSettings={this.props.siteSettings}
/>
: <DisabledContent />
}
</div>
}
}
const gridStyles = StyleSheet.create({
row1col1: {
gridRow: 1,
gridColumn: 1
},
row1col2: {
gridRow: 1,
gridColumn: 2
},
row1col3: {
gridRow: 1,
gridColumn: 3
}
})
const styles = StyleSheet.create({
flexAlignCenter: {
display: 'flex',
alignItems: 'center'
},
paymentsContainer: {
position: 'relative',
overflowX: 'hidden',
width: '805px',
paddingBottom: '40px' // cf: padding of .prefTabContainer
},
titleWrapper: {
display: 'grid',
gridTemplateColumns: '1fr 1fr 1fr',
alignItems: 'center',
width: '100%',
padding: `0 ${globalStyles.spacing.panelPadding}`
},
titleWrapper__title: {
position: 'relative',
right: globalStyles.spacing.panelPadding
},
titleWrapper__logo: {
width: '40px'
},
titleWrapper__switchWrap: {
display: 'flex',
alignItems: 'center',
width: '100%'
},
switchWrap__label: {
color: '#999',
fontWeight: 'bold'
},
switchWrap__label_left: {
paddingRight: '.75ch !important'
},
switchWrap__label_right: {
// TODO: Add 'position: relative' and 'bottom: 1px' for macOS (en_US) only.
paddingLeft: '.75ch !important',
color: globalStyles.color.braveOrange
},
switchWrap__right: {
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
width: `calc(100% + ${globalStyles.spacing.panelPadding})`
},
// Auto suggest switch
switchWrap__autoSuggestSwitch: {
// TODO: Refactor switchControls.less
position: 'relative',
right: '5px',
top: '1px'
},
autoSuggestSwitch__subtext: {
fontSize: globalStyles.fontSize.settingItemSubtext
},
autoSuggestSwitch__moreInfo: {
color: globalStyles.color.commonTextColor
},
autoSuggestSwitch__moreInfoBtnSuggest: {
// TODO: refactor preferences.less to remove !important
':hover': {
textDecoration: 'none !important'
}
},
// History and settings icons
switchWrap__mainIconsRight: {
position: 'relative',
top: '3.5px'
},
switchWrap__mainIcons: {
backgroundColor: globalStyles.color.braveOrange,
width: '25px',
height: '26px',
display: 'inline-block',
position: 'relative',
':hover': {
backgroundColor: globalStyles.color.braveDarkOrange
}
},
mainIcons__historyIcon: {
right: '5px',
WebkitMaskImage: `url(${historyIcon})`,
':hover': {
backgroundColor: globalStyles.color.braveDarkOrange
}
},
mainIcons__historyDisabled: {
backgroundColor: globalStyles.color.chromeTertiary,
cursor: 'default',
':hover': {
backgroundColor: globalStyles.color.chromeTertiary
}
},
mainIcons__settingsIcon: {
WebkitMaskImage: `url(${settingsIcon})`,
':hover': {
backgroundColor: globalStyles.color.braveDarkOrange
}
},
mainIcons__settingsIconDisabled: {
backgroundColor: globalStyles.color.chromeTertiary,
cursor: 'default',
':hover': {
backgroundColor: globalStyles.color.chromeTertiary
}
},
paymentHistoryOverlay__header: {
paddingLeft: `${paymentStylesVariables.spacing.paymentHistoryTablePadding} !important`
},
paymentHistoryOverlay__body: {
background: '#fff',
height: '300px',
overflowY: 'auto',
padding: '0 !important'
},
paymentHistoryOverlay__footer: {
display: 'block !important',
paddingLeft: `${paymentStylesVariables.spacing.paymentHistoryTablePadding} !important`,
paddingTop: '10px !important',
paddingBottom: '10px !important'
},
paymentHistoryOverlay__title: {
// TODO: refactor preferences.less to remove !important
color: `${globalStyles.color.braveMediumOrange} !important`,
textIndent: '0 !important'
}
})
module.exports = PaymentsTab