Skip to content

Commit

Permalink
Adds some additional banners
Browse files Browse the repository at this point in the history
Fixed recovery promotional removal
Removes staging flag
Fixes fake visits

Resolves brave#12131
Resolves brave#12098
Resolves brave#11394

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Nov 29, 2017
1 parent 0147755 commit 17be9ba
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 25 deletions.
24 changes: 19 additions & 5 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const clientOptions = {
server: process.env.LEDGER_SERVER_URL,
createWorker: electron.app.createWorker,
version: 'v2',
environment: 'staging' // TODO remove before merge
environment: process.env.LEDGER_ENVIRONMENT || 'production'
}
const fileTypes = {
bmp: Buffer.from([0x42, 0x4d]),
Expand Down Expand Up @@ -993,6 +993,8 @@ const recoverKeys = (state, useRecoveryKeyFile, key) => {

client.recoverWallet(null, recoveryKey, (err, result) => {
appActions.onWalletRecovery(err, result)
appActions.onPromotionRemoval()
appActions.onPromotionGet()
})

return state
Expand Down Expand Up @@ -2429,17 +2431,29 @@ const claimPromotion = (state) => {
return
}

client.setPromotion(promotion.get('promotionId'), (err) => {
client.setPromotion(promotion.get('promotionId'), (err, _, status) => {
let param = null
if (err) {
console.error(`Problem claiming promotion ${err.toString()}`)
return
param = status
}

appActions.onPromotionResponse()
appActions.onPromotionResponse(param)
})
}

const onPromotionResponse = (state) => {
const onPromotionResponse = (state, status) => {
if (status) {
if (status.get('statusCode') === 422) {
// promotion already claimed
state = ledgerState.setPromotionProp(state, 'promotionStatus', 'expiredError')
} else {
// general error
state = ledgerState.setPromotionProp(state, 'promotionStatus', 'generalError')
}
return state
}

ledgerNotifications.removePromotionNotification(state)
state = ledgerState.setPromotionProp(state, 'claimedTimestamp', new Date().getTime())

Expand Down
8 changes: 7 additions & 1 deletion app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,12 @@ const ledgerReducer = (state, action, immutableAction) => {
}
case appConstants.APP_ON_PROMOTION_RESPONSE:
{
state = ledgerApi.onPromotionResponse(state)
state = ledgerApi.onPromotionResponse(state, action.get('status'))
break
}
case appConstants.APP_ON_PROMOTION_REMOVAL:
{
ledgerNotifications.removePromotionNotification(state)
state = ledgerState.removePromotion(state)
break
}
Expand All @@ -457,6 +458,11 @@ const ledgerReducer = (state, action, immutableAction) => {
ledgerApi.getPromotion(state)
break
}
case appConstants.APP_ON_PROMOTION_CLOSE:
{
state = ledgerState.setPromotionProp(state, 'promotionStatus', null)
break
}
case appConstants.APP_ON_LEDGER_MEDIA_PUBLISHER:
{
state = ledgerApi.onMediaPublisher(
Expand Down
10 changes: 8 additions & 2 deletions app/common/state/ledgerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,16 @@ const ledgerState = {
},

getAboutPromotion: (state) => {
const promotion = ledgerState.getActivePromotion(state)
let promotion = ledgerState.getActivePromotion(state)
const claim = state.getIn(['ledger', 'promotion', 'claimedTimestamp']) || null
const status = state.getIn(['ledger', 'promotion', 'promotionStatus']) || null

if (claim) {
return promotion.set('claimedTimestamp', claim)
promotion = promotion.set('claimedTimestamp', claim)
}

if (status) {
promotion = promotion.set('promotionStatus', status)
}

return promotion
Expand Down
7 changes: 6 additions & 1 deletion app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ printKeys=Print key
privacy=Privacy
privateData=Private Data
privateDataMessage=Clear the following data types when I close Brave
promotionClaimed=Congrats! {{token}} tokens have been added to your wallet.
promotionGeneralErrorMessage=The Brave Payments server is not responding. Please try again later to claim your token grant.
promotionGeneralErrorText=Note: This error could also be caused by a network connection problem.
promotionGeneralErrorTitle=Uh oh.
promotionClaimedErrorMessage=The promotion has ended.
promotionClaimedErrorText=There may be additional Basic Attention Token promotions in the future so stay tuned
promotionClaimedErrorTitle=Sorry!
protocolRegistrationPermission=Protocol registration
publisher=Site
publisherMediaName={{publisherName}} on {{provider}}
Expand Down
9 changes: 8 additions & 1 deletion app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,14 @@ var rendererIdentifiers = function () {
'channelBeta',
'channelDeveloper',
'channelNightly',
'spellCheckLanguages'
'spellCheckLanguages',
// Ledger
'promotionGeneralErrorTitle',
'promotionGeneralErrorMessage',
'promotionGeneralErrorText',
'promotionClaimedErrorMessage',
'promotionClaimedErrorText',
'promotionClaimedErrorTitle'
].concat(countryCodes).concat(availableLanguages)
}

Expand Down
50 changes: 43 additions & 7 deletions app/renderer/components/preferences/payment/enabledContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {l10nErrorText} = require('../../../../common/lib/httpUtil')
const {changeSetting} = require('../../../lib/settingsUtil')
const getSetting = require('../../../../../js/settings').getSetting
const settings = require('../../../../../js/constants/settings')
const locale = require('../../../../../js/l10n')

// components
const ImmutableComponent = require('../../immutableComponent')
Expand All @@ -38,6 +39,7 @@ class EnabledContent extends ImmutableComponent {
super(props)
this.claimButton = this.claimButton.bind(this)
this.onClaimClick = this.onClaimClick.bind(this)
this.closeClick = this.closeClick.bind(this)
}

walletButton () {
Expand Down Expand Up @@ -196,31 +198,65 @@ class EnabledContent extends ImmutableComponent {
}

closeClick () {
appActions.onPromotionRemoval()
const promo = this.props.ledgerData.get('promotion') || Immutable.Map()
const status = promo.get('promotionStatus')
if (status && !promo.has('claimedTimestamp')) {
if (status === 'expiredError') {
appActions.onPromotionRemoval()
} else {
appActions.onPromotionClose()
}
} else {
appActions.onPromotionRemoval()
}
}

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

if (!successText || !promo.has('claimedTimestamp')) {
if ((!successText || !promo.has('claimedTimestamp')) && !status) {
return
}

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

if (status) {
switch (status) {
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
}
}
}

return <div className={cx({[css(styles.enabledContent__grant)]: true, 'enabledContent__grant': true})}>
<div
className={css(styles.enabledContent__grant_close)}
onClick={this.closeClick}
/>
<p className={css(styles.enabledContent__grant_title)}>
<span className={css(styles.enabledContent__grant_bold)}>{ successText.get('title') }</span> { successText.get('message') }
<span className={css(styles.enabledContent__grant_bold)}>{title}</span> {message}
</p>
<p className={css(styles.enabledContent__grant_text)}>
{promo.getIn(['panel', 'disclaimer'])}
{text}
</p>
<BrowserButton
secondaryColor
l10nId={'ok'}
l10nId={'paymentHistoryOKText'}
custom={styles.enabledContent__grant_button}
onClick={this.closeClick}
/>
Expand Down Expand Up @@ -299,7 +335,7 @@ class EnabledContent extends ImmutableComponent {
data-l10n-id={walletStatusText.id}
data-l10n-args={walletStatusText.args ? JSON.stringify(walletStatusText.args) : null}
/>
{this.successMessage()}
{this.statusMessage()}
</div>
<LedgerTable ledgerData={this.props.ledgerData}
settings={this.props.settings}
Expand Down
1 change: 1 addition & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ AppStore
claimedTimestamp: number,
minimumReconcileTimestamp: number,
promotionId: number,
promotionStatus: string,
remindTimestamp: number,
stateWallet: {
disabledWallet: {
Expand Down
11 changes: 9 additions & 2 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1837,9 +1837,10 @@ const appActions = {
})
},

onPromotionResponse: function () {
onPromotionResponse: function (status) {
dispatch({
actionType: appConstants.APP_ON_PROMOTION_RESPONSE
actionType: appConstants.APP_ON_PROMOTION_RESPONSE,
status
})
},

Expand All @@ -1861,6 +1862,12 @@ const appActions = {
})
},

onPromotionClose: function () {
dispatch({
actionType: appConstants.APP_ON_PROMOTION_CLOSE
})
},

onLedgerNotificationInterval: function () {
dispatch({
actionType: appConstants.APP_ON_LEDGER_NOTIFICATION_INTERVAL
Expand Down
1 change: 1 addition & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ const appConstants = {
APP_ON_PROMOTION_REMIND: _,
APP_ON_PROMOTION_REMOVAL: _,
APP_ON_PROMOTION_GET: _,
APP_ON_PROMOTION_CLOSE: _,
APP_ON_LEDGER_NOTIFICATION_INTERVAL: _,
APP_ON_LEDGER_MEDIA_DATA: _,
APP_ON_PRUNE_SYNOPSIS: _,
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"aphrodite": "1.1.0",
"async": "^2.0.1",
"bat-balance": "^1.0.3",
"bat-client": "^2.0.2",
"bat-client": "^2.0.3",
"bat-publisher": "^2.0.0",
"bignumber.js": "^4.0.4",
"bloodhound-js": "brave/bloodhound",
Expand Down
3 changes: 2 additions & 1 deletion test/unit/app/browser/reducers/ledgerReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ describe('ledgerReducer unit tests', function () {
}
fakeLedgerNotifications = {
onPromotionReceived: dummyModifyState,
onInterval: dummyModifyState
onInterval: dummyModifyState,
removePromotionNotification: () => {}
}
mockery.registerMock('../../browser/api/ledger', fakeLedgerApi)
mockery.registerMock('../../common/state/ledgerState', fakeLedgerState)
Expand Down
5 changes: 4 additions & 1 deletion tools/lib/synopsisHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const generateSynopsisVisits = function (synopsis, numPublishers) {
let numVisits = Math.round(Math.random() * 10)

for (let i = 0; i < numVisits; i++) {
synopsis.addVisit(PROTOCOL_PREFIXES[Math.round(Math.random())] + host + '/', Math.round(Math.random() * 60 * 1000))
synopsis.addPublisher(PROTOCOL_PREFIXES[Math.round(Math.random())] + host + '/', {
duration: Math.round(Math.random() * 60 * 1000),
revisitP: false
})
}
})

Expand Down

0 comments on commit 17be9ba

Please sign in to comment.