Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Adds broken seed overlay
Browse files Browse the repository at this point in the history
Resolves #13424

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Mar 22, 2018
1 parent 985ecbb commit 171418a
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 64 deletions.
17 changes: 16 additions & 1 deletion app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const updateState = require('../../common/state/updateState')
// Constants
const settings = require('../../../js/constants/settings')
const messages = require('../../../js/constants/messages')
const ledgerStatuses = require('../../common/constants/ledgerStatuses')

// Utils
const config = require('../../../js/constants/buildConfig')
Expand Down Expand Up @@ -179,11 +180,25 @@ const paymentPresent = (state, tabId, present) => {
}

appActions.onPromotionGet()

state = checkSeed(state)
getPublisherTimestamp(true)
} else if (balanceTimeoutId) {
clearTimeout(balanceTimeoutId)
balanceTimeoutId = false
}

return state
}

const checkSeed = (state) => {
const seed = ledgerState.getInfoProp(state, 'passphrase')

if (!client.isValidPassPhrase(seed)) {
state = ledgerState.setAboutProp(state, 'status', ledgerStatuses.CORRUPTED)
}

return state
}

const getPublisherTimestamp = (updateList) => {
Expand Down Expand Up @@ -1629,7 +1644,7 @@ const getStateInfo = (state, parsedData) => {
const oldReconcileStamp = ledgerState.getInfoProp(state, 'reconcileStamp')

if (oldReconcileStamp && newInfo.reconcileStamp > oldReconcileStamp) {
state = ledgerState.setAboutProp(state, 'status', 'contributionInProgress')
state = ledgerState.setAboutProp(state, 'status', ledgerStatuses.IN_PROGRESS)
}

let passphrase = ledgerClient.prototype.getWalletPassphrase(parsedData)
Expand Down
2 changes: 1 addition & 1 deletion app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ const ledgerReducer = (state, action, immutableAction) => {
}
case appConstants.APP_LEDGER_PAYMENTS_PRESENT:
{
ledgerApi.paymentPresent(state, action.get('tabId'), action.get('present'))
state = ledgerApi.paymentPresent(state, action.get('tabId'), action.get('present'))
break
}
case appConstants.APP_ON_ADD_FUNDS_CLOSED:
Expand Down
10 changes: 10 additions & 0 deletions app/common/constants/ledgerStatuses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* 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 statuses = {
CORRUPTED: 'corruptedSeed',
IN_PROGRESS: 'contributionInProgress'
}

module.exports = statuses
5 changes: 5 additions & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ contributionTime=Contribution Time
copied=Copied!
copy=Copy
copyToClipboard.title=Copy to clipboard
corruptedOverlayTitle=Hello!
corruptedOverlayMessage=Unfortunately your active wallet has been corrupted.
corruptedOverlayText=You must recover your backup wallet with your recovery keys before any transactions can be processed. We apologize for the inconvenience.
corruptedOverlayFAQ=View the Brave Payments FAQ…
corruptedOverlayButton=Recover your Brave Wallet
createdWalletStatus=Your wallet is ready!
createWallet=create wallet
createWalletStatus=Click the Create Wallet button to get started.
Expand Down
5 changes: 4 additions & 1 deletion app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ var rendererIdentifiers = function () {
'promotionGeneralErrorText',
'promotionClaimedErrorMessage',
'promotionClaimedErrorText',
'promotionClaimedErrorTitle'
'promotionClaimedErrorTitle',
'corruptedOverlayTitle',
'corruptedOverlayMessage',
'corruptedOverlayText'
].concat(countryCodes).concat(availableLanguages)
}

Expand Down
187 changes: 130 additions & 57 deletions app/renderer/components/preferences/payment/enabledContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,48 @@ const {StyleSheet, css} = require('aphrodite/no-important')
const addMonths = require('date-fns/add_months')
const Immutable = require('immutable')

// util
const {batToCurrencyString, formatCurrentBalance, formattedDateFromTimestamp, walletStatus} = require('../../../../common/lib/ledgerUtil')
const {l10nErrorText} = require('../../../../common/lib/httpUtil')
const ledgerUtil = require('../../../../common/lib/ledgerUtil')
const {changeSetting} = require('../../../lib/settingsUtil')
const settings = require('../../../../../js/constants/settings')
const locale = require('../../../../../js/l10n')

// State
const ledgerState = require('../../../../common/state/ledgerState')

// components
// Components
const ImmutableComponent = require('../../immutableComponent')
const BrowserButton = require('../../common/browserButton')
const {FormTextbox} = require('../../common/textbox')
const {FormDropdown} = require('../../common/dropdown')
const LedgerTable = require('./ledgerTable')

// style
const globalStyles = require('../../styles/global')
const {paymentStylesVariables} = require('../../styles/payment')
const closeButton = require('../../../../../img/toolbar/stoploading_btn.svg')
const cx = require('../../../../../js/lib/classSet')
// State
const ledgerState = require('../../../../common/state/ledgerState')

// Actions
const appActions = require('../../../../../js/actions/appActions')

// Constants
const ledgerStatuses = require('../../../../common/constants/ledgerStatuses')
const settings = require('../../../../../js/constants/settings')

// Utils
const {
batToCurrencyString,
formatCurrentBalance,
formattedDateFromTimestamp,
walletStatus
} = require('../../../../common/lib/ledgerUtil')
const {l10nErrorText} = require('../../../../common/lib/httpUtil')
const ledgerUtil = require('../../../../common/lib/ledgerUtil')
const {changeSetting} = require('../../../lib/settingsUtil')
const locale = require('../../../../../js/l10n')

// Styles
const globalStyles = require('../../styles/global')
const cx = require('../../../../../js/lib/classSet')
const {paymentStylesVariables} = require('../../styles/payment')
const closeButton = require('../../../../../img/toolbar/stoploading_btn.svg')

// TODO: report when funds are too low
// TODO: support non-USD currency
class EnabledContent extends ImmutableComponent {
constructor (props) {
super(props)
this.claimButton = this.claimButton.bind(this)
this.onClaimClick = this.onClaimClick.bind(this)
this.closeClick = this.closeClick.bind(this)
this.closePromotionClick = this.closePromotionClick.bind(this)
}

walletButton () {
Expand Down Expand Up @@ -139,7 +146,7 @@ class EnabledContent extends ImmutableComponent {
let prevReconcileDateValue
let text

if (ledgerData.get('status') === 'contributionInProgress') {
if (ledgerData.get('status') === ledgerStatuses.IN_PROGRESS) {
text = 'paymentInProgress'
} else if (!walletCreated || !walletHasReconcile || !walletHasTransactions) {
text = 'noPaymentHistory'
Expand Down Expand Up @@ -201,7 +208,7 @@ class EnabledContent extends ImmutableComponent {
</section>
}

closeClick () {
closePromotionClick () {
const promo = this.props.ledgerData.get('promotion') || Immutable.Map()
const status = promo.get('promotionStatus')
if (status && !promo.has('claimedTimestamp')) {
Expand All @@ -215,55 +222,98 @@ class EnabledContent extends ImmutableComponent {
}
}

closeStatusClick () {

}

statusMessage () {
const promo = this.props.ledgerData.get('promotion') || Immutable.Map()
const status = this.props.ledgerData.get('status') || ''
const successText = promo.getIn(['panel', 'successText'])
let status = promo.get('promotionStatus')
const promotionStatus = promo.get('promotionStatus')
let isPromotion = true

if ((!successText || !promo.has('claimedTimestamp')) && !status) {
return
if ((!successText || !promo.has('claimedTimestamp')) && !promotionStatus) {
isPromotion = false
if (status.length === 0) {
return
}
}

let title = successText.get('title')
let message = successText.get('message')
let text = promo.getIn(['panel', 'disclaimer'])
let title, message, text, rightButton, leftButton

if (status) {
if (isPromotion) {
title = successText.get('title')
message = successText.get('message')
text = promo.getIn(['panel', 'disclaimer'])
rightButton = <BrowserButton
secondaryColor
l10nId={'paymentHistoryOKText'}
custom={styles.enabledContent__overlay_button}
onClick={this.closePromotionClick}
/>

if (promotionStatus) {
switch (promotionStatus) {
case 'generalError':
{
title = locale.translation('promotionGeneralErrorTitle')
message = locale.translation('promotionGeneralErrorMessage')
text = locale.translation('promotionGeneralErrorText')
break
}
case 'expiredError':
{
title = locale.translation('promotionClaimedErrorTitle')
message = locale.translation('promotionClaimedErrorMessage')
text = locale.translation('promotionClaimedErrorText')
break
}
}
}
} else {
switch (status) {
case 'generalError':
case ledgerStatuses.CORRUPTED:
{
title = locale.translation('promotionGeneralErrorTitle')
message = locale.translation('promotionGeneralErrorMessage')
text = locale.translation('promotionGeneralErrorText')
title = locale.translation('corruptedOverlayTitle')
message = locale.translation('corruptedOverlayMessage')
text = locale.translation('corruptedOverlayText')
leftButton = <a
data-l10n-id='corruptedOverlayFAQ'
className={css(styles.enabledContent__overlay_link)}
href='https://brave.com/faq-payments#corrupted-wallet'
target='_blank'
/>
rightButton = <BrowserButton
secondaryColor
l10nId={'corruptedOverlayButton'}
custom={styles.enabledContent__overlay_button}
onClick={this.closeStatusClick}
/>
break
}
case 'expiredError':
default:
{
title = locale.translation('promotionClaimedErrorTitle')
message = locale.translation('promotionClaimedErrorMessage')
text = locale.translation('promotionClaimedErrorText')
break
return
}
}
}

return <div className={cx({[css(styles.enabledContent__grant)]: true, 'enabledContent__grant': true})}>
return <div className={cx({[css(styles.enabledContent__overlay)]: true, 'enabledContent__overlay': true})}>
<div
className={css(styles.enabledContent__grant_close)}
onClick={this.closeClick}
className={css(styles.enabledContent__overlay_close)}
onClick={this.closePromotionClick}
/>
<p className={css(styles.enabledContent__grant_title)}>
<span className={css(styles.enabledContent__grant_bold)}>{title}</span> {message}
<p className={css(styles.enabledContent__overlay_title)}>
<span className={css(styles.enabledContent__overlay_bold)}>{title}</span> {message}
</p>
<p className={css(styles.enabledContent__grant_text)}>
<p className={css(styles.enabledContent__overlay_text)}>
{text}
</p>
<BrowserButton
secondaryColor
l10nId={'paymentHistoryOKText'}
custom={styles.enabledContent__grant_button}
onClick={this.closeClick}
/>
<div className={css(styles.enabledContent__overlay_buttons)}>
<div className={css(gridStyles.row1col1, styles.enabledContent__overlay_buttons_left)}>{leftButton}</div>
<div className={css(gridStyles.row1col2, styles.enabledContent__overlay_buttons_right)}>{rightButton}</div>
</div>
</div>
}

Expand Down Expand Up @@ -465,7 +515,7 @@ const styles = StyleSheet.create({
padding: '0 10px'
},

enabledContent__grant: {
enabledContent__overlay: {
position: 'absolute',
zIndex: 3,
top: 0,
Expand All @@ -474,12 +524,12 @@ const styles = StyleSheet.create({
minHeight: '159px',
background: '#f3f3f3',
borderRadius: '8px',
padding: '30px 50px 20px',
padding: '27px 50px 17px',
boxSizing: 'border-box',
boxShadow: '4px 6px 3px #dadada'
},

enabledContent__grant_close: {
enabledContent__overlay_close: {
position: 'absolute',
right: '15px',
top: '15px',
Expand All @@ -495,29 +545,52 @@ const styles = StyleSheet.create({
}
},

enabledContent__grant_title: {
enabledContent__overlay_title: {
color: '#5f5f5f',
fontSize: '20px',
display: 'block',
marginBottom: '10px'
},

enabledContent__grant_bold: {
enabledContent__overlay_bold: {
color: '#ff5500'
},

enabledContent__grant_text: {
enabledContent__overlay_text: {
fontSize: '16px',
color: '#828282',
maxWidth: '700px',
lineHeight: '25px',
padding: '5px'
padding: '5px 5px 5px 0'
},

enabledContent__grant_button: {
enabledContent__overlay_buttons: {
display: 'grid',
gridTemplateColumns: '1fr 1fr'
},

enabledContent__overlay_buttons_left: {
marginLeft: 0
},

enabledContent__overlay_buttons_right: {
marginRight: 0
},

enabledContent__overlay_button: {
float: 'right'
},

enabledContent__overlay_link: {
color: '#5f5f5f',
fontSize: '16px',
textDecoration: 'none',

':hover': {
textDecoration: 'underline'
}
},

enabledContent__walletBar: {
display: 'grid',
gridTemplateColumns: '1fr 1fr 1fr',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"aphrodite": "1.1.0",
"async": "^2.0.1",
"bat-balance": "^1.0.7",
"bat-client": "^2.0.11",
"bat-client": "^2.1.1",
"bat-publisher": "^2.0.13",
"bignumber.js": "^4.0.4",
"bloodhound-js": "brave/bloodhound",
Expand Down
Loading

0 comments on commit 171418a

Please sign in to comment.