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
Adds functionality to monthly contribution dropdown (Panel) #957
Merged
+344
−18
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
Fixes brave/brave-browser#2245, monthly donation functionality
- Loading branch information
| @@ -0,0 +1,60 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
| * You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| #include "brave/components/brave_rewards/browser/rewards_service.h" | ||
| #include "brave/components/brave_rewards/browser/rewards_service_factory.h" | ||
| #include "brave/components/brave_rewards/browser/extension_rewards_service_observer.h" | ||
| #include "chrome/browser/ui/browser.h" | ||
| #include "chrome/test/base/in_process_browser_test.h" | ||
| #include "chrome/test/base/ui_test_utils.h" | ||
| #include "content/public/test/browser_test_utils.h" | ||
|
|
||
| using namespace brave_rewards; | ||
|
|
||
| class ExtensionRewardsServiceObserverBrowserTest | ||
| : public InProcessBrowserTest, | ||
| public RewardsServiceObserver { | ||
| public: | ||
|
|
||
| void SetUpOnMainThread() override { | ||
| InProcessBrowserTest::SetUpOnMainThread(); | ||
| rewards_service_ = RewardsServiceFactory::GetForProfile(browser()->profile()); | ||
| } | ||
|
|
||
| void TearDown() override { | ||
| InProcessBrowserTest::TearDown(); | ||
| } | ||
|
|
||
| void OnRecurringDonations( | ||
| RewardsService* rewards_service, | ||
| const ledger::PublisherInfoList& list) override { | ||
|
|
||
| ledger::PublisherInfo firstPublisher = list.front(); | ||
| EXPECT_STREQ(firstPublisher.id.c_str(), "brave.com"); | ||
| EXPECT_STREQ(std::to_string(firstPublisher.weight).c_str(), "10"); | ||
|
|
||
| on_recurring_notifications_callback_was_called_ = true; | ||
| } | ||
|
|
||
| void WaitForOnRecurringDonationsCallback() { | ||
| if (on_recurring_notifications_callback_was_called_) { | ||
| return; | ||
| } | ||
|
|
||
| base::RunLoop run_loop; | ||
| run_loop.Run(); | ||
| } | ||
|
|
||
| RewardsService* rewards_service_; | ||
| bool on_recurring_notifications_callback_was_called_ = false; | ||
| }; | ||
|
|
||
| IN_PROC_BROWSER_TEST_F(ExtensionRewardsServiceObserverBrowserTest, SaveARecurringDonation) { | ||
| rewards_service_->AddObserver(this); | ||
|
|
||
| rewards_service_->AddRecurringPayment("brave.com", 10); | ||
| WaitForOnRecurringDonationsCallback(); | ||
|
|
||
| rewards_service_->RemoveObserver(this); | ||
| } |
| @@ -145,6 +145,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; | ||
| } | ||
| @@ -1504,6 +1505,19 @@ ledger::PublisherInfoList GetRecurringDonationsOnFileTaskRunner(PublisherInfoDat | ||
| void RewardsServiceImpl::OnRecurringDonationsData(const ledger::PublisherInfoListCallback callback, | ||
| const ledger::PublisherInfoList list) { | ||
| callback(list, 0); | ||
|
|
||
| // Incoming ledger::PublisherInfoList needs to be converted to brave_rewards::ContentSiteList | ||
| brave_rewards::ContentSiteList site_list; | ||
| for (auto& info : list) { | ||
| site_list.push_back(PublisherInfoToContentSite(info)); | ||
| } | ||
|
|
||
| TriggerOnRecurringDonations(site_list); | ||
| } | ||
|
|
||
| void RewardsServiceImpl::TriggerOnRecurringDonations(brave_rewards::ContentSiteList list) { | ||
| for (auto& observer : observers_) | ||
| observer.OnRecurringDonations(this, list); | ||
| } | ||
|
|
||
| void RewardsServiceImpl::GetRecurringDonations(ledger::PublisherInfoListCallback callback) { | ||
| @@ -1564,6 +1578,10 @@ void RewardsServiceImpl::OnTipsUpdatedData(const ledger::PublisherInfoList list) | ||
| } | ||
| } | ||
|
|
||
| void RewardsServiceImpl::AddRecurringPayment(const std::string& publisher_key, double new_amount) { | ||
NejcZdovc
Member
|
||
| SaveRecurringDonation(publisher_key, new_amount); | ||
| } | ||
|
|
||
| void RewardsServiceImpl::RemoveRecurring(const std::string& publisher_key) { | ||
| ledger_->RemoveRecurring(publisher_key); | ||
| } | ||
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Using
BRAVE_STARTconstant per @bridiver