Skip to content

Commit

Permalink
Hides expiry date for ads
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Apr 10, 2019
1 parent c7fe1e8 commit c87cd24
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 53 deletions.
1 change: 1 addition & 0 deletions browser/ui/webui/brave_rewards_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ void RewardsDOMHandler::OnGrantFinish(
finish.SetInteger("status", result);
finish.SetInteger("expiryTime", grant.expiryTime);
finish.SetString("probi", grant.probi);
finish.SetString("type", grant.type);

web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.grantFinish", finish);
GetAllBalanceReports();
Expand Down
20 changes: 19 additions & 1 deletion common/extensions/api/brave_rewards.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,25 @@
"parameters": [
{
"name": "properties",
"type": "any"
"type": "object",
"properties": {
"status": {
"type": "integer",
"description": "publisher attention score"
},
"expiryTime": {
"type": "integer",
"description": "grant expiry time"
},
"probi": {
"type": "string",
"description": "value of the grant"
},
"type": {
"type": "string",
"description": "type of the grant (ugp or ads)"
}
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,14 @@ void ExtensionRewardsServiceObserver::OnGrantFinish(
return;
}

base::DictionaryValue finish;
finish.SetInteger("status", result);
finish.SetInteger("expiryTime", grant.expiryTime);
finish.SetString("probi", grant.probi);
extensions::api::brave_rewards::OnGrantFinish::Properties properties;
properties.status = result;
properties.expiry_time = grant.expiryTime;
properties.probi = grant.probi;
properties.type = grant.type;

std::unique_ptr<base::ListValue> args(
extensions::api::brave_rewards::OnGrantFinish::Create(finish)
extensions::api::brave_rewards::OnGrantFinish::Create(properties)
.release());
std::unique_ptr<extensions::Event> event(new extensions::Event(
extensions::events::BRAVE_START,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ transpile_web_ui("brave_rewards_panel") {
"background/api/tabs_api.ts",
"background/events/rewardsEvents.ts",
"background/events/tabEvents.ts",
"background/reducers/grant_panel_reducer.ts",
"background/reducers/index.ts",
"background/reducers/rewards_panel_reducer.ts",
"background/storage.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export const grantPanelReducer = (state: RewardsExtension.State | undefined, act
case 0:
currentGrant.expiryTime = properties.expiryTime * 1000
currentGrant.probi = properties.probi
currentGrant.type = properties.type
currentGrant.status = null
chrome.braveRewards.getWalletProperties()
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class Panel extends React.Component<Props, State> {
const notificationId = this.getNotificationProp('id', notification)
const notificationType = this.getNotificationProp('type', notification)
const notificationClick = this.getNotificationClickEvent(notificationType, notificationId)
const { currentGrant } = this.props.rewardsPanelData
let { currentGrant } = this.props.rewardsPanelData
const defaultContribution = this.getContribution(publisher)
const tipAmounts = defaultContribution !== '0.0'
? this.generateAmounts(publisher)
Expand All @@ -421,6 +421,9 @@ export class Panel extends React.Component<Props, State> {
faviconUrl = `chrome://favicon/size/48@2x/${publisher.favicon_url}`
}
}

currentGrant = utils.getGrant(currentGrant)

return (
<WalletWrapper
compact={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,22 @@ export const getGrants = (grants?: RewardsExtension.Grant[]) => {
}

return grants.map((grant: RewardsExtension.Grant) => {
let expireDate = ''
if (grant.type !== 'ads') {
expireDate = new Date(grant.expiryTime * 1000).toLocaleDateString()
}

return {
tokens: convertProbiToFixed(grant.probi),
expireDate: new Date(grant.expiryTime * 1000).toLocaleDateString()
expireDate
}
})
}

export const getGrant = (grant?: RewardsExtension.GrantInfo) => {
if (grant && grant.type === 'ads') {
grant.expiryTime = 0
}

return grant
}
7 changes: 6 additions & 1 deletion components/brave_rewards/resources/ui/components/grant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class Grant extends React.Component<Props, State> {
let type
let promoId
let tokens = '0.0'
let date = ''

if (grant.type) {
type = grant.type
Expand All @@ -156,6 +157,10 @@ class Grant extends React.Component<Props, State> {
tokens = convertProbiToFixed(grant.probi)
}

if (grant.type !== 'ads') {
date = new Date(grant.expiryTime).toLocaleDateString()
}

return (
<>
{
Expand All @@ -175,7 +180,7 @@ class Grant extends React.Component<Props, State> {
title={'It’s your lucky day!'}
text={'Your token grant is on its way.'}
>
<GrantComplete onClose={this.onFinish} amount={tokens} date={new Date(grant.expiryTime).toLocaleDateString()} />
<GrantComplete onClose={this.onFinish} amount={tokens} date={date} />
</GrantWrapper>
: null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,14 @@ class PageWallet extends React.Component<Props, State> {
}

return grants.map((grant: Rewards.Grant) => {
let expireDate = ''
if (grant.type !== 'ads') {
expireDate = new Date(grant.expiryTime * 1000).toLocaleDateString()
}

return {
tokens: utils.convertProbiToFixed(grant.probi),
expireDate: new Date(grant.expiryTime * 1000).toLocaleDateString()
expireDate
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const grantReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
let ui = state.ui
newGrant.expiryTime = properties.expiryTime * 1000
newGrant.probi = properties.probi
newGrant.type = properties.type
newGrant.status = null
ui.emptyWallet = false

Expand Down
1 change: 1 addition & 0 deletions components/definitions/rewardsExtensions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ declare namespace RewardsExtension {
altcurrency: string
probi: string
expiryTime: number
type: string
}

export type GrantStatus = 'wrongPosition' | 'grantGone' | 'generalError' | 'grantAlreadyClaimed' | number | null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ describe('Grant Reducer', () => {
properties: {
status: 0,
expiryTime: 11,
probi: '30.000000'
probi: '30.000000',
type: 'ads'
}
}
})
Expand Down
Loading

0 comments on commit c87cd24

Please sign in to comment.