Skip to content

Commit

Permalink
Merge pull request #896 from brave/contribution-notification
Browse files Browse the repository at this point in the history
Improves notifications for contribution
  • Loading branch information
NejcZdovc committed Nov 14, 2018
1 parent dc657d5 commit 57f93ea
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 21 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ deps = {
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/omaha": "https://github.com/brave/omaha.git@dc2582d63a5b92dd39bf7bfd07612e501e133143",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@9045b873c75165ea569151d34c2c797c07d11257",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@c15ad1f568f530c6acdccf5e4d5b20032faf15bb",
"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
26 changes: 16 additions & 10 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,22 @@ void RewardsServiceImpl::OnReconcileComplete(ledger::Result result,
ledger::PUBLISHER_CATEGORY category,
const std::string& probi) {

RewardsNotificationsService::RewardsNotificationArgs args;
args.push_back(viewing_id);
args.push_back(std::to_string(result));
args.push_back(std::to_string(category));
args.push_back(probi);

rewards_notifications_service_->AddNotification(
RewardsNotificationsService::REWARDS_NOTIFICATION_AUTO_CONTRIBUTE,
args,
"contribution_" + viewing_id);
if ((result == ledger::Result::LEDGER_OK &&
category == ledger::PUBLISHER_CATEGORY::AUTO_CONTRIBUTE) ||
result == ledger::Result::LEDGER_ERROR ||
result == ledger::Result::NOT_ENOUGH_FUNDS ||
result == ledger::Result::TIP_ERROR) {
RewardsNotificationsService::RewardsNotificationArgs args;
args.push_back(viewing_id);
args.push_back(std::to_string(result));
args.push_back(std::to_string(category));
args.push_back(probi);

rewards_notifications_service_->AddNotification(
RewardsNotificationsService::REWARDS_NOTIFICATION_AUTO_CONTRIBUTE,
args,
"contribution_" + viewing_id);
}

if (result == ledger::Result::LEDGER_OK) {
auto now = base::Time::Now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@
"message": "Auto-Contribute",
"description": "Notification title when we display info about auto contribution"
},
"contributeNotification": {
"contributeNotificationSuccess": {
"message": "You've contributed $amount$ BAT",
"description": "Description for successful contribution notification",
"description": "We show this string in the notification when contribution is successful",
"placeholders": {
"amount": {
"content": "$1",
Expand All @@ -184,5 +184,17 @@
"braveRewardsCreatingText": {
"message": "Creating wallet",
"description": "Used in a button displaying wallet creation process"
},
"contributeNotificationError": {
"message": "There was a problem processing your contribution.",
"description": "We show this string in notification when contribution fails"
},
"contributeNotificationNotEnoughFunds": {
"message": "Your scheduled monthly payment for Auto-Contribute and monthly tips could not be completed due to insufficient funds. We’ll try again in 30 days.",
"description": "We show this string in the notification when you don't have enough funds for contribution"
},
"contributeNotificationTipError": {
"message": "There was a problem processing your tip, please try again.",
"description": "We show this string in notification when tip fails"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const getMessage = (message: string, substitutions?: string[]): string =>
export const getUIMessages = (): Record<string, string> => {
const strings = [
'braveAdsTitle',
'braveContributeTitle',
'braveRewards',
'braveRewardsCreatingText',
'donateMonthly',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { WalletAddIcon, BatColorIcon } from 'brave-ui/components/icons'
import { WalletWrapper, WalletSummary, WalletSummarySlider, WalletPanel } from 'brave-ui/features/rewards'
import { Provider } from 'brave-ui/features/rewards/profile'
import { NotificationType } from 'brave-ui/features/rewards/walletWrapper'
import { Type as AlertType } from 'brave-ui/features/rewards/alert'

// Utils
import * as rewardsPanelActions from '../actions/rewards_panel_actions'
Expand Down Expand Up @@ -187,6 +188,7 @@ export class Panel extends React.Component<Props, State> {

let type: NotificationType = ''
let text = ''
let isAlert = ''
switch (notification.type) {
case 1:
{
Expand All @@ -196,10 +198,26 @@ export class Panel extends React.Component<Props, State> {
break
}

if (notification.args[1] === '0') {
text = getMessage('contributeNotificationSuccess')
const result = notification.args[1]

// Results
// 0 - success
// 1 - general error
// 15 - not enough funds
// 16 - error while tipping

if (result === '0') {
const fixed = utils.convertProbiToFixed(notification.args[3])
text = getMessage('contributeNotificationSuccess', [fixed])
} else if (result === '15') {
text = getMessage('contributeNotificationNotEnoughFunds')
isAlert = 'warning'
} else if (result === '16') {
text = getMessage('contributeNotificationTipError')
isAlert = 'error'
} else {
text = getMessage('contributeNotificationError')
isAlert = 'error'
}
type = 'contribute'
break
Expand All @@ -210,12 +228,24 @@ export class Panel extends React.Component<Props, State> {
break
}

if (isAlert) {
return {
alert: {
node: text,
type: isAlert as AlertType,
onAlertClose: this.onCloseNotification.bind(this, notification.id)
}
}
}

return {
id: notification.id,
date: new Date(notification.timestamp * 1000).toLocaleDateString(),
type: type,
text: text,
onCloseNotification: this.onCloseNotification
notification: {
id: notification.id,
date: new Date(notification.timestamp * 1000).toLocaleDateString(),
type: type,
text: text,
onCloseNotification: this.onCloseNotification
}
}
}

Expand Down Expand Up @@ -255,7 +285,7 @@ export class Panel extends React.Component<Props, State> {
showSecActions={false}
connectedWallet={false}
grants={this.getGrants(grants)}
notification={notification}
{...notification}
>
<WalletSummarySlider
id={'panel-slider'}
Expand Down

0 comments on commit 57f93ea

Please sign in to comment.