Skip to content

Commit

Permalink
Fixes brave/brave-browser#3637, adds notification for tip reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanml committed Mar 27, 2019
1 parent dcc0def commit 23d5c90
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ BraveRewardsGetACEnabledFunction::Run() {
return RespondNow(Error("Rewards service is not initialized"));
}

rewards_service->GetAutoContribute(base::Bind(
rewards_service->GetAutoContribute(base::BindOnce(
&BraveRewardsGetACEnabledFunction::OnGetACEnabled,
this));
return RespondLater();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RewardsNotificationService {
REWARDS_NOTIFICATION_IMPENDING_CONTRIBUTION,
REWARDS_NOTIFICATION_INSUFFICIENT_FUNDS,
REWARDS_NOTIFICATION_BACKUP_WALLET,
REWARDS_NOTIFICATION_TIPS_PROCESSED
};

struct RewardsNotification {
Expand Down
4 changes: 2 additions & 2 deletions components/brave_rewards/browser/rewards_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ using GetPublisherMinVisitTimeCallback = base::Callback<void(uint64_t)>;
using GetPublisherMinVisitsCallback = base::Callback<void(uint32_t)>;
using GetPublisherAllowNonVerifiedCallback = base::Callback<void(bool)>;
using GetPublisherAllowVideosCallback = base::Callback<void(bool)>;
using GetAutoContributeCallback = base::Callback<void(bool)>;
using GetAutoContributeCallback = base::OnceCallback<void(bool)>;
using GetReconcileStampCallback = base::Callback<void(uint64_t)>;
using IsWalletCreatedCallback = base::Callback<void(bool)>;
using GetPendingContributionsTotalCallback = base::Callback<void(double)>;
Expand Down Expand Up @@ -138,7 +138,7 @@ class RewardsService : public KeyedService {
virtual void SetContributionAmount(double amount) const = 0;
virtual void SetUserChangedContribution() const = 0;
virtual void GetAutoContribute(
const GetAutoContributeCallback& callback) = 0;
GetAutoContributeCallback callback) = 0;
virtual void SetAutoContribute(bool enabled) const = 0;
virtual void SetTimer(uint64_t time_offset, uint32_t* timer_id) = 0;
virtual void GetAllBalanceReports(
Expand Down
25 changes: 23 additions & 2 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,11 @@ void RewardsServiceImpl::OnReconcileComplete(ledger::Result result,
return;

FetchWalletProperties();

if (category == ledger::REWARDS_CATEGORY::RECURRING_DONATION) {
MaybeShowNotificationTipsPaid();
}

bat_ledger_->OnReconcileCompleteSuccess(viewing_id,
category,
probi,
Expand Down Expand Up @@ -1706,12 +1711,12 @@ void RewardsServiceImpl::SetUserChangedContribution() const {
}

void RewardsServiceImpl::GetAutoContribute(
const GetAutoContributeCallback& callback) {
GetAutoContributeCallback callback) {
if (!Connected()) {
return;
}

bat_ledger_->GetAutoContribute(callback);
bat_ledger_->GetAutoContribute(std::move(callback));
}

void RewardsServiceImpl::SetAutoContribute(bool enabled) const {
Expand Down Expand Up @@ -2403,6 +2408,22 @@ void RewardsServiceImpl::ShowNotificationAddFunds(bool sufficient) {
"rewards_notification_insufficient_funds");
}

void RewardsServiceImpl::MaybeShowNotificationTipsPaid() {
GetAutoContribute(base::BindOnce(
&RewardsServiceImpl::ShowNotificationTipsPaid,
AsWeakPtr()));
}

void RewardsServiceImpl::ShowNotificationTipsPaid(bool ac_enabled) {
if (ac_enabled)
return;

RewardsNotificationService::RewardsNotificationArgs args;
notification_service_->AddNotification(
RewardsNotificationService::REWARDS_NOTIFICATION_TIPS_PROCESSED, args,
"rewards_notification_tips_processed");
}

std::unique_ptr<ledger::LogStream> RewardsServiceImpl::Log(
const char* file,
int line,
Expand Down
5 changes: 4 additions & 1 deletion components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class RewardsServiceImpl : public RewardsService,
void GetReconcileStamp(const GetReconcileStampCallback& callback) override;
void GetAddresses(const GetAddressesCallback& callback) override;
void GetAutoContribute(
const GetAutoContributeCallback& callback) override;
GetAutoContributeCallback callback) override;
void GetPublisherMinVisitTime(
const GetPublisherMinVisitTimeCallback& callback) override;
void GetPublisherMinVisits(
Expand Down Expand Up @@ -425,6 +425,9 @@ class RewardsServiceImpl : public RewardsService,
bool ShouldShowNotificationAddFunds() const;
void ShowNotificationAddFunds(bool sufficient);

void MaybeShowNotificationTipsPaid();
void ShowNotificationTipsPaid(bool ac_enabled);

// Mojo Proxy methods
void OnPublisherBannerMojoProxy(const std::string& banner);
void OnGetConfirmationsHistory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,5 +376,13 @@
"welcomeBack": {
"message": "Welcome Back!",
"description": "Title message for wallet disabled panel"
},
"tipsProcessedNotification": {
"message": "Your monthly tips have been processed!",
"description": "Message for monthly tips processed notification"
},
"contributionTips": {
"message": "Contributions & Tips",
"description": "Title for monthly tips processed notification"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const getUIMessages = (): Record<string, string> => {
'captchaTarget',
'captchaMissedTarget',
'claim',
'contributionTips',
'disabledPanelTextTwo',
'donateMonthly',
'donateNow',
Expand Down Expand Up @@ -84,6 +85,7 @@ export const getUIMessages = (): Record<string, string> => {
'rewardsSummary',
'serviceText',
'termsOfService',
'tipsProcessedNotification',
'tokenGrant',
'tokenGrantClaimed',
'unVerifiedPublisher',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ export class Panel extends React.Component<Props, State> {
type = 'insufficientFunds'
text = getMessage('insufficientFundsNotification')
break
case RewardsNotificationType.REWARDS_NOTIFICATION_TIPS_PROCESSED:
type = 'tipsProcessed'
text = getMessage('tipsProcessedNotification')
break
default:
type = ''
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ export const enum RewardsNotificationType {
REWARDS_NOTIFICATION_FAILED_CONTRIBUTION,
REWARDS_NOTIFICATION_IMPENDING_CONTRIBUTION,
REWARDS_NOTIFICATION_INSUFFICIENT_FUNDS,
REWARDS_NOTIFICATION_BACKUP_WALLET
REWARDS_NOTIFICATION_BACKUP_WALLET,
REWARDS_NOTIFICATION_TIPS_PROCESSED
}

0 comments on commit 23d5c90

Please sign in to comment.