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

Hides expiry date for ads (uplift to 0.64.x) #2193

Merged
merged 1 commit into from
Apr 15, 2019
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
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 @@ -563,6 +563,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 @@ -344,7 +344,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 pendingTotal = parseFloat(
(pendingContributionTotal || 0).toFixed(1))
Expand All @@ -356,6 +356,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 @@ -40,6 +40,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