From 2b3debda92a3f69ff386e6a8cc41668c1c2a0a02 Mon Sep 17 00:00:00 2001 From: ryanml Date: Tue, 19 Mar 2019 01:49:07 -0700 Subject: [PATCH 1/2] Fixes brave/brave-browser#2245 Fixes brave/brave-browser#2823 Monthly donation functionality via panel --- browser/extensions/api/brave_rewards_api.cc | 135 ++++++++++++++++++ browser/extensions/api/brave_rewards_api.h | 57 ++++++++ browser/ui/webui/brave_donate_ui.cc | 52 +++---- common/extensions/api/brave_rewards.json | 88 ++++++++++++ .../brave_rewards/browser/content_site.cc | 2 + .../brave_rewards/browser/content_site.h | 1 + .../extension_rewards_service_observer.cc | 33 +++++ .../extension_rewards_service_observer.h | 4 + .../brave_rewards/browser/rewards_service.h | 10 +- .../browser/rewards_service_impl.cc | 50 +++---- .../browser/rewards_service_impl.h | 12 +- .../browser/rewards_service_observer.h | 3 - .../donate/reducers/donate_reducer.ts | 4 +- .../_locales/en_US/messages.json | 4 + .../actions/rewards_panel_actions.ts | 18 +++ .../background/api/locale_api.ts | 1 + .../background/events/rewardsEvents.ts | 13 ++ .../reducers/rewards_panel_reducer.ts | 38 +++++ .../brave_rewards/background/storage.ts | 4 +- .../brave_rewards/components/app.tsx | 3 + .../brave_rewards/components/panel.tsx | 81 ++++++++++- .../constants/rewards_panel_types.ts | 6 +- components/definitions/chromel.d.ts | 7 + components/definitions/rewardsExtensions.d.ts | 19 +++ package-lock.json | 4 +- package.json | 2 +- 26 files changed, 587 insertions(+), 64 deletions(-) diff --git a/browser/extensions/api/brave_rewards_api.cc b/browser/extensions/api/brave_rewards_api.cc index de6b78ef14e1..c5eac7adefde 100644 --- a/browser/extensions/api/brave_rewards_api.cc +++ b/browser/extensions/api/brave_rewards_api.cc @@ -291,5 +291,140 @@ ExtensionFunction::ResponseAction BraveRewardsSaveSettingFunction::Run() { return RespondNow(NoArguments()); } +BraveRewardsSaveRecurringDonationFunction:: +~BraveRewardsSaveRecurringDonationFunction() { +} + +ExtensionFunction::ResponseAction + BraveRewardsSaveRecurringDonationFunction::Run() { + + std::unique_ptr params( + brave_rewards::SaveRecurringDonation::Params::Create(*args_)); + + Profile* profile = Profile::FromBrowserContext(browser_context()); + RewardsService* rewards_service_ = + RewardsServiceFactory::GetForProfile(profile); + + if (rewards_service_) { + rewards_service_->SaveRecurringDonation( + params->publisher_key, params->new_amount); + } + + return RespondNow(NoArguments()); +} + +BraveRewardsRemoveRecurringDonationFunction:: +~BraveRewardsRemoveRecurringDonationFunction() { +} + +ExtensionFunction::ResponseAction + BraveRewardsRemoveRecurringDonationFunction::Run() { + std::unique_ptr params( + brave_rewards::RemoveRecurringDonation::Params::Create(*args_)); + + Profile* profile = Profile::FromBrowserContext(browser_context()); + RewardsService* rewards_service_ = + RewardsServiceFactory::GetForProfile(profile); + + if (rewards_service_) { + rewards_service_->RemoveRecurring(params->publisher_key); + } + + return RespondNow(NoArguments()); +} + +BraveRewardsGetRecurringDonationsFunction:: +~BraveRewardsGetRecurringDonationsFunction() { +} + +ExtensionFunction::ResponseAction +BraveRewardsGetRecurringDonationsFunction::Run() { + Profile* profile = Profile::FromBrowserContext(browser_context()); + RewardsService* rewards_service = + RewardsServiceFactory::GetForProfile(profile); + + if (!rewards_service) { + return RespondNow(Error("Rewards service is not initialized")); + } + + rewards_service->GetRecurringDonationsList(base::Bind( + &BraveRewardsGetRecurringDonationsFunction::OnGetRecurringDonations, + this)); + return RespondLater(); +} + +void BraveRewardsGetRecurringDonationsFunction::OnGetRecurringDonations( + std::unique_ptr<::brave_rewards::ContentSiteList> list) { + std::unique_ptr result(new base::DictionaryValue()); + auto recurringDonations = std::make_unique(); + + if (!list->empty()) { + for (auto const& item: *list) { + auto recurringDonation = std::make_unique(); + recurringDonation->SetString("publisherKey", item.id); + recurringDonation->SetInteger("amount", item.weight); + recurringDonations->Append(std::move(recurringDonation)); + } + } + + result->SetList("recurringDonations", std::move(recurringDonations)); + Respond(OneArgument(std::move(result))); +} + +BraveRewardsGetPublisherBannerFunction:: +~BraveRewardsGetPublisherBannerFunction() { +} + +ExtensionFunction::ResponseAction +BraveRewardsGetPublisherBannerFunction::Run() { + std::unique_ptr params( + brave_rewards::GetPublisherBanner::Params::Create(*args_)); + + Profile* profile = Profile::FromBrowserContext(browser_context()); + RewardsService* rewards_service = + RewardsServiceFactory::GetForProfile(profile); + + if (!rewards_service) { + return RespondNow(Error("Rewards service is not initialized")); + } + + rewards_service->GetPublisherBanner( + params->publisher_key, + base::BindOnce( + &BraveRewardsGetPublisherBannerFunction::OnPublisherBanner, + this)); + return RespondLater(); +} + +void BraveRewardsGetPublisherBannerFunction::OnPublisherBanner( + std::unique_ptr<::brave_rewards::PublisherBanner> banner) { + std::unique_ptr result(new base::DictionaryValue()); + + if (banner) { + result->SetString("publisherKey", banner->publisher_key); + result->SetString("title", banner->title); + result->SetString("name", banner->name); + result->SetString("description", banner->description); + result->SetString("background", banner->background); + result->SetString("logo", banner->logo); + result->SetString("provider", banner->provider); + result->SetBoolean("verified", banner->verified); + + auto amounts = std::make_unique(); + for (int const& value : banner->amounts) { + amounts->AppendInteger(value); + } + result->SetList("amounts", std::move(amounts)); + + auto social = std::make_unique(); + for (auto const& item : banner->social) { + social->SetString(item.first, item.second); + } + result->SetDictionary("social", std::move(social)); + } + + Respond(OneArgument(std::move(result))); +} + } // namespace api } // namespace extensions diff --git a/browser/extensions/api/brave_rewards_api.h b/browser/extensions/api/brave_rewards_api.h index 7004f0e9102a..8d150e85f3d8 100644 --- a/browser/extensions/api/brave_rewards_api.h +++ b/browser/extensions/api/brave_rewards_api.h @@ -6,7 +6,11 @@ #ifndef BRAVE_BROWSER_EXTENSIONS_API_BRAVE_REWARDS_API_H_ #define BRAVE_BROWSER_EXTENSIONS_API_BRAVE_REWARDS_API_H_ +#include + #include "extensions/browser/extension_function.h" +#include "brave/components/brave_rewards/browser/content_site.h" +#include "brave/components/brave_rewards/browser/publisher_banner.h" namespace extensions { namespace api { @@ -165,6 +169,59 @@ class BraveRewardsSaveSettingFunction : public UIThreadExtensionFunction { ResponseAction Run() override; }; +class BraveRewardsSaveRecurringDonationFunction : + public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("braveRewards.saveRecurringDonation", UNKNOWN) + + protected: + ~BraveRewardsSaveRecurringDonationFunction() override; + + ResponseAction Run() override; +}; + +class BraveRewardsRemoveRecurringDonationFunction : + public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("braveRewards.removeRecurringDonation", UNKNOWN) + + protected: + ~BraveRewardsRemoveRecurringDonationFunction() override; + + ResponseAction Run() override; +}; + +class BraveRewardsGetRecurringDonationsFunction : + public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("braveRewards.getRecurringDonations", UNKNOWN) + + protected: + ~BraveRewardsGetRecurringDonationsFunction() override; + + ResponseAction Run() override; + + private: + void OnGetRecurringDonations( + std::unique_ptr list); +}; + +class BraveRewardsGetPublisherBannerFunction : +public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION( + "braveRewards.getPublisherBanner", UNKNOWN) + + protected: + ~BraveRewardsGetPublisherBannerFunction() override; + + ResponseAction Run() override; + + private: + void OnPublisherBanner( + std::unique_ptr<::brave_rewards::PublisherBanner> banner); +}; + } // namespace api } // namespace extensions diff --git a/browser/ui/webui/brave_donate_ui.cc b/browser/ui/webui/brave_donate_ui.cc index b7cf9852674d..7b9c6f756e3a 100644 --- a/browser/ui/webui/brave_donate_ui.cc +++ b/browser/ui/webui/brave_donate_ui.cc @@ -57,6 +57,9 @@ class RewardsDonateDOMHandler : public WebUIMessageHandler, void OnGetRecurringTips( std::unique_ptr list); + void OnPublisherBanner( + std::unique_ptr banner); + // RewardsServiceObserver implementation void OnWalletProperties( brave_rewards::RewardsService* rewards_service, @@ -64,9 +67,6 @@ class RewardsDonateDOMHandler : public WebUIMessageHandler, std::unique_ptr wallet_properties) override; - void OnPublisherBanner(brave_rewards::RewardsService* rewards_service, - const brave_rewards::PublisherBanner banner) override; - void OnRecurringTipRemoved(brave_rewards::RewardsService* rewards_service, bool success) override; @@ -118,7 +118,10 @@ void RewardsDonateDOMHandler::GetPublisherDonateData( const base::ListValue* args) { std::string publisher_key; args->GetString(0, &publisher_key); - rewards_service_->GetPublisherBanner(publisher_key); + rewards_service_->GetPublisherBanner( + publisher_key, + base::Bind(&RewardsDonateDOMHandler::OnPublisherBanner, + weak_factory_.GetWeakPtr())); } void RewardsDonateDOMHandler::GetWalletProperties(const base::ListValue* args) { @@ -229,33 +232,34 @@ void RewardsDonateDOMHandler::OnGetRecurringTips( } void RewardsDonateDOMHandler::OnPublisherBanner( - brave_rewards::RewardsService* rewards_service, - const brave_rewards::PublisherBanner banner) { + std::unique_ptr banner) { if (!web_ui()->CanCallJavascript()) { return; } base::DictionaryValue result; - result.SetString("publisherKey", banner.publisher_key); - result.SetString("title", banner.title); - result.SetString("name", banner.name); - result.SetString("description", banner.description); - result.SetString("background", banner.background); - result.SetString("logo", banner.logo); - result.SetString("provider", banner.provider); - result.SetBoolean("verified", banner.verified); - - auto amounts = std::make_unique(); - for (int const& value : banner.amounts) { - amounts->AppendInteger(value); - } - result.SetList("amounts", std::move(amounts)); + if (banner) { + result.SetString("publisherKey", banner->publisher_key); + result.SetString("title", banner->title); + result.SetString("name", banner->name); + result.SetString("description", banner->description); + result.SetString("background", banner->background); + result.SetString("logo", banner->logo); + result.SetString("provider", banner->provider); + result.SetBoolean("verified", banner->verified); + + auto amounts = std::make_unique(); + for (int const& value : banner->amounts) { + amounts->AppendInteger(value); + } + result.SetList("amounts", std::move(amounts)); - auto social = std::make_unique(); - for (auto const& item : banner.social) { - social->SetString(item.first, item.second); + auto social = std::make_unique(); + for (auto const& item : banner->social) { + social->SetString(item.first, item.second); + } + result.SetDictionary("social", std::move(social)); } - result.SetDictionary("social", std::move(social)); web_ui()->CallJavascriptFunctionUnsafe( "brave_rewards_donate.publisherBanner", result); diff --git a/common/extensions/api/brave_rewards.json b/common/extensions/api/brave_rewards.json index 8189dde6a074..1b0e5a4fc196 100644 --- a/common/extensions/api/brave_rewards.json +++ b/common/extensions/api/brave_rewards.json @@ -287,6 +287,30 @@ } } ] + }, + { + "name": "onRecurringDonations", + "type": "function", + "description": "Fired when publisher recurring donations modified", + "parameters": [ + { + "name": "donations", + "type": "array", + "items": { + "type": "object", + "properties": { + "publisherKey": { + "type": "string", + "description": "publisher key, unique identifier" + }, + "amount": { + "type": "integer", + "description": "publisher donation amount" + } + } + } + } + ] } ], "functions": [ @@ -477,6 +501,70 @@ "type": "string" } ] + }, + { + "name": "saveRecurringDonation", + "type": "function", + "description": "Updates recurring donation amount for rewards panel", + "parameters": [ + { + "name": "publisher_key", + "type": "string" + }, + { + "name": "new_amount", + "type": "integer" + } + ] + }, + { + "name": "removeRecurringDonation", + "type": "function", + "description": "Removes recurring donation for rewards panel", + "parameters": [ + { + "name": "publisher_key", + "type": "string" + } + ] + }, + { + "name": "getRecurringDonations", + "type": "function", + "description": "Gets list of sites with recurring donation data", + "parameters": [ + { + "type": "function", + "name": "callback", + "parameters": [ + { + "name": "donations", + "type": "any" + } + ] + } + ] + }, + { + "name": "getPublisherBanner", + "type": "function", + "description": "Retrieves data for publisher banner", + "parameters": [ + { + "name": "publisher_key", + "type": "string" + }, + { + "name": "callback", + "type": "function", + "parameters": [ + { + "name": "banner", + "type": "any" + } + ] + } + ] } ] } diff --git a/components/brave_rewards/browser/content_site.cc b/components/brave_rewards/browser/content_site.cc index 47e1a78c6ace..171c39ca6fd3 100644 --- a/components/brave_rewards/browser/content_site.cc +++ b/components/brave_rewards/browser/content_site.cc @@ -12,6 +12,7 @@ namespace brave_rewards { percentage(0), verified(false), excluded(0), + weight(0), reconcile_stamp(0) { } @@ -26,6 +27,7 @@ namespace brave_rewards { url = properties.url; provider = properties.provider; id = properties.id; + weight = properties.weight; reconcile_stamp = properties.reconcile_stamp; } diff --git a/components/brave_rewards/browser/content_site.h b/components/brave_rewards/browser/content_site.h index 13e5a205d950..4dcf23280e72 100644 --- a/components/brave_rewards/browser/content_site.h +++ b/components/brave_rewards/browser/content_site.h @@ -31,6 +31,7 @@ struct ContentSite { std::string favicon_url; std::string url; std::string provider; + double weight; uint64_t reconcile_stamp; }; diff --git a/components/brave_rewards/browser/extension_rewards_service_observer.cc b/components/brave_rewards/browser/extension_rewards_service_observer.cc index 329b86ee6483..f023e133c30f 100644 --- a/components/brave_rewards/browser/extension_rewards_service_observer.cc +++ b/components/brave_rewards/browser/extension_rewards_service_observer.cc @@ -325,4 +325,37 @@ void ExtensionRewardsServiceObserver::OnExcludedSitesChanged( event_router->BroadcastEvent(std::move(event)); } +void ExtensionRewardsServiceObserver::OnRecurringDonationUpdated( + RewardsService* rewards_service, + brave_rewards::ContentSiteList list) { + auto* event_router = extensions::EventRouter::Get(profile_); + if (!event_router) { + return; + } + + std::vector donations; + + for (size_t i = 0; i < list.size(); i++) { + donations.push_back( + extensions::api::brave_rewards::OnRecurringDonations:: + DonationsType()); + + auto& donation = donations[donations.size() - 1]; + donation.publisher_key = list[i].id; + donation.amount = list[i].percentage; + } + + std::unique_ptr args( + extensions::api::brave_rewards:: + OnRecurringDonations::Create(donations) + .release()); + + std::unique_ptr event(new extensions::Event( + extensions::events::BRAVE_START, + extensions::api::brave_rewards::OnRecurringDonations::kEventName, + std::move(args))); + event_router->BroadcastEvent(std::move(event)); +} + } // namespace brave_rewards diff --git a/components/brave_rewards/browser/extension_rewards_service_observer.h b/components/brave_rewards/browser/extension_rewards_service_observer.h index 9f1a01c2b680..ad91787df328 100644 --- a/components/brave_rewards/browser/extension_rewards_service_observer.h +++ b/components/brave_rewards/browser/extension_rewards_service_observer.h @@ -63,6 +63,10 @@ class ExtensionRewardsServiceObserver : public RewardsServiceObserver, void OnPendingContributionSaved(RewardsService* rewards_service, int result) override; + void OnRecurringDonationUpdated( + RewardsService* rewards_service, + brave_rewards::ContentSiteList list) override; + private: Profile* profile_; diff --git a/components/brave_rewards/browser/rewards_service.h b/components/brave_rewards/browser/rewards_service.h index df6997af81fe..d0002f9b2738 100644 --- a/components/brave_rewards/browser/rewards_service.h +++ b/components/brave_rewards/browser/rewards_service.h @@ -75,6 +75,8 @@ using GetRecurringTipsCallback = base::OnceCallback)>; using GetOneTimeTipsCallback = base::OnceCallback)>; +using GetPublisherBannerCallback = + base::OnceCallback)>; class RewardsService : public KeyedService { public: @@ -156,7 +158,8 @@ class RewardsService : public KeyedService { const std::string& publisher_blob) = 0; virtual void GetContributionAmount( const GetContributionAmountCallback& callback) = 0; - virtual void GetPublisherBanner(const std::string& publisher_id) = 0; + virtual void GetPublisherBanner(const std::string& publisher_id, + GetPublisherBannerCallback callback) = 0; virtual void OnDonate(const std::string& publisher_key, int amount, bool recurring, const ledger::PublisherInfo* publisher_info = NULL) = 0; virtual void OnDonate(const std::string& publisher_key, int amount, @@ -192,6 +195,11 @@ class RewardsService : public KeyedService { static void RegisterProfilePrefs(PrefRegistrySimple* registry); + virtual void SaveRecurringDonation( + const std::string& publisher_key, const int amount) = 0; + virtual void GetRecurringDonationsList( + GetRecurringDonationsListCallback callback) = 0; + protected: base::ObserverList observers_; diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 73b0443e50a0..d546fa36559e 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -157,6 +157,7 @@ ContentSite PublisherInfoToContentSite( content_site.provider = publisher_info.provider; content_site.favicon_url = publisher_info.favicon_url; content_site.id = publisher_info.id; + content_site.weight = publisher_info.weight; content_site.reconcile_stamp = publisher_info.reconcile_stamp; return content_site; } @@ -2104,46 +2105,47 @@ void RewardsServiceImpl::OnSetOnDemandFaviconComplete( callback(success, favicon_url); } -void RewardsServiceImpl::GetPublisherBanner(const std::string& publisher_id) { +void RewardsServiceImpl::GetPublisherBanner( + const std::string& publisher_id, + GetPublisherBannerCallback callback) { if (!Connected()) return; bat_ledger_->GetPublisherBanner(publisher_id, - base::BindOnce(&RewardsServiceImpl::OnPublisherBannerMojoProxy, - AsWeakPtr())); + base::BindOnce(&RewardsServiceImpl::OnPublisherBanner, + AsWeakPtr(), + std::move(callback))); } -void RewardsServiceImpl::OnPublisherBannerMojoProxy( +void RewardsServiceImpl::OnPublisherBanner( + GetPublisherBannerCallback callback, const std::string& banner) { + std::unique_ptr new_banner; + new_banner.reset(new brave_rewards::PublisherBanner()); + std::unique_ptr publisher_banner; + publisher_banner.reset(new ledger::PublisherBanner()); + if (!banner.empty()) { - publisher_banner.reset(new ledger::PublisherBanner()); publisher_banner->loadFromJson(banner); } - OnPublisherBanner(std::move(publisher_banner)); -} -void RewardsServiceImpl::OnPublisherBanner( - std::unique_ptr banner) { - brave_rewards::PublisherBanner new_banner; - - if (!banner) { + if (!publisher_banner) { return; } - new_banner.publisher_key = banner->publisher_key; - new_banner.title = banner->title; - new_banner.name = banner->name; - new_banner.description = banner->description; - new_banner.background = banner->background; - new_banner.logo = banner->logo; - new_banner.amounts = banner->amounts; - new_banner.social = banner->social; - new_banner.provider = banner->provider; - new_banner.verified = banner->verified; + new_banner->publisher_key = publisher_banner->publisher_key; + new_banner->title = publisher_banner->title; + new_banner->name = publisher_banner->name; + new_banner->description = publisher_banner->description; + new_banner->background = publisher_banner->background; + new_banner->logo = publisher_banner->logo; + new_banner->amounts = publisher_banner->amounts; + new_banner->social = publisher_banner->social; + new_banner->provider = publisher_banner->provider; + new_banner->verified = publisher_banner->verified; - for (auto& observer : observers_) - observer.OnPublisherBanner(this, new_banner); + std::move(callback).Run(std::move(new_banner)); } void RewardsServiceImpl::OnDonate_PublisherInfoSaved(ledger::Result result, diff --git a/components/brave_rewards/browser/rewards_service_impl.h b/components/brave_rewards/browser/rewards_service_impl.h index 40a56259eb96..f11c03b4f81d 100644 --- a/components/brave_rewards/browser/rewards_service_impl.h +++ b/components/brave_rewards/browser/rewards_service_impl.h @@ -160,8 +160,10 @@ class RewardsServiceImpl : public RewardsService, const std::string& publisher_blob) override; void GetContributionAmount( const GetContributionAmountCallback& callback) override; - void GetPublisherBanner(const std::string& publisher_id) override; - void OnPublisherBanner(std::unique_ptr banner); + void GetPublisherBanner(const std::string& publisher_id, + GetPublisherBannerCallback callback) override; + void OnPublisherBanner(GetPublisherBannerCallback callback, + const std::string& banner); void RemoveRecurringTip(const std::string& publisher_key) override; void OnGetRecurringTipsUI( GetRecurringTipsCallback callback, @@ -200,6 +202,9 @@ class RewardsServiceImpl : public RewardsService, void GetOneTimeTipsUI(GetOneTimeTipsCallback callback) override; + void SaveRecurringDonation(const std::string& publisher_key, + const int amount) override; + // Testing methods void SetLedgerEnvForTesting(); @@ -385,6 +390,8 @@ class RewardsServiceImpl : public RewardsService, const ledger::REWARDS_CATEGORY category) override; void GetRecurringTips( ledger::PublisherInfoListCallback callback) override; + void GetRecurringDonationsList( + GetRecurringDonationsListCallback callback) override; std::unique_ptr Log( const char* file, int line, @@ -441,7 +448,6 @@ class RewardsServiceImpl : public RewardsService, void ShowNotificationTipsPaid(bool ac_enabled); // Mojo Proxy methods - void OnPublisherBannerMojoProxy(const std::string& banner); void OnGetConfirmationsHistory( brave_rewards::ConfirmationsHistoryCallback callback, const std::string& transactions); diff --git a/components/brave_rewards/browser/rewards_service_observer.h b/components/brave_rewards/browser/rewards_service_observer.h index f96b1d2ac38c..d549a1666b94 100644 --- a/components/brave_rewards/browser/rewards_service_observer.h +++ b/components/brave_rewards/browser/rewards_service_observer.h @@ -61,9 +61,6 @@ class RewardsServiceObserver : public base::CheckedObserver { const std::string& viewing_id, const std::string& category, const std::string& probi) {} - virtual void OnPublisherBanner( - brave_rewards::RewardsService* rewards_service, - const brave_rewards::PublisherBanner banner) {} virtual void OnRewardsMainEnabled( brave_rewards::RewardsService* rewards_service, bool rewards_main_enabled) {} diff --git a/components/brave_rewards/resources/donate/reducers/donate_reducer.ts b/components/brave_rewards/resources/donate/reducers/donate_reducer.ts index d3618e8aba70..2e6acccf4914 100644 --- a/components/brave_rewards/resources/donate/reducers/donate_reducer.ts +++ b/components/brave_rewards/resources/donate/reducers/donate_reducer.ts @@ -37,7 +37,9 @@ const publishersReducer: Reducer = (state: RewardsDonate.St state.publishers = {} } const publisher: RewardsDonate.Publisher = payload.data - state.publishers[publisher.publisherKey] = publisher + if (publisher && publisher.publisherKey) { + state.publishers[publisher.publisherKey] = publisher + } break } case types.GET_WALLET_PROPERTIES: diff --git a/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json b/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json index 2eda806df35d..536cb4ed4c24 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json +++ b/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json @@ -388,5 +388,9 @@ "serviceTextPanelWelcome": { "message": "By clicking ‘Join Rewards’, you indicate that you have read and agree to the", "description": "Terms of service panel opt-in text" + }, + "bat": { + "message": "BAT", + "description": "BAT text for displaying converted donation amount." } } diff --git a/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts b/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts index 4271871d0136..dd6385f77adc 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts @@ -114,3 +114,21 @@ export const onSettingSave = (key: string, value: any) => action(types.ON_SETTIN key, value }) + +export const saveRecurringDonation = (publisherKey: string, newAmount: number) => action(types.SAVE_RECURRING_DONATION, { + publisherKey, + newAmount +}) + +export const removeRecurringContribution = (publisherKey: string) => action(types.REMOVE_RECURRING_DONATION, { + publisherKey +}) + +export const onRecurringDonations = (result: RewardsExtension.RecurringDonation) => action(types.ON_RECURRING_DONATIONS, { + result +}) + +export const onPublisherBanner = (banner: RewardsExtension.PublisherBanner) => + action(types.ON_PUBLISHER_BANNER, { + banner + }) diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/api/locale_api.ts b/components/brave_rewards/resources/extension/brave_rewards/background/api/locale_api.ts index 7880f827e285..e4f5bcc9d7f3 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/api/locale_api.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/api/locale_api.ts @@ -26,6 +26,7 @@ export const getUIMessages = (): Record => { 'backupNow', 'backupWalletNotification', 'backupWalletTitle', + 'bat', 'braveAdsTitle', 'braveContributeTitle', 'braveRewards', diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/events/rewardsEvents.ts b/components/brave_rewards/resources/extension/brave_rewards/background/events/rewardsEvents.ts index eff0d9b62706..9d3117b9d437 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/events/rewardsEvents.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/events/rewardsEvents.ts @@ -10,6 +10,13 @@ chrome.braveRewards.onWalletCreated.addListener(() => { chrome.braveRewards.onPublisherData.addListener((windowId: number, publisher: RewardsExtension.Publisher) => { rewardsPanelActions.onPublisherData(windowId, publisher) + + // Get publisher amounts + if (publisher && publisher.publisher_key) { + chrome.braveRewards.getPublisherBanner(publisher.publisher_key, ((banner: RewardsExtension.PublisherBanner) => { + rewardsPanelActions.onPublisherBanner(banner) + })) + } }) chrome.braveRewards.onWalletProperties.addListener((properties: RewardsExtension.WalletProperties) => { @@ -63,3 +70,9 @@ chrome.braveRewards.onPublisherListNormalized.addListener((properties: RewardsEx chrome.braveRewards.onExcludedSitesChanged.addListener((properties: RewardsExtension.ExcludedSitesChanged) => { rewardsPanelActions.onExcludedSitesChanged(properties) }) + +chrome.braveRewards.onRecurringDonations.addListener((donations: Record[]) => { + rewardsPanelActions.onRecurringDonations({ + recurringDonations: donations + }) +}) diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts b/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts index c9d6e7963766..7c23c467c5bc 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts @@ -305,6 +305,44 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a } break } + case types.REMOVE_RECURRING_DONATION: { + let publisherKey = payload.publisherKey + if (publisherKey == null) { + break + } + chrome.braveRewards.removeRecurringDonation(publisherKey) + break + } + case types.SAVE_RECURRING_DONATION: { + let newAmount = payload.newAmount + let publisherKey = payload.publisherKey + + if (newAmount < 0 || + isNaN(newAmount) || + publisherKey == null) { + break + } + + chrome.braveRewards.saveRecurringDonation(publisherKey, newAmount) + break + } + case types.ON_RECURRING_DONATIONS: { + state = { ...state } + state.recurringDonations = payload.result.recurringDonations + break + } + case types.ON_PUBLISHER_BANNER: { + if (!payload.banner || !payload.banner.publisherKey) { + break + } + + state = { ...state } + if (!state.donationAmounts) { + state.donationAmounts = {} + } + state.donationAmounts[payload.banner.publisherKey] = payload.banner.amounts + break + } } return state } diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/storage.ts b/components/brave_rewards/resources/extension/brave_rewards/background/storage.ts index caf9e337997e..0c679ee5f14b 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/storage.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/storage.ts @@ -35,7 +35,9 @@ export const defaultState: RewardsExtension.State = { enabledMain: false, enabledAC: false, grants: [], - currentGrant: undefined + currentGrant: undefined, + recurringDonations: [], + donationAmounts: {} } const cleanData = (state: RewardsExtension.State) => { diff --git a/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx b/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx index baa8329477cb..71b2b10f47ce 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx +++ b/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx @@ -43,6 +43,9 @@ export class RewardsPanel extends React.Component { chrome.braveRewards.getACEnabled(((enabled: boolean) => { this.props.actions.onEnabledAC(enabled) })) + chrome.braveRewards.getRecurringDonations((donations: RewardsExtension.RecurringDonation) => { + this.props.actions.onRecurringDonations(donations) + }) } componentDidUpdate (prevProps: Props, prevState: State) { diff --git a/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx b/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx index 859b29523737..6aee75684de6 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx +++ b/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx @@ -25,15 +25,20 @@ interface Props extends RewardsExtension.ComponentProps { interface State { showSummary: boolean publisherKey: string | null + newMonthlyAmount: string | null } export class Panel extends React.Component { + private defaultDonationAmounts: number[] + constructor (props: Props) { super(props) this.state = { showSummary: true, - publisherKey: null + publisherKey: null, + newMonthlyAmount: null } + this.defaultDonationAmounts = [1, 5, 10] } get actions () { @@ -335,6 +340,71 @@ export class Panel extends React.Component { } } + onContributionAmountChange = (event: React.ChangeEvent) => { + let newMonthlyAmount: string + const newValue = parseInt(event.target.value, 10) + const publisher: RewardsExtension.Publisher | undefined = this.getPublisher() + + if (!publisher || !publisher.publisher_key) { + return + } + + const publisherKey = publisher.publisher_key + + if (newValue === 0) { + newMonthlyAmount = '0.0' + this.actions.removeRecurringContribution(publisherKey) + } else { + newMonthlyAmount = newValue.toFixed(1).toString() + this.actions.saveRecurringDonation(publisherKey, newValue) + } + + this.setState({ + newMonthlyAmount: newMonthlyAmount + }) + } + + generateAmounts = (publisher?: RewardsExtension.Publisher) => { + const { donationAmounts } = this.props.rewardsPanelData + const { rates } = this.props.rewardsPanelData.walletProperties + + const publisherKey = publisher && publisher.publisher_key + const initialAmounts = ( + !publisherKey || + !donationAmounts || + !donationAmounts[publisherKey] || + donationAmounts[publisherKey].length === 0 + ) ? this.defaultDonationAmounts : donationAmounts[publisherKey] + + const amounts = [0, ...initialAmounts] + + return amounts.map((value: number) => { + return { + tokens: value.toFixed(1), + converted: utils.convertBalance(value.toString(), rates), + selected: false + } + }) + } + + getContribution = (publisher?: RewardsExtension.Publisher) => { + let defaultContribution = '0.0' + const { recurringDonations } = this.props.rewardsPanelData + + if (!recurringDonations || + (!publisher || !publisher.publisher_key)) { + return defaultContribution + } + + recurringDonations.map((donation: any) => { + if (donation.publisherKey === publisher.publisher_key) { + defaultContribution = donation.amount.toFixed(1) + } + }) + + return defaultContribution + } + render () { const { pendingContributionTotal, enabledAC } = this.props.rewardsPanelData const { balance, rates, grants } = this.props.rewardsPanelData.walletProperties @@ -345,6 +415,10 @@ export class Panel extends React.Component { const notificationType = this.getNotificationProp('type', notification) const notificationClick = this.getNotificationClickEvent(notificationType, notificationId) const { currentGrant } = this.props.rewardsPanelData + const defaultContribution = this.getContribution(publisher) + const donationAmounts = defaultContribution !== '0.0' + ? this.generateAmounts(publisher) + : undefined const pendingTotal = parseFloat( (pendingContributionTotal || 0).toFixed(1)) @@ -398,17 +472,18 @@ export class Panel extends React.Component { platform={publisher.provider as Provider} publisherName={publisher.name} publisherImg={faviconUrl} - monthlyAmount={'10.0'} + monthlyAmount={this.state.newMonthlyAmount || defaultContribution} isVerified={publisher.verified} tipsEnabled={true} includeInAuto={!publisher.excluded} attentionScore={(publisher.percentage || 0).toString()} onToggleTips={this.doNothing} donationAction={this.showDonateToSiteDetail} - onAmountChange={this.doNothing} + onAmountChange={this.onContributionAmountChange} onIncludeInAuto={this.switchAutoContribute} showUnVerified={!publisher.verified} acEnabled={enabledAC} + donationAmounts={donationAmounts} moreLink={'https://brave.com/faq-rewards/#unclaimed-funds'} /> : null diff --git a/components/brave_rewards/resources/extension/brave_rewards/constants/rewards_panel_types.ts b/components/brave_rewards/resources/extension/brave_rewards/constants/rewards_panel_types.ts index 2811e4a38df2..87e58b65b210 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/constants/rewards_panel_types.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/constants/rewards_panel_types.ts @@ -30,7 +30,11 @@ export const enum types { ON_ENABLED_AC = '@@rewards_panel/ON_ENABLED_AC', ON_PUBLISHER_LIST_NORMALIZED = '@@rewards_panel/ON_PUBLISHER_LIST_NORMALIZED', ON_EXCLUDED_SITES_CHANGED = '@@rewards_panel/ON_EXCLUDED_SITES_CHANGED', - ON_SETTING_SAVE = '@@rewards_panel/ON_SETTING_SAVE' + ON_SETTING_SAVE = '@@rewards_panel/ON_SETTING_SAVE', + SAVE_RECURRING_DONATION = '@@rewards_panel/SAVE_RECURRING_DONATION', + REMOVE_RECURRING_DONATION = '@@rewards_panel/REMOVE_RECURRING_DONATION', + ON_RECURRING_DONATIONS = '@@rewards_panel/ON_RECURRING_DONATIONS', + ON_PUBLISHER_BANNER = '@@rewards_panel/ON_PUBLISHER_BANNER' } // Note: This declaration must match the RewardsNotificationType enum in diff --git a/components/definitions/chromel.d.ts b/components/definitions/chromel.d.ts index 4aaed0ff3de3..5c666443038c 100644 --- a/components/definitions/chromel.d.ts +++ b/components/definitions/chromel.d.ts @@ -63,7 +63,14 @@ declare namespace chrome.braveRewards { const onExcludedSitesChanged: { addListener: (callback: (properties: RewardsExtension.ExcludedSitesChanged) => void) => void } + const onRecurringDonations: { + addListener: (callback: (donations: Record[]) => void) => {} + } const saveSetting: (key: string, value: string) => {} + const getRecurringDonations: (callback: (donations: RewardsExtension.RecurringDonation) => void) => {} + const saveRecurringDonation: (publisherKey: string, newAmount: string) => {} + const removeRecurringDonation: (publisherKey: string) => {} + const getPublisherBanner: (publisherKey: string, callback: (banner: RewardsExtension.PublisherBanner) => void) => {} } declare namespace chrome.rewardsNotifications { diff --git a/components/definitions/rewardsExtensions.d.ts b/components/definitions/rewardsExtensions.d.ts index a881db197690..066699db7711 100644 --- a/components/definitions/rewardsExtensions.d.ts +++ b/components/definitions/rewardsExtensions.d.ts @@ -13,6 +13,8 @@ declare namespace RewardsExtension { walletCreating: boolean walletCreateFailed: boolean walletProperties: WalletProperties + recurringDonations: Record[] + donationAmounts: Record } interface ApplicationState { @@ -125,4 +127,21 @@ declare namespace RewardsExtension { publisher_key: string excluded: boolean } + + interface RecurringDonation { + recurringDonations: Record[] + } + + interface PublisherBanner { + publisherKey: string + name: string + title: string + description: string + background: string + logo: string + amounts: number[], + provider: string + social: Record + verified: boolean + } } diff --git a/package-lock.json b/package-lock.json index f3e35badf8ed..1d95118cea02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1597,8 +1597,8 @@ } }, "brave-ui": { - "version": "github:brave/brave-ui#d59401050d87a59bc15f743dab8ce06454b08671", - "from": "github:brave/brave-ui#d59401050d87a59bc15f743dab8ce06454b08671", + "version": "github:brave/brave-ui#716ae8111f69993010e8ba54e37d054387f3212c", + "from": "github:brave/brave-ui#716ae8111f69993010e8ba54e37d054387f3212c", "dev": true, "requires": { "@ctrl/tinycolor": "^2.2.1", diff --git a/package.json b/package.json index 7b3badbc3152..60316a902eed 100644 --- a/package.json +++ b/package.json @@ -277,7 +277,7 @@ "@types/react-redux": "6.0.4", "@types/redux-logger": "^3.0.7", "awesome-typescript-loader": "^5.2.1", - "brave-ui": "github:brave/brave-ui#d59401050d87a59bc15f743dab8ce06454b08671", + "brave-ui": "github:brave/brave-ui#716ae8111f69993010e8ba54e37d054387f3212c", "css-loader": "^2.1.1", "csstype": "^2.5.5", "deep-freeze-node": "^1.1.3", From 5d9baecf6b068a6a3563027dce673d855a76afe5 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Mon, 8 Apr 2019 12:00:13 +0200 Subject: [PATCH 2/2] Fixes rebase problems --- browser/extensions/api/brave_rewards_api.cc | 53 +++++++++---------- browser/extensions/api/brave_rewards_api.h | 20 +++---- browser/ui/webui/brave_donate_ui.cc | 14 +++++ common/extensions/api/brave_rewards.json | 46 ++++++++-------- .../extension_rewards_service_observer.cc | 37 +++++++------ .../extension_rewards_service_observer.h | 10 ++-- .../brave_rewards/browser/rewards_service.h | 6 +-- .../browser/rewards_service_impl.h | 6 +-- .../donate/actions/donate_actions.ts | 4 ++ .../resources/donate/brave_donate.tsx | 7 ++- .../donate/constants/donate_types.ts | 3 +- .../donate/reducers/donate_reducer.ts | 1 + .../_locales/en_US/messages.json | 2 +- .../actions/rewards_panel_actions.ts | 6 +-- .../background/events/rewardsEvents.ts | 18 +++++-- .../reducers/rewards_panel_reducer.ts | 18 +++---- .../brave_rewards/background/storage.ts | 4 +- .../brave_rewards/components/app.tsx | 6 ++- .../brave_rewards/components/panel.tsx | 45 +++++++--------- .../constants/rewards_panel_types.ts | 6 +-- components/definitions/chromel.d.ts | 15 +++--- components/definitions/rewardsExtensions.d.ts | 8 +-- package-lock.json | 4 +- package.json | 2 +- 24 files changed, 184 insertions(+), 157 deletions(-) diff --git a/browser/extensions/api/brave_rewards_api.cc b/browser/extensions/api/brave_rewards_api.cc index c5eac7adefde..e6ba202647ec 100644 --- a/browser/extensions/api/brave_rewards_api.cc +++ b/browser/extensions/api/brave_rewards_api.cc @@ -291,54 +291,53 @@ ExtensionFunction::ResponseAction BraveRewardsSaveSettingFunction::Run() { return RespondNow(NoArguments()); } -BraveRewardsSaveRecurringDonationFunction:: -~BraveRewardsSaveRecurringDonationFunction() { +BraveRewardsSaveRecurringTipFunction:: +~BraveRewardsSaveRecurringTipFunction() { } ExtensionFunction::ResponseAction - BraveRewardsSaveRecurringDonationFunction::Run() { - - std::unique_ptr params( - brave_rewards::SaveRecurringDonation::Params::Create(*args_)); +BraveRewardsSaveRecurringTipFunction::Run() { + std::unique_ptr params( + brave_rewards::SaveRecurringTip::Params::Create(*args_)); Profile* profile = Profile::FromBrowserContext(browser_context()); RewardsService* rewards_service_ = RewardsServiceFactory::GetForProfile(profile); if (rewards_service_) { - rewards_service_->SaveRecurringDonation( - params->publisher_key, params->new_amount); + rewards_service_->SaveRecurringTip(params->publisher_key, + params->new_amount); } return RespondNow(NoArguments()); } -BraveRewardsRemoveRecurringDonationFunction:: -~BraveRewardsRemoveRecurringDonationFunction() { +BraveRewardsRemoveRecurringTipFunction:: +~BraveRewardsRemoveRecurringTipFunction() { } ExtensionFunction::ResponseAction - BraveRewardsRemoveRecurringDonationFunction::Run() { - std::unique_ptr params( - brave_rewards::RemoveRecurringDonation::Params::Create(*args_)); +BraveRewardsRemoveRecurringTipFunction::Run() { + std::unique_ptr params( + brave_rewards::RemoveRecurringTip::Params::Create(*args_)); Profile* profile = Profile::FromBrowserContext(browser_context()); RewardsService* rewards_service_ = RewardsServiceFactory::GetForProfile(profile); if (rewards_service_) { - rewards_service_->RemoveRecurring(params->publisher_key); + rewards_service_->RemoveRecurringTip(params->publisher_key); } return RespondNow(NoArguments()); } -BraveRewardsGetRecurringDonationsFunction:: -~BraveRewardsGetRecurringDonationsFunction() { +BraveRewardsGetRecurringTipsFunction:: +~BraveRewardsGetRecurringTipsFunction() { } ExtensionFunction::ResponseAction -BraveRewardsGetRecurringDonationsFunction::Run() { +BraveRewardsGetRecurringTipsFunction::Run() { Profile* profile = Profile::FromBrowserContext(browser_context()); RewardsService* rewards_service = RewardsServiceFactory::GetForProfile(profile); @@ -347,27 +346,27 @@ BraveRewardsGetRecurringDonationsFunction::Run() { return RespondNow(Error("Rewards service is not initialized")); } - rewards_service->GetRecurringDonationsList(base::Bind( - &BraveRewardsGetRecurringDonationsFunction::OnGetRecurringDonations, + rewards_service->GetRecurringTipsUI(base::Bind( + &BraveRewardsGetRecurringTipsFunction::OnGetRecurringTips, this)); return RespondLater(); } -void BraveRewardsGetRecurringDonationsFunction::OnGetRecurringDonations( +void BraveRewardsGetRecurringTipsFunction::OnGetRecurringTips( std::unique_ptr<::brave_rewards::ContentSiteList> list) { std::unique_ptr result(new base::DictionaryValue()); - auto recurringDonations = std::make_unique(); + auto recurringTips = std::make_unique(); if (!list->empty()) { - for (auto const& item: *list) { - auto recurringDonation = std::make_unique(); - recurringDonation->SetString("publisherKey", item.id); - recurringDonation->SetInteger("amount", item.weight); - recurringDonations->Append(std::move(recurringDonation)); + for (auto const& item : *list) { + auto tip = std::make_unique(); + tip->SetString("publisherKey", item.id); + tip->SetInteger("amount", item.weight); + recurringTips->Append(std::move(tip)); } } - result->SetList("recurringDonations", std::move(recurringDonations)); + result->SetList("recurringTips", std::move(recurringTips)); Respond(OneArgument(std::move(result))); } diff --git a/browser/extensions/api/brave_rewards_api.h b/browser/extensions/api/brave_rewards_api.h index 8d150e85f3d8..8b945dd97e43 100644 --- a/browser/extensions/api/brave_rewards_api.h +++ b/browser/extensions/api/brave_rewards_api.h @@ -169,40 +169,40 @@ class BraveRewardsSaveSettingFunction : public UIThreadExtensionFunction { ResponseAction Run() override; }; -class BraveRewardsSaveRecurringDonationFunction : +class BraveRewardsSaveRecurringTipFunction : public UIThreadExtensionFunction { public: - DECLARE_EXTENSION_FUNCTION("braveRewards.saveRecurringDonation", UNKNOWN) + DECLARE_EXTENSION_FUNCTION("braveRewards.saveRecurringTip", UNKNOWN) protected: - ~BraveRewardsSaveRecurringDonationFunction() override; + ~BraveRewardsSaveRecurringTipFunction() override; ResponseAction Run() override; }; -class BraveRewardsRemoveRecurringDonationFunction : +class BraveRewardsRemoveRecurringTipFunction : public UIThreadExtensionFunction { public: - DECLARE_EXTENSION_FUNCTION("braveRewards.removeRecurringDonation", UNKNOWN) + DECLARE_EXTENSION_FUNCTION("braveRewards.removeRecurringTip", UNKNOWN) protected: - ~BraveRewardsRemoveRecurringDonationFunction() override; + ~BraveRewardsRemoveRecurringTipFunction() override; ResponseAction Run() override; }; -class BraveRewardsGetRecurringDonationsFunction : +class BraveRewardsGetRecurringTipsFunction : public UIThreadExtensionFunction { public: - DECLARE_EXTENSION_FUNCTION("braveRewards.getRecurringDonations", UNKNOWN) + DECLARE_EXTENSION_FUNCTION("braveRewards.getRecurringTips", UNKNOWN) protected: - ~BraveRewardsGetRecurringDonationsFunction() override; + ~BraveRewardsGetRecurringTipsFunction() override; ResponseAction Run() override; private: - void OnGetRecurringDonations( + void OnGetRecurringTips( std::unique_ptr list); }; diff --git a/browser/ui/webui/brave_donate_ui.cc b/browser/ui/webui/brave_donate_ui.cc index 7b9c6f756e3a..77608736f31c 100644 --- a/browser/ui/webui/brave_donate_ui.cc +++ b/browser/ui/webui/brave_donate_ui.cc @@ -67,6 +67,9 @@ class RewardsDonateDOMHandler : public WebUIMessageHandler, std::unique_ptr wallet_properties) override; + void OnRecurringTipSaved(brave_rewards::RewardsService* rewards_service, + bool success) override; + void OnRecurringTipRemoved(brave_rewards::RewardsService* rewards_service, bool success) override; @@ -316,5 +319,16 @@ void RewardsDonateDOMHandler::OnRecurringTipRemoved( "brave_rewards_donate.recurringTipRemoved", base::Value(success)); } +void RewardsDonateDOMHandler::OnRecurringTipSaved( + brave_rewards::RewardsService* rewards_service, + bool success) { + if (!web_ui()->CanCallJavascript()) { + return; + } + + web_ui()->CallJavascriptFunctionUnsafe( + "brave_rewards_donate.recurringTipSaved", base::Value(success)); +} + BraveDonateUI::~BraveDonateUI() { } diff --git a/common/extensions/api/brave_rewards.json b/common/extensions/api/brave_rewards.json index 1b0e5a4fc196..01dcd78ed4da 100644 --- a/common/extensions/api/brave_rewards.json +++ b/common/extensions/api/brave_rewards.json @@ -289,26 +289,24 @@ ] }, { - "name": "onRecurringDonations", + "name": "onRecurringTipSaved", "type": "function", - "description": "Fired when publisher recurring donations modified", + "description": "Fired when publisher recurring tip is saved", "parameters": [ { - "name": "donations", - "type": "array", - "items": { - "type": "object", - "properties": { - "publisherKey": { - "type": "string", - "description": "publisher key, unique identifier" - }, - "amount": { - "type": "integer", - "description": "publisher donation amount" - } - } - } + "name": "success", + "type": "boolean" + } + ] + }, + { + "name": "onRecurringTipRemoved", + "type": "function", + "description": "Fired when publisher recurring tip is removed", + "parameters": [ + { + "name": "success", + "type": "boolean" } ] } @@ -503,9 +501,9 @@ ] }, { - "name": "saveRecurringDonation", + "name": "saveRecurringTip", "type": "function", - "description": "Updates recurring donation amount for rewards panel", + "description": "Updates recurring tip amount for rewards panel", "parameters": [ { "name": "publisher_key", @@ -518,9 +516,9 @@ ] }, { - "name": "removeRecurringDonation", + "name": "removeRecurringTip", "type": "function", - "description": "Removes recurring donation for rewards panel", + "description": "Removes recurring tip for rewards panel", "parameters": [ { "name": "publisher_key", @@ -529,16 +527,16 @@ ] }, { - "name": "getRecurringDonations", + "name": "getRecurringTips", "type": "function", - "description": "Gets list of sites with recurring donation data", + "description": "Gets list of sites with recurring tip data", "parameters": [ { "type": "function", "name": "callback", "parameters": [ { - "name": "donations", + "name": "tips", "type": "any" } ] diff --git a/components/brave_rewards/browser/extension_rewards_service_observer.cc b/components/brave_rewards/browser/extension_rewards_service_observer.cc index f023e133c30f..9d9485580b7f 100644 --- a/components/brave_rewards/browser/extension_rewards_service_observer.cc +++ b/components/brave_rewards/browser/extension_rewards_service_observer.cc @@ -325,35 +325,38 @@ void ExtensionRewardsServiceObserver::OnExcludedSitesChanged( event_router->BroadcastEvent(std::move(event)); } -void ExtensionRewardsServiceObserver::OnRecurringDonationUpdated( +void ExtensionRewardsServiceObserver::OnRecurringTipSaved( RewardsService* rewards_service, - brave_rewards::ContentSiteList list) { + bool success) { auto* event_router = extensions::EventRouter::Get(profile_); if (!event_router) { return; } - std::vector donations; - - for (size_t i = 0; i < list.size(); i++) { - donations.push_back( - extensions::api::brave_rewards::OnRecurringDonations:: - DonationsType()); + std::unique_ptr args( + extensions::api::brave_rewards::OnRecurringTipSaved::Create( + success).release()); + std::unique_ptr event(new extensions::Event( + extensions::events::BRAVE_START, + extensions::api::brave_rewards::OnRecurringTipSaved::kEventName, + std::move(args))); + event_router->BroadcastEvent(std::move(event)); +} - auto& donation = donations[donations.size() - 1]; - donation.publisher_key = list[i].id; - donation.amount = list[i].percentage; +void ExtensionRewardsServiceObserver::OnRecurringTipRemoved( + RewardsService* rewards_service, + bool success) { + auto* event_router = extensions::EventRouter::Get(profile_); + if (!event_router) { + return; } std::unique_ptr args( - extensions::api::brave_rewards:: - OnRecurringDonations::Create(donations) - .release()); - + extensions::api::brave_rewards::OnRecurringTipRemoved::Create( + success).release()); std::unique_ptr event(new extensions::Event( extensions::events::BRAVE_START, - extensions::api::brave_rewards::OnRecurringDonations::kEventName, + extensions::api::brave_rewards::OnRecurringTipRemoved::kEventName, std::move(args))); event_router->BroadcastEvent(std::move(event)); } diff --git a/components/brave_rewards/browser/extension_rewards_service_observer.h b/components/brave_rewards/browser/extension_rewards_service_observer.h index ad91787df328..4f0bcca605fe 100644 --- a/components/brave_rewards/browser/extension_rewards_service_observer.h +++ b/components/brave_rewards/browser/extension_rewards_service_observer.h @@ -40,6 +40,12 @@ class ExtensionRewardsServiceObserver : public RewardsServiceObserver, std::string publisher_key, bool excluded) override; + void OnRecurringTipSaved(RewardsService* rewards_service, + bool success) override; + + void OnRecurringTipRemoved(RewardsService* rewards_service, + bool success) override; + // RewardsServicePrivateObserver implementation void OnGetCurrentBalanceReport(RewardsService* rewards_service, const BalanceReport& balance_report) override; @@ -63,10 +69,6 @@ class ExtensionRewardsServiceObserver : public RewardsServiceObserver, void OnPendingContributionSaved(RewardsService* rewards_service, int result) override; - void OnRecurringDonationUpdated( - RewardsService* rewards_service, - brave_rewards::ContentSiteList list) override; - private: Profile* profile_; diff --git a/components/brave_rewards/browser/rewards_service.h b/components/brave_rewards/browser/rewards_service.h index d0002f9b2738..ad464a996592 100644 --- a/components/brave_rewards/browser/rewards_service.h +++ b/components/brave_rewards/browser/rewards_service.h @@ -195,10 +195,8 @@ class RewardsService : public KeyedService { static void RegisterProfilePrefs(PrefRegistrySimple* registry); - virtual void SaveRecurringDonation( - const std::string& publisher_key, const int amount) = 0; - virtual void GetRecurringDonationsList( - GetRecurringDonationsListCallback callback) = 0; + virtual void SaveRecurringTip(const std::string& publisher_key, + const int amount) = 0; protected: base::ObserverList observers_; diff --git a/components/brave_rewards/browser/rewards_service_impl.h b/components/brave_rewards/browser/rewards_service_impl.h index f11c03b4f81d..c5f0e0c2491d 100644 --- a/components/brave_rewards/browser/rewards_service_impl.h +++ b/components/brave_rewards/browser/rewards_service_impl.h @@ -202,7 +202,7 @@ class RewardsServiceImpl : public RewardsService, void GetOneTimeTipsUI(GetOneTimeTipsCallback callback) override; - void SaveRecurringDonation(const std::string& publisher_key, + void SaveRecurringTip(const std::string& publisher_key, const int amount) override; // Testing methods @@ -269,8 +269,6 @@ class RewardsServiceImpl : public RewardsService, void OnContributionInfoSaved(const ledger::REWARDS_CATEGORY category, bool success); void OnRecurringTipSaved(bool success); - void SaveRecurringTip(const std::string& publisher_key, - const int amount); void OnGetRecurringTips( const ledger::PublisherInfoListCallback callback, const ledger::PublisherInfoList list); @@ -390,8 +388,6 @@ class RewardsServiceImpl : public RewardsService, const ledger::REWARDS_CATEGORY category) override; void GetRecurringTips( ledger::PublisherInfoListCallback callback) override; - void GetRecurringDonationsList( - GetRecurringDonationsListCallback callback) override; std::unique_ptr Log( const char* file, int line, diff --git a/components/brave_rewards/resources/donate/actions/donate_actions.ts b/components/brave_rewards/resources/donate/actions/donate_actions.ts index 531fb192f5bd..f586fe0c22f5 100644 --- a/components/brave_rewards/resources/donate/actions/donate_actions.ts +++ b/components/brave_rewards/resources/donate/actions/donate_actions.ts @@ -41,3 +41,7 @@ export const onReconcileStamp = (stamp: number) => action(types.ON_RECONCILE_STA export const onRecurringTipRemoved = (success: boolean) => action(types.ON_RECURRING_TIP_REMOVED, { success }) + +export const onRecurringTipSaved = (success: boolean) => action(types.ON_RECURRING_TIP_SAVED, { + success +}) diff --git a/components/brave_rewards/resources/donate/brave_donate.tsx b/components/brave_rewards/resources/donate/brave_donate.tsx index 36ff9d8eb68f..eff1ff988524 100644 --- a/components/brave_rewards/resources/donate/brave_donate.tsx +++ b/components/brave_rewards/resources/donate/brave_donate.tsx @@ -79,13 +79,18 @@ window.cr.define('brave_rewards_donate', function () { getActions().onRecurringTipRemoved(success) } + function recurringTipSaved (success: boolean) { + getActions().onRecurringTipSaved(success) + } + return { initialize, publisherBanner, walletProperties, recurringTips, reconcileStamp, - recurringTipRemoved + recurringTipRemoved, + recurringTipSaved } }) diff --git a/components/brave_rewards/resources/donate/constants/donate_types.ts b/components/brave_rewards/resources/donate/constants/donate_types.ts index fdcbd95f12a4..a41c8eed6011 100644 --- a/components/brave_rewards/resources/donate/constants/donate_types.ts +++ b/components/brave_rewards/resources/donate/constants/donate_types.ts @@ -12,5 +12,6 @@ export const enum types { ON_RECURRING_TIPS = '@@rewards/ON_RECURRING_TIPS', GET_RECONCILE_STAMP = '@@rewards/GET_RECONCILE_STAMP', ON_RECONCILE_STAMP = '@@rewards/ON_RECONCILE_STAMP', - ON_RECURRING_TIP_REMOVED = '@@rewards/ON_RECURRING_TIP_REMOVED' + ON_RECURRING_TIP_REMOVED = '@@rewards/ON_RECURRING_TIP_REMOVED', + ON_RECURRING_TIP_SAVED = '@@rewards/ON_RECURRING_TIP_SAVED' } diff --git a/components/brave_rewards/resources/donate/reducers/donate_reducer.ts b/components/brave_rewards/resources/donate/reducers/donate_reducer.ts index 2e6acccf4914..a8a4a085c402 100644 --- a/components/brave_rewards/resources/donate/reducers/donate_reducer.ts +++ b/components/brave_rewards/resources/donate/reducers/donate_reducer.ts @@ -71,6 +71,7 @@ const publishersReducer: Reducer = (state: RewardsDonate.St } case types.GET_RECURRING_TIPS: case types.ON_RECURRING_TIP_REMOVED: + case types.ON_RECURRING_TIP_SAVED: chrome.send('brave_rewards_donate.getRecurringTips') break case types.ON_RECURRING_TIPS: diff --git a/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json b/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json index 536cb4ed4c24..5d8b17fb25cb 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json +++ b/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json @@ -391,6 +391,6 @@ }, "bat": { "message": "BAT", - "description": "BAT text for displaying converted donation amount." + "description": "BAT text for displaying converted tip amount." } } diff --git a/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts b/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts index dd6385f77adc..6c0d4f27c5c8 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/actions/rewards_panel_actions.ts @@ -115,16 +115,16 @@ export const onSettingSave = (key: string, value: any) => action(types.ON_SETTIN value }) -export const saveRecurringDonation = (publisherKey: string, newAmount: number) => action(types.SAVE_RECURRING_DONATION, { +export const saveRecurringTip = (publisherKey: string, newAmount: number) => action(types.SAVE_RECURRING_TIP, { publisherKey, newAmount }) -export const removeRecurringContribution = (publisherKey: string) => action(types.REMOVE_RECURRING_DONATION, { +export const removeRecurringTip = (publisherKey: string) => action(types.REMOVE_RECURRING_TIP, { publisherKey }) -export const onRecurringDonations = (result: RewardsExtension.RecurringDonation) => action(types.ON_RECURRING_DONATIONS, { +export const onRecurringTips = (result: RewardsExtension.RecurringTips) => action(types.ON_RECURRING_TIPS, { result }) diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/events/rewardsEvents.ts b/components/brave_rewards/resources/extension/brave_rewards/background/events/rewardsEvents.ts index 9d3117b9d437..52d2bbab2f9b 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/events/rewardsEvents.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/events/rewardsEvents.ts @@ -71,8 +71,18 @@ chrome.braveRewards.onExcludedSitesChanged.addListener((properties: RewardsExten rewardsPanelActions.onExcludedSitesChanged(properties) }) -chrome.braveRewards.onRecurringDonations.addListener((donations: Record[]) => { - rewardsPanelActions.onRecurringDonations({ - recurringDonations: donations - }) +chrome.braveRewards.onRecurringTipSaved.addListener((success: boolean) => { + if (success) { + chrome.braveRewards.getRecurringTips((tips: RewardsExtension.RecurringTips) => { + rewardsPanelActions.onRecurringTips(tips) + }) + } +}) + +chrome.braveRewards.onRecurringTipRemoved.addListener((success: boolean) => { + if (success) { + chrome.braveRewards.getRecurringTips((tips: RewardsExtension.RecurringTips) => { + rewardsPanelActions.onRecurringTips(tips) + }) + } }) diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts b/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts index 7c23c467c5bc..a76d048e966d 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/reducers/rewards_panel_reducer.ts @@ -305,15 +305,15 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a } break } - case types.REMOVE_RECURRING_DONATION: { + case types.REMOVE_RECURRING_TIP: { let publisherKey = payload.publisherKey if (publisherKey == null) { break } - chrome.braveRewards.removeRecurringDonation(publisherKey) + chrome.braveRewards.removeRecurringTip(publisherKey) break } - case types.SAVE_RECURRING_DONATION: { + case types.SAVE_RECURRING_TIP: { let newAmount = payload.newAmount let publisherKey = payload.publisherKey @@ -323,12 +323,12 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a break } - chrome.braveRewards.saveRecurringDonation(publisherKey, newAmount) + chrome.braveRewards.saveRecurringTip(publisherKey, newAmount) break } - case types.ON_RECURRING_DONATIONS: { + case types.ON_RECURRING_TIPS: { state = { ...state } - state.recurringDonations = payload.result.recurringDonations + state.recurringTips = payload.result.recurringTips break } case types.ON_PUBLISHER_BANNER: { @@ -337,10 +337,10 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a } state = { ...state } - if (!state.donationAmounts) { - state.donationAmounts = {} + if (!state.tipAmounts) { + state.tipAmounts = {} } - state.donationAmounts[payload.banner.publisherKey] = payload.banner.amounts + state.tipAmounts[payload.banner.publisherKey] = payload.banner.amounts break } } diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/storage.ts b/components/brave_rewards/resources/extension/brave_rewards/background/storage.ts index 0c679ee5f14b..ad1f580363dd 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/storage.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/storage.ts @@ -36,8 +36,8 @@ export const defaultState: RewardsExtension.State = { enabledAC: false, grants: [], currentGrant: undefined, - recurringDonations: [], - donationAmounts: {} + recurringTips: [], + tipAmounts: {} } const cleanData = (state: RewardsExtension.State) => { diff --git a/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx b/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx index 71b2b10f47ce..e8cedbf4eea5 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx +++ b/components/brave_rewards/resources/extension/brave_rewards/components/app.tsx @@ -40,11 +40,13 @@ export class RewardsPanel extends React.Component { chrome.braveRewards.getRewardsMainEnabled(((enabled: boolean) => { this.props.actions.onEnabledMain(enabled) })) + chrome.braveRewards.getACEnabled(((enabled: boolean) => { this.props.actions.onEnabledAC(enabled) })) - chrome.braveRewards.getRecurringDonations((donations: RewardsExtension.RecurringDonation) => { - this.props.actions.onRecurringDonations(donations) + + chrome.braveRewards.getRecurringTips((tips: RewardsExtension.RecurringTips) => { + this.props.actions.onRecurringTips(tips) }) } diff --git a/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx b/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx index 6aee75684de6..43250088abf2 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx +++ b/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx @@ -25,20 +25,18 @@ interface Props extends RewardsExtension.ComponentProps { interface State { showSummary: boolean publisherKey: string | null - newMonthlyAmount: string | null } export class Panel extends React.Component { - private defaultDonationAmounts: number[] + private defaultTipAmounts: number[] constructor (props: Props) { super(props) this.state = { showSummary: true, - publisherKey: null, - newMonthlyAmount: null + publisherKey: null } - this.defaultDonationAmounts = [1, 5, 10] + this.defaultTipAmounts = [1, 5, 10] } get actions () { @@ -341,7 +339,6 @@ export class Panel extends React.Component { } onContributionAmountChange = (event: React.ChangeEvent) => { - let newMonthlyAmount: string const newValue = parseInt(event.target.value, 10) const publisher: RewardsExtension.Publisher | undefined = this.getPublisher() @@ -352,29 +349,23 @@ export class Panel extends React.Component { const publisherKey = publisher.publisher_key if (newValue === 0) { - newMonthlyAmount = '0.0' - this.actions.removeRecurringContribution(publisherKey) + this.actions.removeRecurringTip(publisherKey) } else { - newMonthlyAmount = newValue.toFixed(1).toString() - this.actions.saveRecurringDonation(publisherKey, newValue) + this.actions.saveRecurringTip(publisherKey, newValue) } - - this.setState({ - newMonthlyAmount: newMonthlyAmount - }) } generateAmounts = (publisher?: RewardsExtension.Publisher) => { - const { donationAmounts } = this.props.rewardsPanelData + const { tipAmounts } = this.props.rewardsPanelData const { rates } = this.props.rewardsPanelData.walletProperties const publisherKey = publisher && publisher.publisher_key const initialAmounts = ( !publisherKey || - !donationAmounts || - !donationAmounts[publisherKey] || - donationAmounts[publisherKey].length === 0 - ) ? this.defaultDonationAmounts : donationAmounts[publisherKey] + !tipAmounts || + !tipAmounts[publisherKey] || + tipAmounts[publisherKey].length === 0 + ) ? this.defaultTipAmounts : tipAmounts[publisherKey] const amounts = [0, ...initialAmounts] @@ -389,16 +380,16 @@ export class Panel extends React.Component { getContribution = (publisher?: RewardsExtension.Publisher) => { let defaultContribution = '0.0' - const { recurringDonations } = this.props.rewardsPanelData + const { recurringTips } = this.props.rewardsPanelData - if (!recurringDonations || + if (!recurringTips || (!publisher || !publisher.publisher_key)) { return defaultContribution } - recurringDonations.map((donation: any) => { - if (donation.publisherKey === publisher.publisher_key) { - defaultContribution = donation.amount.toFixed(1) + recurringTips.map((tip: any) => { + if (tip.publisherKey === publisher.publisher_key) { + defaultContribution = tip.amount.toFixed(1) } }) @@ -416,7 +407,7 @@ export class Panel extends React.Component { const notificationClick = this.getNotificationClickEvent(notificationType, notificationId) const { currentGrant } = this.props.rewardsPanelData const defaultContribution = this.getContribution(publisher) - const donationAmounts = defaultContribution !== '0.0' + const tipAmounts = defaultContribution !== '0.0' ? this.generateAmounts(publisher) : undefined @@ -472,7 +463,7 @@ export class Panel extends React.Component { platform={publisher.provider as Provider} publisherName={publisher.name} publisherImg={faviconUrl} - monthlyAmount={this.state.newMonthlyAmount || defaultContribution} + monthlyAmount={defaultContribution} isVerified={publisher.verified} tipsEnabled={true} includeInAuto={!publisher.excluded} @@ -483,7 +474,7 @@ export class Panel extends React.Component { onIncludeInAuto={this.switchAutoContribute} showUnVerified={!publisher.verified} acEnabled={enabledAC} - donationAmounts={donationAmounts} + donationAmounts={tipAmounts} moreLink={'https://brave.com/faq-rewards/#unclaimed-funds'} /> : null diff --git a/components/brave_rewards/resources/extension/brave_rewards/constants/rewards_panel_types.ts b/components/brave_rewards/resources/extension/brave_rewards/constants/rewards_panel_types.ts index 87e58b65b210..c4733657c1b0 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/constants/rewards_panel_types.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/constants/rewards_panel_types.ts @@ -31,9 +31,9 @@ export const enum types { ON_PUBLISHER_LIST_NORMALIZED = '@@rewards_panel/ON_PUBLISHER_LIST_NORMALIZED', ON_EXCLUDED_SITES_CHANGED = '@@rewards_panel/ON_EXCLUDED_SITES_CHANGED', ON_SETTING_SAVE = '@@rewards_panel/ON_SETTING_SAVE', - SAVE_RECURRING_DONATION = '@@rewards_panel/SAVE_RECURRING_DONATION', - REMOVE_RECURRING_DONATION = '@@rewards_panel/REMOVE_RECURRING_DONATION', - ON_RECURRING_DONATIONS = '@@rewards_panel/ON_RECURRING_DONATIONS', + SAVE_RECURRING_TIP = '@@rewards_panel/SAVE_RECURRING_TIP', + REMOVE_RECURRING_TIP = '@@rewards_panel/REMOVE_RECURRING_TIP', + ON_RECURRING_TIPS = '@@rewards_panel/ON_RECURRING_TIPS', ON_PUBLISHER_BANNER = '@@rewards_panel/ON_PUBLISHER_BANNER' } diff --git a/components/definitions/chromel.d.ts b/components/definitions/chromel.d.ts index 5c666443038c..52d2221c8f1e 100644 --- a/components/definitions/chromel.d.ts +++ b/components/definitions/chromel.d.ts @@ -63,14 +63,17 @@ declare namespace chrome.braveRewards { const onExcludedSitesChanged: { addListener: (callback: (properties: RewardsExtension.ExcludedSitesChanged) => void) => void } - const onRecurringDonations: { - addListener: (callback: (donations: Record[]) => void) => {} - } const saveSetting: (key: string, value: string) => {} - const getRecurringDonations: (callback: (donations: RewardsExtension.RecurringDonation) => void) => {} - const saveRecurringDonation: (publisherKey: string, newAmount: string) => {} - const removeRecurringDonation: (publisherKey: string) => {} + const getRecurringTips: (callback: (tips: RewardsExtension.RecurringTips) => void) => {} + const saveRecurringTip: (publisherKey: string, newAmount: string) => {} + const removeRecurringTip: (publisherKey: string) => {} const getPublisherBanner: (publisherKey: string, callback: (banner: RewardsExtension.PublisherBanner) => void) => {} + const onRecurringTipSaved: { + addListener: (callback: (success: boolean) => void) => void + } + const onRecurringTipRemoved: { + addListener: (callback: (success: boolean) => void) => void + } } declare namespace chrome.rewardsNotifications { diff --git a/components/definitions/rewardsExtensions.d.ts b/components/definitions/rewardsExtensions.d.ts index 066699db7711..f57d812d5b94 100644 --- a/components/definitions/rewardsExtensions.d.ts +++ b/components/definitions/rewardsExtensions.d.ts @@ -13,8 +13,8 @@ declare namespace RewardsExtension { walletCreating: boolean walletCreateFailed: boolean walletProperties: WalletProperties - recurringDonations: Record[] - donationAmounts: Record + recurringTips: Record[] + tipAmounts: Record } interface ApplicationState { @@ -128,8 +128,8 @@ declare namespace RewardsExtension { excluded: boolean } - interface RecurringDonation { - recurringDonations: Record[] + interface RecurringTips { + recurringTips: Record[] } interface PublisherBanner { diff --git a/package-lock.json b/package-lock.json index 1d95118cea02..afea65ebd7c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1597,8 +1597,8 @@ } }, "brave-ui": { - "version": "github:brave/brave-ui#716ae8111f69993010e8ba54e37d054387f3212c", - "from": "github:brave/brave-ui#716ae8111f69993010e8ba54e37d054387f3212c", + "version": "github:brave/brave-ui#1b1ee01094d6caa3336dcd42298c4178e6930185", + "from": "github:brave/brave-ui#1b1ee01094d6caa3336dcd42298c4178e6930185", "dev": true, "requires": { "@ctrl/tinycolor": "^2.2.1", diff --git a/package.json b/package.json index 60316a902eed..6d84c3be151a 100644 --- a/package.json +++ b/package.json @@ -277,7 +277,7 @@ "@types/react-redux": "6.0.4", "@types/redux-logger": "^3.0.7", "awesome-typescript-loader": "^5.2.1", - "brave-ui": "github:brave/brave-ui#716ae8111f69993010e8ba54e37d054387f3212c", + "brave-ui": "github:brave/brave-ui#1b1ee01094d6caa3336dcd42298c4178e6930185", "css-loader": "^2.1.1", "csstype": "^2.5.5", "deep-freeze-node": "^1.1.3",