forked from brave/browser-laptop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves brave#14188 Auditors: Test Plan:
- Loading branch information
Showing
15 changed files
with
430 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* 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 = { | ||
GENERAL_ERROR: 'generalError', | ||
PROMO_EXPIRED: 'expiredError', | ||
CAPTCHA_CHECK: 'captchaCheck', | ||
CAPTCHA_ERROR: 'captchaError' | ||
} | ||
|
||
module.exports = statuses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
/* 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 {StyleSheet, css} = require('aphrodite/no-important') | ||
|
||
// Components | ||
const ImmutableComponent = require('../../immutableComponent') | ||
|
||
// Actions | ||
const appActions = require('../../../../../js/actions/appActions') | ||
|
||
// Constants | ||
const promotionStatuses = require('../../../../common/constants/promotionStatuses') | ||
|
||
// Styles | ||
const cx = require('../../../../../js/lib/classSet') | ||
const closeButton = require('../../../../../img/toolbar/stoploading_btn.svg') | ||
const dragIcon = require('../../../../extensions/brave/img/ledger/BAT_captcha_dragicon.png') | ||
|
||
// TODO: report when funds are too low | ||
class Captcha extends ImmutableComponent { | ||
constructor (props) { | ||
super(props) | ||
this.onCaptchaDrop = this.onCaptchaDrop.bind(this) | ||
this.onCaptchaDrag = this.onCaptchaDrag.bind(this) | ||
this.getText = this.getText.bind(this) | ||
this.captchaBox = null | ||
this.dndStartPosition = { | ||
x: 0, | ||
y: 0, | ||
width: 0, | ||
height: 0 | ||
} | ||
} | ||
|
||
onCaptchaDrop (event) { | ||
event.preventDefault() | ||
const target = this.captchaBox.getBoundingClientRect() | ||
console.log('start X', this.dndStartPosition.x) | ||
console.log('start Y', this.dndStartPosition.y) | ||
console.log('clientX', event.clientX) | ||
console.log('clientY', event.clientY) | ||
console.log('X', (event.clientX - target.left)) | ||
console.log('Y', (event.clientY - target.top)) | ||
console.log('box', target) | ||
|
||
const x = event.clientX - target.left - this.dndStartPosition.x + (this.dndStartPosition.height / 2) | ||
const y = event.clientY - target.top - this.dndStartPosition.y + (this.dndStartPosition.width / 2) | ||
|
||
appActions.onPromotionClaim(x, y) | ||
} | ||
|
||
onCaptchaDrag (event) { | ||
const target = event.target.getBoundingClientRect() | ||
this.dndStartPosition = { | ||
x: event.clientX - target.left, | ||
y: event.clientY - target.top, | ||
width: target.width, | ||
height: target.height | ||
} | ||
} | ||
|
||
preventDefault (event) { | ||
event.preventDefault() | ||
} | ||
|
||
getText () { | ||
if (this.props.promo.get('promotionStatus') === promotionStatuses.CAPTCHA_ERROR) { | ||
return { | ||
title: 'promotionCaptchaErrorTitle', | ||
text: 'promotionCaptchaErrorText' | ||
} | ||
} | ||
|
||
return { | ||
title: 'promotionCaptchaTitle', | ||
text: 'promotionCaptchaText' | ||
} | ||
} | ||
|
||
render () { | ||
const text = this.getText() | ||
|
||
return <div | ||
className={cx({ | ||
[css(styles.enabledContent__overlay)]: true, | ||
[css(styles.enabledContent__captcha)]: true, | ||
'enabledContent__overlay': true | ||
})} | ||
style={{'background': `url(${this.props.promo.get('captcha')}) no-repeat top left #f3f3f3`}} | ||
ref={(node) => { this.captchaBox = node }} | ||
> | ||
{ | ||
<div | ||
className={css(styles.enabledContent__overlay_close)} | ||
onClick={this.closePromotionClick} | ||
/> | ||
} | ||
<p className={css(styles.enabledContent__overlay_title)}> | ||
<span className={css(styles.enabledContent__overlay_bold)} data-l10n-id={text.title} /> | ||
<span data-l10n-id={text.text} /> | ||
</p> | ||
<img onDragStart={this.onCaptchaDrag} src={dragIcon} draggable='true' className={css(styles.enabledContent__captcha__image)} /> | ||
<div onDrop={this.onCaptchaDrop} onDragOver={this.preventDefault} className={css(styles.enabledContent__captcha__drop)} /> | ||
<p className={css(styles.enabledContent__overlay_text)} data-l10n-id='promotionCaptchaMessage' /> | ||
</div> | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
enabledContent__overlay: { | ||
position: 'absolute', | ||
zIndex: 3, | ||
top: 0, | ||
left: 0, | ||
width: '100%', | ||
minHeight: '159px', | ||
background: '#f3f3f3', | ||
borderRadius: '8px', | ||
padding: '27px 50px 17px', | ||
boxSizing: 'border-box', | ||
boxShadow: '4px 6px 3px #dadada' | ||
}, | ||
|
||
enabledContent__overlay_close: { | ||
position: 'absolute', | ||
right: '15px', | ||
top: '15px', | ||
height: '15px', | ||
width: '15px', | ||
cursor: 'pointer', | ||
|
||
background: `url(${closeButton}) center no-repeat`, | ||
backgroundSize: `15px`, | ||
|
||
':focus': { | ||
outline: 'none' | ||
} | ||
}, | ||
|
||
enabledContent__overlay_title: { | ||
color: '#5f5f5f', | ||
fontSize: '20px', | ||
display: 'block', | ||
marginBottom: '10px' | ||
}, | ||
|
||
enabledContent__overlay_bold: { | ||
color: '#ff5500', | ||
paddingRight: '5px' | ||
}, | ||
|
||
enabledContent__overlay_text: { | ||
fontSize: '16px', | ||
color: '#828282', | ||
maxWidth: '700px', | ||
lineHeight: '25px', | ||
padding: '5px 5px 5px 0', | ||
marginTop: '10px' | ||
}, | ||
|
||
enabledContent__captcha: { | ||
// TODO we need to make sure that text is not in DND zone | ||
width: '805px', | ||
height: '180px', | ||
padding: '20px' | ||
}, | ||
|
||
enabledContent__captcha__drop: { | ||
position: 'absolute', | ||
width: '400px', | ||
height: '180px', | ||
top: 0, | ||
right: 0, | ||
zIndex: 2, | ||
display: 'block' | ||
}, | ||
|
||
enabledContent__captcha__image: { | ||
marginTop: '10px' | ||
} | ||
}) | ||
|
||
module.exports = Captcha |
Oops, something went wrong.