Skip to content

Commit

Permalink
Adds support for 409 error code for grants
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Dec 21, 2018
1 parent b045822 commit 3dd1294
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 34 deletions.
1 change: 1 addition & 0 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ void CustomizeWebUIHTMLSource(const std::string &name, content::WebUIDataSource*
{ "grantGeneralErrorText", IDS_BRAVE_REWARDS_LOCAL_GENERAL_GRANT_ERROR_TEXT },
{ "walletCorrupted", IDS_BRAVE_REWARDS_LOCAL_WALLET_CORRUPTED },
{ "walletCorruptedNow", IDS_BRAVE_REWARDS_LOCAL_WALLET_CORRUPTED_NOW },
{ "grantAlreadyClaimedText", IDS_BRAVE_REWARDS_LOCAL_GRANT_ALREADY_CLAIMED_TEXT },

{ "about", IDS_BRAVE_UI_ABOUT },
{ "accept", IDS_BRAVE_UI_ACCEPT },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,33 @@
"grantExpire": {
"message": "Grant Expiration Date",
"description": "Grant expiry label"
},
"grantAlreadyClaimedText": {
"message": "Sorry, it appears that this grant has already been claimed.",
"description": "Description of the error when grant is already claimed."
},
"grantGeneralErrorButton": {
"message": "OK",
"description": "Button text for clearing the error."
},
"grantGeneralErrorText": {
"message": "Brave Rewards is having an issue. Please try again later.",
"description": "Error text when user is having problems claiming a grant."
},
"grantGeneralErrorTitle": {
"message": "Oops, something is wrong. Please try again later.",
"description": "Error title when user is having problems claiming a grant."
},
"grantGoneButton": {
"message": "OK",
"description": "Button text for clearing the error."
},
"grantGoneText": {
"message": "Sorry, it appears that this grant has already expired.",
"description": "Error text when user missed a grant."
},
"grantGoneTitle": {
"message": "This grant is no longer available.",
"description": "Error title when user missed a grant."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export const getUIMessages = (): Record<string, string> => {
'expiresOn',
'for',
'grantExpire',
'grantAlreadyClaimedText',
'grantGeneralErrorButton',
'grantGeneralErrorText',
'grantGeneralErrorTitle',
'grantGoneButton',
'grantGoneText',
'grantGoneTitle',
'grants',
'includeInAuto',
'insufficientFunds',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ export const grantPanelReducer = (state: RewardsExtension.State | undefined, act
let grant = state.grant
grant.status = 'grantGone'

state = {
...state,
grant
}
}
} else if (properties.status === 18) {
state = { ...state }
if (state.grant) {
let grant = state.grant
grant.status = 'grantAlreadyClaimed'

state = {
...state,
grant
Expand Down
16 changes: 16 additions & 0 deletions components/brave_rewards/resources/ui/components/grant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ class Grant extends React.Component<Props, State> {
)
}

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

if (grant.status === 'generalError') {
return (
<GrantWrapper
Expand Down
11 changes: 11 additions & 0 deletions components/brave_rewards/resources/ui/reducers/grant_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ const grantReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
let grant = state.grant
grant.status = 'grantGone'

state = {
...state,
grant
}
}
} else if (properties.status === 18) {
state = { ...state }
if (state.grant) {
let grant = state.grant
grant.status = 'grantAlreadyClaimed'

state = {
...state,
grant
Expand Down
4 changes: 3 additions & 1 deletion components/definitions/rewards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ declare namespace Rewards {
actions: any
}

export type GrantStatus = 'wrongPosition' | 'grantGone' | 'generalError' | 'grantAlreadyClaimed' | number | null

export interface Grant {
promotionId?: string
altcurrency?: string
probi: string
expiryTime: number
captcha?: string
hint?: string
status?: 'wrongPosition' | 'grantGone' | 'generalError' | number | null
status?: GrantStatus
}

export interface WalletProperties {
Expand Down
4 changes: 3 additions & 1 deletion components/definitions/rewardsExtensions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ declare namespace RewardsExtension {
expiryTime: number
}

export type GrantStatus = 'wrongPosition' | 'grantGone' | 'generalError' | 'grantAlreadyClaimed' | number | null

export interface GrantInfo {
promotionId?: string
altcurrency?: string
probi: string
expiryTime: number
captcha?: string
hint?: string
status?: 'wrongPosition' | 'grantGone' | 'generalError' | number | null
status?: GrantStatus
}

export interface GrantFinish {
Expand Down
1 change: 1 addition & 0 deletions components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
<message name="IDS_BRAVE_REWARDS_LOCAL_GENERAL_GRANT_ERROR_TEXT" desc="">Brave Rewards is having an issue. Please try again later.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_WALLET_CORRUPTED" desc="">We detected that something is wrong with your wallet. You must recover your backup wallet before any transactions can be processed.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_WALLET_CORRUPTED_NOW" desc="">Recover now!</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_GRANT_ALREADY_CLAIMED_TEXT" desc="">Sorry, it appears that this grant has already been claimed.</message>

<!-- WebUI brave ui resources -->
<message name="IDS_BRAVE_UI_ABOUT" desc="">about</message>
Expand Down
Loading

0 comments on commit 3dd1294

Please sign in to comment.