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

Commit

Permalink
Merge pull request #15003 from NejcZdovc/captcha2
Browse files Browse the repository at this point in the history
Use v2 promotion endpoints
  • Loading branch information
bsclifton committed Aug 19, 2018
1 parent 45a4f0e commit b511d2e
Show file tree
Hide file tree
Showing 10 changed files with 4,173 additions and 4,150 deletions.
8 changes: 6 additions & 2 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2944,11 +2944,13 @@ const getCaptcha = (state) => {
return
}

appActions.onCaptchaResponse(null, body)
if (response && response.headers && response.headers['captcha-hint']) {
appActions.onCaptchaResponse(null, body, response.headers['captcha-hint'])
}
})
}

const onCaptchaResponse = (state, response, body) => {
const onCaptchaResponse = (state, response, body, hint) => {
if (body == null) {
if (response && response.get('statusCode') === 429) {
return ledgerState.setPromotionProp(state, 'promotionStatus', promotionStatuses.CAPTCHA_BLOCK)
Expand All @@ -2966,6 +2968,8 @@ const onCaptchaResponse = (state, response, body) => {
state = ledgerState.setPromotionProp(state, 'promotionStatus', promotionStatuses.CAPTCHA_CHECK)
}

state = ledgerState.setPromotionProp(state, 'captchaHint', hint || '')

return state
}

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 @@ -433,7 +433,7 @@ const ledgerReducer = (state, action, immutableAction) => {
}
case appConstants.APP_ON_CAPTCHA_RESPONSE:
{
state = ledgerApi.onCaptchaResponse(state, action.get('response'), action.get('body'))
state = ledgerApi.onCaptchaResponse(state, action.get('response'), action.get('body'), action.get('hint'))
break
}
case appConstants.APP_ON_CAPTCHA_CLOSE:
Expand Down
5 changes: 5 additions & 0 deletions app/common/state/ledgerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ const ledgerState = {
const claim = state.getIn(['ledger', 'promotion', 'claimedTimestamp']) || null
const status = state.getIn(['ledger', 'promotion', 'promotionStatus']) || null
const captcha = state.getIn(['ledger', 'promotion', 'captcha']) || null
const captchaHint = state.getIn(['ledger', 'promotion', 'captchaHint']) || null

if (claim) {
promotion = promotion.set('claimedTimestamp', claim)
Expand All @@ -572,6 +573,10 @@ const ledgerState = {
promotion = promotion.set('captcha', captcha)
}

if (captchaHint) {
promotion = promotion.set('captchaHint', captchaHint)
}

return promotion
},

Expand Down
2 changes: 1 addition & 1 deletion app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ promotionCaptchaTitle=Almost there!
promotionCaptchaErrorTitle=Hmmm…not quite.
promotionCaptchaErrorText=Please try again.
promotionCaptchaText=First, prove you are human:
promotionCaptchaMessage=Drag and drop the BAT logo onto the target
promotionCaptchaMessageNew=Drag and drop the BAT logo onto the <b>{{hint}}</b> target
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.
Expand Down
7 changes: 6 additions & 1 deletion app/renderer/components/preferences/payment/captcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ class Captcha extends ImmutableComponent {
<img src={arrowIcon} draggable='false' className={css(styles.enabledContent__captcha__arrow, styles.disableDND)} />
</div>
<div draggable='false' onDrop={this.onCaptchaDrop} onDragOver={this.preventDefault} className={css(styles.enabledContent__captcha__drop, styles.disableDND)} />
<p draggable='false' className={css(styles.enabledContent__overlay_text, styles.disableDND)} data-l10n-id='promotionCaptchaMessage' />
<p
draggable='false'
className={css(styles.enabledContent__overlay_text, styles.disableDND)}
data-l10n-id='promotionCaptchaMessageNew'
data-l10n-args={JSON.stringify({hint: this.props.promo.get('captchaHint')})}
/>
</div>
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ AppStore
},
promotion: {
activeState: string,
captchaHint: string,
claimedTimestamp: number,
minimumReconcileTimestamp: number,
promotionId: number,
Expand Down
5 changes: 3 additions & 2 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1877,11 +1877,12 @@ const appActions = {
})
},

onCaptchaResponse: function (response, body) {
onCaptchaResponse: function (response, body, hint) {
dispatch({
actionType: appConstants.APP_ON_CAPTCHA_RESPONSE,
body,
response
response,
hint
})
},

Expand Down
Loading

0 comments on commit b511d2e

Please sign in to comment.