From 69c46974241db10745a78d1a7f910785f7ea3cc4 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Tue, 26 May 2020 13:02:44 +0200 Subject: [PATCH] Inline tip --- browser/extensions/api/brave_rewards_api.cc | 19 +++++----- browser/extensions/api/brave_rewards_api.h | 9 +++-- browser/ui/webui/brave_rewards_page_ui.cc | 12 ++++--- common/extensions/api/brave_rewards.json | 2 +- .../browser/ads_service_impl_unittest.cc | 6 ++-- .../brave_rewards/browser/rewards_service.cc | 3 ++ .../brave_rewards/browser/rewards_service.h | 10 +++--- .../browser/rewards_service_impl.cc | 35 ++++++++++++++----- .../browser/rewards_service_impl.h | 12 ++++--- .../browser/rewards_state_browsertest.cc | 9 +++++ components/brave_rewards/common/pref_names.cc | 3 ++ components/brave_rewards/common/pref_names.h | 3 ++ .../android_page/reducers/rewards_reducer.ts | 2 +- .../extension/brave_rewards/background.ts | 4 +-- .../brave_rewards/content_scripts/github.ts | 2 +- .../brave_rewards/content_scripts/reddit.ts | 2 +- .../brave_rewards/content_scripts/twitter.ts | 2 +- .../page/reducers/rewards_reducer.ts | 2 +- components/definitions/chromel.d.ts | 2 +- .../services/bat_ledger/bat_ledger_impl.cc | 14 ++++---- .../services/bat_ledger/bat_ledger_impl.h | 10 +++--- .../public/interfaces/bat_ledger.mojom | 4 +-- test/data/rewards-data/state/ledger_state | 6 +++- .../include/bat/ledger/ledger.h | 7 ++-- .../include/bat/ledger/mojom_structs.h | 2 ++ .../bat/ledger/public/interfaces/ledger.mojom | 7 ++++ .../src/bat/ledger/internal/ledger_impl.cc | 11 +++--- .../src/bat/ledger/internal/ledger_impl.h | 7 ++-- .../bat/ledger/internal/ledger_impl_mock.h | 6 ++-- .../bat/ledger/internal/legacy/bat_state.cc | 4 --- .../bat/ledger/internal/legacy/bat_state.h | 2 -- .../bat/ledger/internal/state/state_keys.h | 3 ++ .../internal/state/state_migration_v2.cc | 12 +++++++ .../bat/ledger/internal/state/state_util.cc | 34 ++++++++++++++++++ .../bat/ledger/internal/state/state_util.h | 12 +++++++ .../src/bat/ledger/internal/wallet/create.cc | 12 +++++++ 36 files changed, 219 insertions(+), 73 deletions(-) diff --git a/browser/extensions/api/brave_rewards_api.cc b/browser/extensions/api/brave_rewards_api.cc index f14579f2f29a..0ab02ec8547d 100644 --- a/browser/extensions/api/brave_rewards_api.cc +++ b/browser/extensions/api/brave_rewards_api.cc @@ -875,14 +875,15 @@ BraveRewardsGetAllNotificationsFunction::Run() { return RespondNow(OneArgument(std::move(list))); } -BraveRewardsGetInlineTipSettingFunction:: -~BraveRewardsGetInlineTipSettingFunction() { +BraveRewardsGetInlineTippingPlatformEnabledFunction:: +~BraveRewardsGetInlineTippingPlatformEnabledFunction() { } ExtensionFunction::ResponseAction -BraveRewardsGetInlineTipSettingFunction::Run() { - std::unique_ptr params( - brave_rewards::GetInlineTipSetting::Params::Create(*args_)); +BraveRewardsGetInlineTippingPlatformEnabledFunction::Run() { + std::unique_ptr + params(brave_rewards::GetInlineTippingPlatformEnabled::Params::Create( + *args_)); Profile* profile = Profile::FromBrowserContext(browser_context()); RewardsService* rewards_service = @@ -891,15 +892,17 @@ BraveRewardsGetInlineTipSettingFunction::Run() { return RespondNow(OneArgument(std::make_unique(false))); } - rewards_service->GetInlineTipSetting( + rewards_service->GetInlineTippingPlatformEnabled( params->key, base::BindOnce( - &BraveRewardsGetInlineTipSettingFunction::OnInlineTipSetting, + &BraveRewardsGetInlineTippingPlatformEnabledFunction:: + OnInlineTipSetting, this)); return RespondLater(); } -void BraveRewardsGetInlineTipSettingFunction::OnInlineTipSetting(bool value) { +void BraveRewardsGetInlineTippingPlatformEnabledFunction::OnInlineTipSetting( + bool value) { Respond(OneArgument(std::make_unique(value))); } diff --git a/browser/extensions/api/brave_rewards_api.h b/browser/extensions/api/brave_rewards_api.h index f1d31a34447e..a3c8dccacaf4 100644 --- a/browser/extensions/api/brave_rewards_api.h +++ b/browser/extensions/api/brave_rewards_api.h @@ -331,12 +331,15 @@ class BraveRewardsGetAllNotificationsFunction : public ExtensionFunction { ResponseAction Run() override; }; -class BraveRewardsGetInlineTipSettingFunction : public ExtensionFunction { +class BraveRewardsGetInlineTippingPlatformEnabledFunction : + public ExtensionFunction { public: - DECLARE_EXTENSION_FUNCTION("braveRewards.getInlineTipSetting", UNKNOWN) + DECLARE_EXTENSION_FUNCTION( + "braveRewards.getInlineTippingPlatformEnabled", + UNKNOWN) protected: - ~BraveRewardsGetInlineTipSettingFunction() override; + ~BraveRewardsGetInlineTippingPlatformEnabledFunction() override; ResponseAction Run() override; diff --git a/browser/ui/webui/brave_rewards_page_ui.cc b/browser/ui/webui/brave_rewards_page_ui.cc index dabcc1baeee2..bd4241392a68 100644 --- a/browser/ui/webui/brave_rewards_page_ui.cc +++ b/browser/ui/webui/brave_rewards_page_ui.cc @@ -150,7 +150,7 @@ class RewardsDOMHandler : public WebUIMessageHandler, void OnGetOneTimeTips( std::unique_ptr list); - void SetInlineTipSetting(const base::ListValue* args); + void SetInlineTippingPlatformEnabled(const base::ListValue* args); void GetPendingContributions(const base::ListValue* args); void OnGetPendingContributions( @@ -425,8 +425,9 @@ void RewardsDOMHandler::RegisterMessages() { web_ui()->RegisterMessageCallback("brave_rewards.getRewardsMainEnabled", base::BindRepeating(&RewardsDOMHandler::GetRewardsMainEnabled, base::Unretained(this))); - web_ui()->RegisterMessageCallback("brave_rewards.setInlineTipSetting", - base::BindRepeating(&RewardsDOMHandler::SetInlineTipSetting, + web_ui()->RegisterMessageCallback( + "brave_rewards.setInlineTippingPlatformEnabled", + base::BindRepeating(&RewardsDOMHandler::SetInlineTippingPlatformEnabled, base::Unretained(this))); web_ui()->RegisterMessageCallback("brave_rewards.getPendingContributions", base::BindRepeating(&RewardsDOMHandler::GetPendingContributions, @@ -1451,7 +1452,8 @@ void RewardsDOMHandler::OnRecurringTipRemoved( "brave_rewards.recurringTipRemoved", base::Value(success)); } -void RewardsDOMHandler::SetInlineTipSetting(const base::ListValue* args) { +void RewardsDOMHandler::SetInlineTippingPlatformEnabled( + const base::ListValue* args) { std::string key; args->GetString(0, &key); @@ -1459,7 +1461,7 @@ void RewardsDOMHandler::SetInlineTipSetting(const base::ListValue* args) { args->GetString(1, &value); if (rewards_service_) { - rewards_service_->SetInlineTipSetting(key, value == "true"); + rewards_service_->SetInlineTippingPlatformEnabled(key, value == "true"); } } diff --git a/common/extensions/api/brave_rewards.json b/common/extensions/api/brave_rewards.json index e3a9558593aa..670e9156b156 100644 --- a/common/extensions/api/brave_rewards.json +++ b/common/extensions/api/brave_rewards.json @@ -944,7 +944,7 @@ ] }, { - "name": "getInlineTipSetting", + "name": "getInlineTippingPlatformEnabled", "type": "function", "description": "Gets setting for inline tip for provided key", "parameters": [ diff --git a/components/brave_ads/browser/ads_service_impl_unittest.cc b/components/brave_ads/browser/ads_service_impl_unittest.cc index 94c4ad69b97f..1cabc64303ea 100644 --- a/components/brave_ads/browser/ads_service_impl_unittest.cc +++ b/components/brave_ads/browser/ads_service_impl_unittest.cc @@ -153,11 +153,11 @@ class MockRewardsService : public RewardsService { void(const std::string&, const std::map&, brave_rewards::SaveMediaInfoCallback)); - MOCK_METHOD2(SetInlineTipSetting, + MOCK_METHOD2(SetInlineTippingPlatformEnabled, void(const std::string& key, bool enabled)); - MOCK_METHOD2(GetInlineTipSetting, + MOCK_METHOD2(GetInlineTippingPlatformEnabled, void(const std::string& key, - brave_rewards::GetInlineTipSettingCallback callback)); + brave_rewards::GetInlineTippingPlatformEnabledCallback)); MOCK_METHOD3(GetShareURL, void(const std::string& type, const std::map& args, diff --git a/components/brave_rewards/browser/rewards_service.cc b/components/brave_rewards/browser/rewards_service.cc index f678bb12bb6f..810f8ccc6ac7 100644 --- a/components/brave_rewards/browser/rewards_service.cc +++ b/components/brave_rewards/browser/rewards_service.cc @@ -80,6 +80,9 @@ void RewardsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { registry->RegisterStringPref(prefs::kStateAnonymousCardId, ""); registry->RegisterStringPref(prefs::kStateRecoverySeed, ""); registry->RegisterStringPref(prefs::kStatePaymentId, ""); + registry->RegisterBooleanPref(prefs::kStateInlineTipRedditEnabled, false); + registry->RegisterBooleanPref(prefs::kStateInlineTipTwitterEnabled, false); + registry->RegisterBooleanPref(prefs::kStateInlineTipGithubEnabled, false); } } // namespace brave_rewards diff --git a/components/brave_rewards/browser/rewards_service.h b/components/brave_rewards/browser/rewards_service.h index 48ebcfbcace7..bd3876be8cbe 100644 --- a/components/brave_rewards/browser/rewards_service.h +++ b/components/brave_rewards/browser/rewards_service.h @@ -81,7 +81,7 @@ using RefreshPublisherCallback = base::OnceCallback; using SaveMediaInfoCallback = base::OnceCallback)>; -using GetInlineTipSettingCallback = base::OnceCallback; +using GetInlineTippingPlatformEnabledCallback = base::OnceCallback; using GetShareURLCallback = base::OnceCallback; using GetPendingContributionsCallback = base::OnceCallback)>; @@ -282,11 +282,13 @@ class RewardsService : public KeyedService { const std::map& args, SaveMediaInfoCallback callback) = 0; - virtual void SetInlineTipSetting(const std::string& key, bool enabled) = 0; + virtual void SetInlineTippingPlatformEnabled( + const std::string& key, + bool enabled) = 0; - virtual void GetInlineTipSetting( + virtual void GetInlineTippingPlatformEnabled( const std::string& key, - GetInlineTipSettingCallback callback) = 0; + GetInlineTippingPlatformEnabledCallback callback) = 0; virtual void GetShareURL( const std::string& type, diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index d773bf7b3e20..7cc766605463 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -270,6 +270,22 @@ net::NetworkTrafficAnnotationTag GetNetworkTrafficAnnotationTagForURLLoad() { })"); } +ledger::InlineTipsPlatforms ConvertInlineTipStringToPlatform( + const std::string& key) { + if (key == "reddit") { + return ledger::InlineTipsPlatforms::REDDIT; + } + if (key == "twitter") { + return ledger::InlineTipsPlatforms::TWITTER; + } + if (key == "github") { + return ledger::InlineTipsPlatforms::GITHUB; + } + + NOTREACHED(); + return ledger::InlineTipsPlatforms::TWITTER; +} + const char pref_prefix[] = "brave.rewards."; } // namespace @@ -2542,23 +2558,26 @@ RewardsServiceImpl::GetAllNotifications() { return notification_service_->GetAllNotifications(); } -void RewardsServiceImpl::SetInlineTipSetting(const std::string& key, - bool enabled) { - bat_ledger_->SetInlineTipSetting(key, enabled); +void RewardsServiceImpl::SetInlineTippingPlatformEnabled( + const std::string& key, + bool enabled) { + const auto platform = ConvertInlineTipStringToPlatform(key); + bat_ledger_->SetInlineTippingPlatformEnabled(platform, enabled); } -void RewardsServiceImpl::GetInlineTipSetting( +void RewardsServiceImpl::GetInlineTippingPlatformEnabled( const std::string& key, - GetInlineTipSettingCallback callback) { - bat_ledger_->GetInlineTipSetting( - key, + GetInlineTippingPlatformEnabledCallback callback) { + const auto platform = ConvertInlineTipStringToPlatform(key); + bat_ledger_->GetInlineTippingPlatformEnabled( + platform, base::BindOnce(&RewardsServiceImpl::OnInlineTipSetting, AsWeakPtr(), std::move(callback))); } void RewardsServiceImpl::OnInlineTipSetting( - GetInlineTipSettingCallback callback, + GetInlineTippingPlatformEnabledCallback callback, bool enabled) { std::move(callback).Run(enabled); } diff --git a/components/brave_rewards/browser/rewards_service_impl.h b/components/brave_rewards/browser/rewards_service_impl.h index fb651c7c8e53..38f6daba0295 100644 --- a/components/brave_rewards/browser/rewards_service_impl.h +++ b/components/brave_rewards/browser/rewards_service_impl.h @@ -240,11 +240,13 @@ class RewardsServiceImpl : public RewardsService, const std::map& args, SaveMediaInfoCallback callback) override; - void SetInlineTipSetting(const std::string& key, bool enabled) override; + void SetInlineTippingPlatformEnabled( + const std::string& key, + bool enabled) override; - void GetInlineTipSetting( + void GetInlineTippingPlatformEnabled( const std::string& key, - GetInlineTipSettingCallback callback) override; + GetInlineTippingPlatformEnabledCallback callback) override; void GetShareURL( const std::string& type, @@ -378,7 +380,9 @@ class RewardsServiceImpl : public RewardsService, GetRecurringTipsCallback callback, ledger::PublisherInfoList list); - void OnInlineTipSetting(GetInlineTipSettingCallback callback, bool enabled); + void OnInlineTipSetting( + GetInlineTippingPlatformEnabledCallback callback, + bool enabled); void OnShareURL(GetShareURLCallback callback, const std::string& url); diff --git a/components/brave_rewards/browser/rewards_state_browsertest.cc b/components/brave_rewards/browser/rewards_state_browsertest.cc index ef29b0b4a822..fb532f3d4911 100644 --- a/components/brave_rewards/browser/rewards_state_browsertest.cc +++ b/components/brave_rewards/browser/rewards_state_browsertest.cc @@ -238,4 +238,13 @@ IN_PROC_BROWSER_TEST_F(RewardsStateBrowserTest, State_2) { EXPECT_EQ( profile_->GetPrefs()->GetBoolean("brave.rewards.ac.enabled"), true); + EXPECT_EQ( + profile_->GetPrefs()->GetBoolean("brave.rewards.inline_tip.reddit"), + true); + EXPECT_EQ( + profile_->GetPrefs()->GetBoolean("brave.rewards.inline_tip.twitter"), + false); + EXPECT_EQ( + profile_->GetPrefs()->GetBoolean("brave.rewards.inline_tip.github"), + false); } diff --git a/components/brave_rewards/common/pref_names.cc b/components/brave_rewards/common/pref_names.cc index d510956d4a64..5488b7c06198 100644 --- a/components/brave_rewards/common/pref_names.cc +++ b/components/brave_rewards/common/pref_names.cc @@ -50,5 +50,8 @@ const char kStateCreationStamp[] = "brave.rewards.creation_stamp"; const char kStateAnonymousCardId[] = "brave.rewards.wallet.anonymous_card_id"; const char kStateRecoverySeed[] = "brave.rewards.wallet.seed"; const char kStatePaymentId[] = "brave.rewards.wallet.payment_id"; +const char kStateInlineTipRedditEnabled[] = "brave.rewards.inline_tip.reddit"; +const char kStateInlineTipTwitterEnabled[] = "brave.rewards.inline_tip.twitter"; +const char kStateInlineTipGithubEnabled[] = "brave.rewards.inline_tip.github"; } // namespace prefs } // namespace brave_rewards diff --git a/components/brave_rewards/common/pref_names.h b/components/brave_rewards/common/pref_names.h index 86d1205f08ba..74591b91c455 100644 --- a/components/brave_rewards/common/pref_names.h +++ b/components/brave_rewards/common/pref_names.h @@ -42,6 +42,9 @@ extern const char kStateCreationStamp[]; extern const char kStateAnonymousCardId[]; extern const char kStateRecoverySeed[]; extern const char kStatePaymentId[]; +extern const char kStateInlineTipRedditEnabled[]; +extern const char kStateInlineTipTwitterEnabled[]; +extern const char kStateInlineTipGithubEnabled[]; extern const char kUseRewardsStagingServer[]; } // namespace prefs diff --git a/components/brave_rewards/resources/android_page/reducers/rewards_reducer.ts b/components/brave_rewards/resources/android_page/reducers/rewards_reducer.ts index 65df904334eb..1b81458c2ab1 100644 --- a/components/brave_rewards/resources/android_page/reducers/rewards_reducer.ts +++ b/components/brave_rewards/resources/android_page/reducers/rewards_reducer.ts @@ -180,7 +180,7 @@ const rewardsReducer: Reducer = (state: Rewards.State let inlineTip = state.inlineTip inlineTip[key] = value - chrome.send('brave_rewards.setInlineTipSetting', [key, value.toString()]) + chrome.send('brave_rewards.setInlineTippingPlatformEnabled', [key, value.toString()]) state = { ...state, diff --git a/components/brave_rewards/resources/extension/brave_rewards/background.ts b/components/brave_rewards/resources/extension/brave_rewards/background.ts index 911bfa56baa2..244814864e68 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background.ts @@ -154,9 +154,9 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { // Must return true for asynchronous calls to sendResponse return true } - case 'inlineTipSetting': { + case 'inlineTippingPlatformEnabled': { // Check if inline tip is enabled - chrome.braveRewards.getInlineTipSetting(msg.key, function (enabled: boolean) { + chrome.braveRewards.getInlineTippingPlatformEnabled(msg.key, function (enabled: boolean) { sendResponse({ enabled }) }) // Must return true for asynchronous calls to sendResponse diff --git a/components/brave_rewards/resources/extension/brave_rewards/content_scripts/github.ts b/components/brave_rewards/resources/extension/brave_rewards/content_scripts/github.ts index 83afa7c6e576..c2ea0a0b8c95 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/content_scripts/github.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/content_scripts/github.ts @@ -367,7 +367,7 @@ const configureBraveTipAction = () => { clearTimeout(timeout) chrome.runtime.sendMessage('rewardsEnabled', function (rewards) { const msg = { - type: 'inlineTipSetting', + type: 'inlineTippingPlatformEnabled', key: 'github' } chrome.runtime.sendMessage(msg, function (inlineTip) { diff --git a/components/brave_rewards/resources/extension/brave_rewards/content_scripts/reddit.ts b/components/brave_rewards/resources/extension/brave_rewards/content_scripts/reddit.ts index e435fe0c66d8..e767111dba5f 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/content_scripts/reddit.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/content_scripts/reddit.ts @@ -419,7 +419,7 @@ const configureBraveTipAction = () => { clearTimeout(timeout) chrome.runtime.sendMessage('rewardsEnabled', function (rewards) { const msg = { - type: 'inlineTipSetting', + type: 'inlineTippingPlatformEnabled', key: 'reddit' } chrome.runtime.sendMessage(msg, function (inlineTip) { diff --git a/components/brave_rewards/resources/extension/brave_rewards/content_scripts/twitter.ts b/components/brave_rewards/resources/extension/brave_rewards/content_scripts/twitter.ts index 809ed85c9d7e..5855782f25be 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/content_scripts/twitter.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/content_scripts/twitter.ts @@ -262,7 +262,7 @@ const configureBraveTipAction = () => { clearTimeout(timeout) chrome.runtime.sendMessage('rewardsEnabled', function (rewards) { const msg = { - type: 'inlineTipSetting', + type: 'inlineTippingPlatformEnabled', key: 'twitter' } chrome.runtime.sendMessage(msg, function (inlineTip) { diff --git a/components/brave_rewards/resources/page/reducers/rewards_reducer.ts b/components/brave_rewards/resources/page/reducers/rewards_reducer.ts index ed3dedd40ba7..8da062be6b0a 100644 --- a/components/brave_rewards/resources/page/reducers/rewards_reducer.ts +++ b/components/brave_rewards/resources/page/reducers/rewards_reducer.ts @@ -252,7 +252,7 @@ const rewardsReducer: Reducer = (state: Rewards.State let inlineTip = state.inlineTip inlineTip[key] = value - chrome.send('brave_rewards.setInlineTipSetting', [key, value.toString()]) + chrome.send('brave_rewards.setInlineTippingPlatformEnabled', [key, value.toString()]) state = { ...state, diff --git a/components/definitions/chromel.d.ts b/components/definitions/chromel.d.ts index 1c617e9dea7f..06424473b153 100644 --- a/components/definitions/chromel.d.ts +++ b/components/definitions/chromel.d.ts @@ -127,7 +127,7 @@ declare namespace chrome.braveRewards { } const refreshPublisher: (publisherKey: string, callback: (status: number, publisherKey: string) => void) => {} const getAllNotifications: (callback: (list: RewardsExtension.Notification[]) => void) => {} - const getInlineTipSetting: (key: string, callback: (enabled: boolean) => void) => {} + const getInlineTippingPlatformEnabled: (key: string, callback: (enabled: boolean) => void) => {} const fetchBalance: (callback: (balance: RewardsExtension.Balance) => void) => {} const onReconcileComplete: { addListener: (callback: (result: number, type: number) => void) => void diff --git a/components/services/bat_ledger/bat_ledger_impl.cc b/components/services/bat_ledger/bat_ledger_impl.cc index a1e97019ed63..21121f22e4be 100644 --- a/components/services/bat_ledger/bat_ledger_impl.cc +++ b/components/services/bat_ledger/bat_ledger_impl.cc @@ -677,14 +677,16 @@ void BatLedgerImpl::StartMonthlyContribution() { ledger_->StartMonthlyContribution(); } -void BatLedgerImpl::SetInlineTipSetting(const std::string& key, bool enabled) { - ledger_->SetInlineTipSetting(key, enabled); +void BatLedgerImpl::SetInlineTippingPlatformEnabled( + const ledger::InlineTipsPlatforms platform, + bool enabled) { + ledger_->SetInlineTippingPlatformEnabled(platform, enabled); } -void BatLedgerImpl::GetInlineTipSetting( - const std::string& key, - GetInlineTipSettingCallback callback) { - std::move(callback).Run(ledger_->GetInlineTipSetting(key)); +void BatLedgerImpl::GetInlineTippingPlatformEnabled( + const ledger::InlineTipsPlatforms platform, + GetInlineTippingPlatformEnabledCallback callback) { + std::move(callback).Run(ledger_->GetInlineTippingPlatformEnabled(platform)); } void BatLedgerImpl::GetShareURL( diff --git a/components/services/bat_ledger/bat_ledger_impl.h b/components/services/bat_ledger/bat_ledger_impl.h index 98b650f0ce09..850606d61c1a 100644 --- a/components/services/bat_ledger/bat_ledger_impl.h +++ b/components/services/bat_ledger/bat_ledger_impl.h @@ -154,11 +154,13 @@ class BatLedgerImpl : public mojom::BatLedger, const base::flat_map& args, SaveMediaInfoCallback callback) override; - void SetInlineTipSetting(const std::string& key, bool enabled) override; + void SetInlineTippingPlatformEnabled( + const ledger::InlineTipsPlatforms platform, + bool enabled) override; - void GetInlineTipSetting( - const std::string& key, - GetInlineTipSettingCallback callback) override; + void GetInlineTippingPlatformEnabled( + const ledger::InlineTipsPlatforms platform, + GetInlineTippingPlatformEnabledCallback callback) override; void GetShareURL( const std::string& type, diff --git a/components/services/bat_ledger/public/interfaces/bat_ledger.mojom b/components/services/bat_ledger/public/interfaces/bat_ledger.mojom index cff4fa148921..5fa34ffad67e 100644 --- a/components/services/bat_ledger/public/interfaces/bat_ledger.mojom +++ b/components/services/bat_ledger/public/interfaces/bat_ledger.mojom @@ -117,9 +117,9 @@ interface BatLedger { SaveMediaInfo(string type, map args) => (ledger.mojom.Result result, ledger.mojom.PublisherInfo? publisher_info); - SetInlineTipSetting(string key, bool enabled); + SetInlineTippingPlatformEnabled(ledger.mojom.InlineTipsPlatforms platform, bool enabled); - GetInlineTipSetting(string key) => (bool enabled); + GetInlineTippingPlatformEnabled(ledger.mojom.InlineTipsPlatforms platform) => (bool enabled); GetShareURL(string type, map args) => (string url); diff --git a/test/data/rewards-data/state/ledger_state b/test/data/rewards-data/state/ledger_state index aee387bcba84..6fd66e719a6f 100644 --- a/test/data/rewards-data/state/ledger_state +++ b/test/data/rewards-data/state/ledger_state @@ -44,5 +44,9 @@ ] } }, - "inlineTip": {} + "inlineTip": { + "github": false, + "reddit": true, + "twitter": false + } } \ No newline at end of file diff --git a/vendor/bat-native-ledger/include/bat/ledger/ledger.h b/vendor/bat-native-ledger/include/bat/ledger/ledger.h index 8aa06d4d6c22..e0766349a16d 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/ledger.h +++ b/vendor/bat-native-ledger/include/bat/ledger/ledger.h @@ -288,9 +288,12 @@ class LEDGER_EXPORT Ledger { const std::map& data, ledger::PublisherInfoCallback callback) = 0; - virtual void SetInlineTipSetting(const std::string& key, bool enabled) = 0; + virtual void SetInlineTippingPlatformEnabled( + const ledger::InlineTipsPlatforms platform, + bool enabled) = 0; - virtual bool GetInlineTipSetting(const std::string& key) = 0; + virtual bool GetInlineTippingPlatformEnabled( + const ledger::InlineTipsPlatforms platform) = 0; virtual std::string GetShareURL( const std::string& type, diff --git a/vendor/bat-native-ledger/include/bat/ledger/mojom_structs.h b/vendor/bat-native-ledger/include/bat/ledger/mojom_structs.h index 6795860a7e52..9525331ca685 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/mojom_structs.h +++ b/vendor/bat-native-ledger/include/bat/ledger/mojom_structs.h @@ -83,6 +83,8 @@ using ExcludeFilter = mojom::ExcludeFilter; using ExternalWallet = mojom::ExternalWallet; using ExternalWalletPtr = mojom::ExternalWalletPtr; +using InlineTipsPlatforms = mojom::InlineTipsPlatforms; + using MediaEventInfo = mojom::MediaEventInfo; using MediaEventInfoPtr = mojom::MediaEventInfoPtr; diff --git a/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom b/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom index f31994eb36d2..23a6c7d0f1c6 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom +++ b/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom @@ -535,3 +535,10 @@ struct UrlResponse { map headers; }; +enum InlineTipsPlatforms { + NONE = 0, + REDDIT = 1, + TWITTER = 2, + GITHUB = 3 +}; + diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc index 9df75cd4c4d9..3621379e8493 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc @@ -1054,12 +1054,15 @@ void LedgerImpl::SaveMediaInfo(const std::string& type, bat_media_->SaveMediaInfo(type, data, callback); } -void LedgerImpl::SetInlineTipSetting(const std::string& key, bool enabled) { - legacy_bat_state_->SetInlineTipSetting(key, enabled); +void LedgerImpl::SetInlineTippingPlatformEnabled( + const ledger::InlineTipsPlatforms platform, + bool enabled) { + braveledger_state::SetInlineTippingPlatformEnabled(this, platform, enabled); } -bool LedgerImpl::GetInlineTipSetting(const std::string& key) { - return legacy_bat_state_->GetInlineTipSetting(key); +bool LedgerImpl::GetInlineTippingPlatformEnabled( + const ledger::InlineTipsPlatforms platform) { + return braveledger_state::GetInlineTippingPlatformEnabled(this, platform); } std::string LedgerImpl::GetShareURL( diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.h b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.h index 12a629d5c47b..9eb6ed024a64 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.h @@ -357,9 +357,12 @@ class LedgerImpl : public ledger::Ledger { const std::map& data, ledger::PublisherInfoCallback callback) override; - void SetInlineTipSetting(const std::string& key, bool enabled) override; + void SetInlineTippingPlatformEnabled( + const ledger::InlineTipsPlatforms platform, + bool enabled) override; - bool GetInlineTipSetting(const std::string& key) override; + bool GetInlineTippingPlatformEnabled( + const ledger::InlineTipsPlatforms platform) override; std::string GetShareURL( const std::string& type, diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl_mock.h b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl_mock.h index a1f45d8e5dbe..61cdf0f6b1d3 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl_mock.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl_mock.h @@ -302,9 +302,11 @@ class MockLedgerImpl : public LedgerImpl { const std::map&, ledger::PublisherInfoCallback)); - MOCK_METHOD2(SetInlineTipSetting, void(const std::string&, bool)); + MOCK_METHOD2(SetInlineTippingPlatformEnabled, + void(const ledger::InlineTipsPlatforms platform, bool)); - MOCK_METHOD1(GetInlineTipSetting, bool(const std::string&)); + MOCK_METHOD1(GetInlineTippingPlatformEnabled, + bool(const ledger::InlineTipsPlatforms platform)); MOCK_METHOD2(GetShareURL, std::string(const std::string&, diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/bat_state.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/bat_state.cc index 51f045bdf5a8..e7e47d161e74 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/bat_state.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/bat_state.cc @@ -125,10 +125,6 @@ uint64_t LegacyBatState::GetCreationStamp() const { return state_->boot_timestamp; } -void LegacyBatState::SetInlineTipSetting(const std::string& key, bool enabled) { - state_->inline_tips[key] = enabled; -} - bool LegacyBatState::GetInlineTipSetting(const std::string& key) const { if (state_->inline_tips.find(key) == state_->inline_tips.end()) { // not found, all tips are on by default diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/bat_state.h b/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/bat_state.h index c1f4e44e19cb..772e80b4e698 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/bat_state.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/legacy/bat_state.h @@ -51,8 +51,6 @@ class LegacyBatState { uint64_t GetCreationStamp() const; - void SetInlineTipSetting(const std::string& key, bool enabled); - bool GetInlineTipSetting(const std::string& key) const; private: diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_keys.h b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_keys.h index 52b771f8eb1f..bf0fb02922c2 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_keys.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_keys.h @@ -32,6 +32,9 @@ namespace ledger { const char kStateAnonymousCardId[] = "wallet.anonymous_card_id"; const char kStateRecoverySeed[] = "wallet.seed"; const char kStatePaymentId[] = "wallet.payment_id"; + const char kStateInlineTipRedditEnabled[] = "inline_tip.reddit"; + const char kStateInlineTipTwitterEnabled[] = "inline_tip.twitter"; + const char kStateInlineTipGithubEnabled[] = "inline_tip.github"; } // namespace ledger diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_migration_v2.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_migration_v2.cc index 7a9c87d88f0e..cd8a2f388b53 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_migration_v2.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_migration_v2.cc @@ -83,6 +83,18 @@ void StateMigrationV2::OnLoadState( ledger::kStatePaymentId, legacy_state_->GetPaymentId()); + ledger_->SetBooleanState( + ledger::kStateInlineTipRedditEnabled, + legacy_state_->GetInlineTipSetting("reddit")); + + ledger_->SetBooleanState( + ledger::kStateInlineTipTwitterEnabled, + legacy_state_->GetInlineTipSetting("twitter")); + + ledger_->SetBooleanState( + ledger::kStateInlineTipGithubEnabled, + legacy_state_->GetInlineTipSetting("github")); + callback(ledger::Result::LEDGER_OK); } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_util.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_util.cc index d0e54826f533..9cb36a1b7948 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_util.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_util.cc @@ -203,4 +203,38 @@ void SetPaymentId(bat_ledger::LedgerImpl* ledger, const std::string& id) { ledger->SetStringState(ledger::kStatePaymentId, id); } +std::string ConvertInlineTipPlatformToKey( + const ledger::InlineTipsPlatforms platform) { + switch (platform) { + case ledger::InlineTipsPlatforms::REDDIT: { + return ledger::kStateInlineTipRedditEnabled; + } + case ledger::InlineTipsPlatforms::TWITTER: { + return ledger::kStateInlineTipTwitterEnabled; + } + case ledger::InlineTipsPlatforms::GITHUB: { + return ledger::kStateInlineTipGithubEnabled; + } + case ledger::InlineTipsPlatforms::NONE: { + NOTREACHED(); + return ""; + } + } +} + +bool GetInlineTippingPlatformEnabled( + bat_ledger::LedgerImpl* ledger, + const ledger::InlineTipsPlatforms platform) { + DCHECK(ledger); + return ledger->GetBooleanState(ConvertInlineTipPlatformToKey(platform)); +} + +void SetInlineTippingPlatformEnabled( + bat_ledger::LedgerImpl* ledger, + const ledger::InlineTipsPlatforms platform, + const bool enabled) { + DCHECK(ledger); + ledger->SetBooleanState(ConvertInlineTipPlatformToKey(platform), enabled); +} + } // namespace braveledger_state diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_util.h b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_util.h index 1d40f827b1ce..e941ea6cddcb 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_util.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/state/state_util.h @@ -90,6 +90,18 @@ std::string GetPaymentId(bat_ledger::LedgerImpl* ledger); void SetPaymentId(bat_ledger::LedgerImpl* ledger, const std::string& id); +std::string ConvertInlineTipPlatformToString( + const ledger::InlineTipsPlatforms platform); + +bool GetInlineTippingPlatformEnabled( + bat_ledger::LedgerImpl* ledger, + const ledger::InlineTipsPlatforms platform); + +void SetInlineTippingPlatformEnabled( + bat_ledger::LedgerImpl* ledger, + const ledger::InlineTipsPlatforms platform, + const bool enabled); + } // namespace braveledger_state #endif // BRAVELEDGER_STATE_STATE_UTIL_H_ diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/create.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/create.cc index 2aebc9482aa8..bf4efdb81627 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/create.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/create.cc @@ -299,6 +299,18 @@ void Create::RegisterPersonaCallback( braveledger_state::SetAnonymousCardId(ledger_, card_id); ledger_->SetCreationStamp(braveledger_time_util::GetCurrentTimeStamp()); ledger_->ResetReconcileStamp(); + braveledger_state::SetInlineTippingPlatformEnabled( + ledger_, + ledger::InlineTipsPlatforms::REDDIT, + true); + braveledger_state::SetInlineTippingPlatformEnabled( + ledger_, + ledger::InlineTipsPlatforms::TWITTER, + true); + braveledger_state::SetInlineTippingPlatformEnabled( + ledger_, + ledger::InlineTipsPlatforms::GITHUB, + true); callback(ledger::Result::WALLET_CREATED); }