Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds captcha error flow #721

Merged
merged 3 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deps = {
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@9a4d0e00d78343de8863d60657727ae4eb5d6321",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@cb66ca61a15b3fe42783e322a5d02be6dae2d5b6",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@86aafe2ef89835ae71c9ed7c2527e3bb3000930e",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@9b119931c702d55be994117eb505d56310720b1d",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@adeff3254bb90ccdc9699040d5a4e1cd6b8393b7",
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ void CustomizeWebUIHTMLSource(const std::string &name, content::WebUIDataSource*
{ "proveHuman", IDS_BRAVE_REWARDS_LOCAL_PROVE_HUMAN },
{ "serverNotResponding", IDS_BRAVE_REWARDS_LOCAL_SERVER_NOT_RESPONDING },
{ "uhOh", IDS_BRAVE_REWARDS_LOCAL_UH_OH },
{ "grantGoneTitle", IDS_BRAVE_REWARDS_LOCAL_GRANT_GONE_TITLE },
{ "grantGoneButton", IDS_BRAVE_REWARDS_LOCAL_GRANT_GONE_BUTTON },
{ "grantGoneText", IDS_BRAVE_REWARDS_LOCAL_GRANT_GONE_TEXT },
{ "grantGeneralErrorTitle", IDS_BRAVE_REWARDS_LOCAL_GENERAL_GRANT_ERROR_TITLE },
{ "grantGeneralErrorButton", IDS_BRAVE_REWARDS_LOCAL_GENERAL_GRANT_ERROR_BUTTON },
{ "grantGeneralErrorText", IDS_BRAVE_REWARDS_LOCAL_GENERAL_GRANT_ERROR_TEXT },

{ "about", IDS_BRAVE_UI_ABOUT },
{ "accept", IDS_BRAVE_UI_ACCEPT },
Expand Down
11 changes: 7 additions & 4 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,13 @@ void RewardsServiceImpl::OnGrantFinish(ledger::Result result,
const ledger::Grant& grant) {
ledger::BalanceReportInfo report_info;
auto now = base::Time::Now();
ledger_->SetBalanceReportItem(GetPublisherMonth(now),
GetPublisherYear(now),
ledger::ReportType::GRANT,
grant.probi);
if (result == ledger::Result::LEDGER_OK) {
ledger_->SetBalanceReportItem(GetPublisherMonth(now),
GetPublisherYear(now),
ledger::ReportType::GRANT,
grant.probi);
}

TriggerOnGrantFinish(result, grant);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,9 @@
"grantNotification": {
"message": "You have a grant waiting for you.",
"description": ""
},
"braveRewardsCreatingText": {
"message": "Creating wallet",
"description": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ interface Props extends RewardsExtension.ComponentProps {

interface State {
windowId: number
creating: boolean
}

export class RewardsPanel extends React.Component<Props, State> {
constructor (props: Props) {
super(props)
this.state = {
windowId: -1
windowId: -1,
creating: false
}
}

Expand All @@ -39,6 +41,16 @@ export class RewardsPanel extends React.Component<Props, State> {
) {
this.getTabData()
}

if (
this.state.creating &&
!prevProps.rewardsPanelData.walletCreateFailed &&
this.props.rewardsPanelData.walletCreateFailed
) {
this.setState({
creating: false
})
}
}

getTabData () {
Expand Down Expand Up @@ -69,16 +81,30 @@ export class RewardsPanel extends React.Component<Props, State> {
})
}

get actions () {
return this.props.actions
}

onCreate = () => {
this.setState({
creating: true
})
this.actions.createWallet()
}

render () {
const { rewardsPanelData, actions } = this.props
const { walletCreateFailed, walletCreated } = this.props.rewardsPanelData

return (
<>
{
!rewardsPanelData.walletCreated
!walletCreated
? <PanelWelcome
error={walletCreateFailed}
creating={this.state.creating}
variant={'two'}
optInAction={actions.createWallet}
optInAction={this.onCreate}
optInErrorAction={this.onCreate}
moreLink={this.openRewards}
/>
: <Panel windowId={this.state.windowId} />
Expand Down
76 changes: 65 additions & 11 deletions components/brave_rewards/ui/components/grant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import * as rewardsActions from '../actions/rewards_actions'
import { getLocale } from '../../../common/locale'
import { convertProbiToFixed } from '../utils'
import GrantError from 'brave-ui/features/rewards/grantError'

interface State {
grantShow: boolean
Expand Down Expand Up @@ -47,7 +48,7 @@ class Grant extends React.Component<Props, State> {
this.actions.onResetGrant()
}

onSuccess = () => {
onFinish = () => {
this.setState({
grantShow: false
})
Expand All @@ -58,6 +59,65 @@ class Grant extends React.Component<Props, State> {
this.actions.solveGrantCaptcha(x, y)
}

grantCaptcha = () => {
const { grant } = this.props.rewardsData

if (!grant) {
return
}

if (grant.status === 'grantGone') {
return (
<GrantWrapper
onClose={this.onFinish}
title={getLocale('grantGoneTitle')}
text={''}
>
<GrantError
buttonText={getLocale('grantGoneButton')}
text={getLocale('grantGoneText')}
onButtonClick={this.onFinish}
/>
</GrantWrapper>
)
}

if (grant.status === 'generalError') {
return (
<GrantWrapper
onClose={this.onGrantHide}
title={getLocale('grantGeneralErrorTitle')}
text={''}
>
<GrantError
buttonText={getLocale('grantGeneralErrorButton')}
text={getLocale('grantGeneralErrorText')}
onButtonClick={this.onGrantHide}
/>
</GrantWrapper>
)
}

if (!grant.captcha || !grant.hint) {
return
}

return (
<GrantWrapper
onClose={this.onGrantHide}
title={grant.status === 'wrongPosition' ? getLocale('notQuite') : getLocale('almostThere')}
text={getLocale('proveHuman')}
>
<GrantCaptcha
onSolution={this.onSolution}
dropBgImage={grant.captcha}
hint={grant.hint}
isWindows={navigator.platform === 'Win32'}
/>
</GrantWrapper>
)
}

render () {
const { grant } = this.props.rewardsData

Expand All @@ -78,24 +138,18 @@ class Grant extends React.Component<Props, State> {
: null
}
{
!grant.expiryTime && grant.captcha && grant.hint
? <GrantWrapper
onClose={this.onGrantHide}
title={grant.status === 'wrongPosition' ? getLocale('notQuite') : getLocale('almostThere')}
text={getLocale('proveHuman')}
>
<GrantCaptcha onSolution={this.onSolution} dropBgImage={grant.captcha} hint={grant.hint} isWindows={navigator.platform === 'Win32'} />
</GrantWrapper>
!grant.expiryTime
? this.grantCaptcha()
: null
}
{
grant.expiryTime
? <GrantWrapper
onClose={this.onSuccess}
onClose={this.onFinish}
title={'It’s your lucky day!'}
text={'Your token grant is on its way.'}
>
<GrantComplete onClose={this.onSuccess} amount={tokens} date={new Date(grant.expiryTime).toLocaleDateString()} />
<GrantComplete onClose={this.onFinish} amount={tokens} date={new Date(grant.expiryTime).toLocaleDateString()} />
</GrantWrapper>
: null
}
Expand Down
24 changes: 23 additions & 1 deletion components/brave_rewards/ui/reducers/grant_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const grantReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
}
chrome.send('brave_rewards.getWalletProperties', [])
}
} else {
} else if (properties.status === 6) {
state = { ...state }
if (state.grant) {
let grant = state.grant
Expand All @@ -114,6 +114,28 @@ const grantReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
}
}
chrome.send('brave_rewards.getGrantCaptcha', [])
} else if (properties.status === 13) {
state = { ...state }
if (state.grant) {
let grant = state.grant
grant.status = 'grantGone'

state = {
...state,
grant
}
}
} else {
state = { ...state }
if (state.grant) {
let grant = state.grant
grant.status = 'generalError'

state = {
...state,
grant
}
}
}
break
}
Expand Down
15 changes: 11 additions & 4 deletions components/definitions/rewards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ declare namespace Rewards {
}

export enum Result {
OK = 0,
ERROR = 1,
LEDGER_OK = 0,
LEDGER_ERROR = 1,
NO_PUBLISHER_STATE = 2,
NO_LEDGER_STATE = 3,
INVALID_PUBLISHER_STATE = 4,
INVALID_LEDGER_STATE = 5,
CAPTCHA_FAILED = 6
CAPTCHA_FAILED = 6,
NO_PUBLISHER_LIST = 7,
TOO_MANY_RESULTS = 8,
NOT_FOUND = 9,
REGISTRATION_VERIFICATION_FAILED = 10,
BAD_REGISTRATION_RESPONSE = 11,
WALLET_CREATED = 12,
GRANT_NOT_FOUND = 13
}

export type AddressesType = 'BTC' | 'ETH' | 'BAT' | 'LTC'
Expand Down Expand Up @@ -65,7 +72,7 @@ declare namespace Rewards {
expiryTime: number
captcha?: string
hint?: string
status?: 'wrongPosition' | 'serverError' | number | null
status?: 'wrongPosition' | 'grantGone' | 'generalError' | number | null
}

export interface WalletProperties {
Expand Down
6 changes: 6 additions & 0 deletions components/resources/brave_components_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@
<message name="IDS_BRAVE_REWARDS_LOCAL_NOT_QUITE" desc="">Hmmm…not quite.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_SERVER_NOT_RESPONDING" desc="">The Brave Rewards server is not responding. We will fix this as soon as possible.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_UH_OH" desc="">Uh oh!</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_GRANT_GONE_TITLE" desc="">Grant gone!</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_GRANT_GONE_BUTTON" desc="">OK</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_GRANT_GONE_TEXT" desc="">Sorry, but this grant is already expired.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_GENERAL_GRANT_ERROR_TITLE" desc="">Ups, something is wrong!</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_GENERAL_GRANT_ERROR_BUTTON" desc="">Ok</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_GENERAL_GRANT_ERROR_TEXT" desc="">We detect some problem, please try again later.</message>

<!-- WebUI brave ui resources -->
<message name="IDS_BRAVE_UI_ABOUT" desc="">about</message>
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 @@ -270,7 +270,7 @@
"babel-preset-react": "^6.24.1",
"babel-preset-react-optimize": "^1.0.1",
"babel-preset-stage-0": "^6.24.1",
"brave-ui": "^0.29.0",
"brave-ui": "^0.29.3",
"css-loader": "^0.28.9",
"csstype": "^2.5.5",
"emptykit.css": "^1.0.1",
Expand Down