diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index 40a2af332aec..1a509a828e50 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -658,7 +658,7 @@ bool AdsServiceImpl::StartService() { bat_ads_service_.set_connection_error_handler( base::Bind(&AdsServiceImpl::MaybeStart, AsWeakPtr(), true)); - UpdateIsProductionFlag(); + SetEnvironment(); UpdateIsDebugFlag(); UpdateIsTestingFlag(); @@ -748,31 +748,32 @@ void AdsServiceImpl::OnEnsureBaseDirectoryExists( MaybeShowMyFirstAdNotification(); } -void AdsServiceImpl::UpdateIsProductionFlag() { - auto is_production = IsProduction(); - bat_ads_service_->SetProduction(is_production, base::NullCallback()); -} - -bool AdsServiceImpl::IsProduction() const { -#if defined(OS_ANDROID) +void AdsServiceImpl::SetEnvironment() { + ads::Environment environment; #if defined(OFFICIAL_BUILD) - return !GetBooleanPref(brave_rewards::prefs::kUseRewardsStagingServer); + environment = ads::Environment::PRODUCTION; #else - return false; + environment = ads::Environment::STAGING; #endif +#if defined(OS_ANDROID) + if (GetBooleanPref(brave_rewards::prefs::kUseRewardsStagingServer)) { + environment = ads::Environment::STAGING; + } #else - const auto& command_line = *base::CommandLine::ForCurrentProcess(); -#if defined(OFFICIAL_BUILD) - return !command_line.HasSwitch(switches::kStaging); -#else - return command_line.HasSwitch(switches::kProduction); + if (command_line.HasSwitch(switches::kProduction)) { + environment = ads::Environment::PRODUCTION; + } else if (command_line.HasSwitch(switches::kStaging)) { + environment = ads::Environment::STAGING; + } else if (command_line.HasSwitch(switches::kDevelopment)) { + environment = ads::Environment::DEVELOPMENT; + } #endif -#endif + bat_ads_service_->SetEnvironment(environment, base::NullCallback()); } void AdsServiceImpl::UpdateIsDebugFlag() { diff --git a/components/brave_ads/browser/ads_service_impl.h b/components/brave_ads/browser/ads_service_impl.h index 8a142aabe775..c4b4d5556d40 100644 --- a/components/brave_ads/browser/ads_service_impl.h +++ b/components/brave_ads/browser/ads_service_impl.h @@ -160,8 +160,8 @@ class AdsServiceImpl : public AdsService, void OnEnsureBaseDirectoryExists( const bool success); - void UpdateIsProductionFlag(); - bool IsProduction() const; + void SetEnvironment(); + void UpdateIsDebugFlag(); bool IsDebug() const; void UpdateIsTestingFlag(); diff --git a/components/brave_ads/common/switches.cc b/components/brave_ads/common/switches.cc index b27e1f59fcfe..4c66f1d02d82 100644 --- a/components/brave_ads/common/switches.cc +++ b/components/brave_ads/common/switches.cc @@ -6,10 +6,15 @@ #include "brave/components/brave_ads/common/switches.h" namespace brave_ads { + namespace switches { -const char kStaging[] = "brave-ads-staging"; + const char kProduction[] = "brave-ads-production"; +const char kStaging[] = "brave-ads-staging"; +const char kDevelopment[] = "brave-ads-development"; const char kDebug[] = "brave-ads-debug"; const char kTesting[] = "brave-ads-testing"; + } // namespace switches + } // namespace brave_ads diff --git a/components/brave_ads/common/switches.h b/components/brave_ads/common/switches.h index e7417151c422..837607bce246 100644 --- a/components/brave_ads/common/switches.h +++ b/components/brave_ads/common/switches.h @@ -10,8 +10,9 @@ namespace brave_ads { namespace switches { -extern const char kStaging[]; extern const char kProduction[]; +extern const char kStaging[]; +extern const char kDevelopment[]; extern const char kDebug[]; extern const char kTesting[]; diff --git a/components/brave_rewards/browser/rewards_service_browsertest.cc b/components/brave_rewards/browser/rewards_service_browsertest.cc index 13cd2729c363..a770d46f6125 100644 --- a/components/brave_rewards/browser/rewards_service_browsertest.cc +++ b/components/brave_rewards/browser/rewards_service_browsertest.cc @@ -451,9 +451,9 @@ class BraveRewardsBrowserTest : base::Unretained(this))); } - void GetProduction() { - rewards_service()->GetProduction( - base::Bind(&BraveRewardsBrowserTest::OnGetProduction, + void GetEnvironment() { + rewards_service()->GetEnvironment( + base::Bind(&BraveRewardsBrowserTest::OnGetEnvironment, base::Unretained(this))); } @@ -1232,7 +1232,7 @@ class BraveRewardsBrowserTest : const std::vector tip_amounts_ = {1.0, 5.0, 10.0}; - MOCK_METHOD1(OnGetProduction, void(bool)); + MOCK_METHOD1(OnGetEnvironment, void(ledger::Environment)); MOCK_METHOD1(OnGetDebug, void(bool)); MOCK_METHOD1(OnGetReconcileTime, void(int32_t)); MOCK_METHOD1(OnGetShortRetries, void(bool)); @@ -1430,39 +1430,40 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, ActivateSettingsModal) { IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) { testing::InSequence s; - // SetProduction(true) - EXPECT_CALL(*this, OnGetProduction(true)); + // SetEnvironment(ledger::Environment::PRODUCTION) + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::PRODUCTION)); // Staging - true and 1 - EXPECT_CALL(*this, OnGetProduction(false)).Times(2); + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::STAGING)).Times(2); // Staging - false and random - EXPECT_CALL(*this, OnGetProduction(true)).Times(2); + EXPECT_CALL(*this, OnGetEnvironment( + ledger::Environment::PRODUCTION)).Times(2); - rewards_service()->SetProduction(true); - GetProduction(); + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + GetEnvironment(); RunUntilIdle(); // Staging - true - rewards_service()->SetProduction(true); + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); rewards_service()->HandleFlags("staging=true"); - GetProduction(); + GetEnvironment(); RunUntilIdle(); // Staging - 1 - rewards_service()->SetProduction(true); + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); rewards_service()->HandleFlags("staging=1"); - GetProduction(); + GetEnvironment(); RunUntilIdle(); // Staging - false - rewards_service()->SetProduction(false); + rewards_service()->SetEnvironment(ledger::Environment::STAGING); rewards_service()->HandleFlags("staging=false"); - GetProduction(); + GetEnvironment(); RunUntilIdle(); // Staging - random - rewards_service()->SetProduction(false); + rewards_service()->SetEnvironment(ledger::Environment::STAGING); rewards_service()->HandleFlags("staging=werwe"); - GetProduction(); + GetEnvironment(); RunUntilIdle(); // SetDebug(true) @@ -1500,6 +1501,45 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) { GetDebug(); RunUntilIdle(); + // SetEnvironment(ledger::Environment::PRODUCTION) + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::PRODUCTION)); + // Development - true and 1 + EXPECT_CALL( + *this, + OnGetEnvironment(ledger::Environment::DEVELOPMENT)).Times(2); + // Development - false and random + EXPECT_CALL( + *this, + OnGetEnvironment(ledger::Environment::PRODUCTION)).Times(2); + + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + GetEnvironment(); + RunUntilIdle(); + + // Development - true + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + rewards_service()->HandleFlags("development=true"); + GetEnvironment(); + RunUntilIdle(); + + // Development - 1 + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + rewards_service()->HandleFlags("development=1"); + GetEnvironment(); + RunUntilIdle(); + + // Development - false + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + rewards_service()->HandleFlags("development=false"); + GetEnvironment(); + RunUntilIdle(); + + // Development - random + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); + rewards_service()->HandleFlags("development=werwe"); + GetEnvironment(); + RunUntilIdle(); + // positive number EXPECT_CALL(*this, OnGetReconcileTime(10)); // negative number and string @@ -1540,12 +1580,12 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsSingleArg) { } IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsMultipleFlags) { - EXPECT_CALL(*this, OnGetProduction(false)); + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::STAGING)); EXPECT_CALL(*this, OnGetDebug(true)); EXPECT_CALL(*this, OnGetReconcileTime(10)); EXPECT_CALL(*this, OnGetShortRetries(true)); - rewards_service()->SetProduction(true); + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); rewards_service()->SetDebug(true); rewards_service()->SetReconcileTime(0); rewards_service()->SetShortRetries(false); @@ -1555,18 +1595,18 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsMultipleFlags) { GetReconcileTime(); GetShortRetries(); - GetProduction(); + GetEnvironment(); GetDebug(); RunUntilIdle(); } IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsWrongInput) { - EXPECT_CALL(*this, OnGetProduction(true)); + EXPECT_CALL(*this, OnGetEnvironment(ledger::Environment::PRODUCTION)); EXPECT_CALL(*this, OnGetDebug(false)); EXPECT_CALL(*this, OnGetReconcileTime(0)); EXPECT_CALL(*this, OnGetShortRetries(false)); - rewards_service()->SetProduction(true); + rewards_service()->SetEnvironment(ledger::Environment::PRODUCTION); rewards_service()->SetDebug(false); rewards_service()->SetReconcileTime(0); rewards_service()->SetShortRetries(false); @@ -1577,7 +1617,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, HandleFlagsWrongInput) { GetReconcileTime(); GetShortRetries(); GetDebug(); - GetProduction(); + GetEnvironment(); RunUntilIdle(); } diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 5801ab8120f7..b3629a7fcb20 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -502,16 +502,14 @@ void RewardsServiceImpl::StartLedger() { bat_ledger_service_.set_connection_error_handler( base::Bind(&RewardsServiceImpl::ConnectionClosed, AsWeakPtr())); - bool is_production = true; + ledger::Environment environment = ledger::Environment::STAGING; // Environment #if defined(OFFICIAL_BUILD) && defined(OS_ANDROID) - is_production = !ShouldUseStagingServerForAndroid(); + environment = GetServerEnvironmentForAndroid(); #elif defined(OFFICIAL_BUILD) - is_production = true; - #else - is_production = false; + environment = ledger::Environment::PRODUCTION; #endif - SetProduction(is_production); + SetEnvironment(environment); SetDebug(false); @@ -2861,16 +2859,16 @@ void RewardsServiceImpl::HandleFlags(const std::string& options) { } if (name == "staging") { - bool is_production; + ledger::Environment environment; std::string lower = base::ToLowerASCII(value); if (lower == "true" || lower == "1") { - is_production = false; + environment = ledger::Environment::STAGING; } else { - is_production = true; + environment = ledger::Environment::PRODUCTION; } - SetProduction(is_production); + SetEnvironment(environment); continue; } @@ -2925,6 +2923,18 @@ void RewardsServiceImpl::HandleFlags(const std::string& options) { SaveExternalWallet(ledger::kWalletUphold, std::move(uphold)); continue; } + + if (name == "development") { + ledger::Environment environment; + std::string lower = base::ToLowerASCII(value); + + if (lower == "true" || lower == "1") { + environment = ledger::Environment::DEVELOPMENT; + SetEnvironment(environment); + } + + continue; + } } } @@ -2992,9 +3002,9 @@ void RewardsServiceImpl::SetLedgerEnvForTesting() { // this is needed because we are using braveledger_bat_helper::buildURL // directly in BraveRewardsBrowserTest #if defined(OFFICIAL_BUILD) - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; #else - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; #endif } @@ -3002,8 +3012,13 @@ void RewardsServiceImpl::StartMonthlyContributionForTest() { bat_ledger_->StartMonthlyContribution(); } -void RewardsServiceImpl::GetProduction(const GetProductionCallback& callback) { - bat_ledger_service_->GetProduction(callback); +void RewardsServiceImpl::CheckInsufficientFundsForTesting() { + MaybeShowNotificationAddFunds(); +} + +void RewardsServiceImpl::GetEnvironment( + const GetEnvironmentCallback& callback) { + bat_ledger_service_->GetEnvironment(callback); } void RewardsServiceImpl::GetDebug(const GetDebugCallback& callback) { @@ -3020,8 +3035,8 @@ void RewardsServiceImpl::GetShortRetries( bat_ledger_service_->GetShortRetries(callback); } -void RewardsServiceImpl::SetProduction(bool production) { - bat_ledger_service_->SetProduction(production); +void RewardsServiceImpl::SetEnvironment(ledger::Environment environment) { + bat_ledger_service_->SetEnvironment(environment); } void RewardsServiceImpl::SetDebug(bool debug) { @@ -4016,13 +4031,18 @@ void RewardsServiceImpl::GrantAttestationResult( #endif #if defined(OS_ANDROID) -bool RewardsServiceImpl::ShouldUseStagingServerForAndroid() { - bool use_staging = false; +ledger::Environment RewardsServiceImpl::GetServerEnvironmentForAndroid() { + auto result = ledger::Environment::PRODUCTION; if (profile_ && profile_->GetPrefs()) { - use_staging = profile_->GetPrefs()-> - GetBoolean(prefs::kUseRewardsStagingServer); + use_staging = + profile_->GetPrefs()->GetBoolean(prefs::kUseRewardsStagingServer); } - return use_staging; + + if (use_staging) { + result = ledger::Environment::STAGING; + } + + return result; } #endif diff --git a/components/brave_rewards/browser/rewards_service_impl.h b/components/brave_rewards/browser/rewards_service_impl.h index 91f3851e2cc2..65e2132b7a4d 100644 --- a/components/brave_rewards/browser/rewards_service_impl.h +++ b/components/brave_rewards/browser/rewards_service_impl.h @@ -71,7 +71,7 @@ class PublisherInfoDatabase; class RewardsNotificationServiceImpl; class BraveRewardsBrowserTest; -using GetProductionCallback = base::Callback; +using GetEnvironmentCallback = base::Callback; using GetDebugCallback = base::Callback; using GetReconcileTimeCallback = base::Callback; using GetShortRetriesCallback = base::Callback; @@ -194,8 +194,8 @@ class RewardsServiceImpl : public RewardsService, GetRewardsInternalsInfoCallback callback) override; void HandleFlags(const std::string& options); - void SetProduction(bool production); - void GetProduction(const GetProductionCallback& callback); + void SetEnvironment(ledger::Environment environment); + void GetEnvironment(const GetEnvironmentCallback& callback); void SetDebug(bool debug); void GetDebug(const GetDebugCallback& callback); void SetReconcileTime(int32_t time); @@ -297,6 +297,7 @@ class RewardsServiceImpl : public RewardsService, void StartMonthlyContributionForTest(); void MaybeShowNotificationAddFundsForTesting( base::OnceCallback callback); + void CheckInsufficientFundsForTesting(); private: friend class ::BraveRewardsBrowserTest; @@ -732,7 +733,7 @@ class RewardsServiceImpl : public RewardsService, ledger::ContributionQueuePtr info); #if defined(OS_ANDROID) - bool ShouldUseStagingServerForAndroid(); + bool GetServerEnvironmentForAndroid(); void CreateWalletAttestationResult( bat_ledger::mojom::BatLedger::CreateWalletCallback callback, bool result, const std::string& result_string); diff --git a/components/services/bat_ads/bat_ads_service_impl.cc b/components/services/bat_ads/bat_ads_service_impl.cc index 1ecacdb97beb..43f7b7ce3875 100644 --- a/components/services/bat_ads/bat_ads_service_impl.cc +++ b/components/services/bat_ads/bat_ads_service_impl.cc @@ -31,11 +31,11 @@ void BatAdsServiceImpl::Create( std::move(callback).Run(); } -void BatAdsServiceImpl::SetProduction( - const bool is_production, - SetProductionCallback callback) { - DCHECK(!is_initialized_ || ads::_is_production == is_production); - ads::_is_production = is_production; +void BatAdsServiceImpl::SetEnvironment( + const ads::Environment environment, + SetEnvironmentCallback callback) { + DCHECK(!is_initialized_|| ads::_environment == environment); + ads::_environment = environment; std::move(callback).Run(); } diff --git a/components/services/bat_ads/bat_ads_service_impl.h b/components/services/bat_ads/bat_ads_service_impl.h index cc5d115e6f1a..94148d70df3a 100644 --- a/components/services/bat_ads/bat_ads_service_impl.h +++ b/components/services/bat_ads/bat_ads_service_impl.h @@ -13,6 +13,7 @@ #include "brave/components/services/bat_ads/public/interfaces/bat_ads.mojom.h" #include "mojo/public/cpp/bindings/binding_set.h" #include "services/service_manager/public/cpp/service_context_ref.h" +#include "bat/ads/ads.h" namespace bat_ads { @@ -29,9 +30,9 @@ class BatAdsServiceImpl : public mojom::BatAdsService { mojom::BatAdsAssociatedRequest bat_ads, CreateCallback callback) override; - void SetProduction( - const bool is_production, - SetProductionCallback callback) override; + void SetEnvironment( + const ads::Environment environment, + SetEnvironmentCallback callback) override; void SetTesting( const bool is_testing, diff --git a/components/services/bat_ads/public/interfaces/BUILD.gn b/components/services/bat_ads/public/interfaces/BUILD.gn index 3aa0e4c6711e..5adf92fcb6d6 100644 --- a/components/services/bat_ads/public/interfaces/BUILD.gn +++ b/components/services/bat_ads/public/interfaces/BUILD.gn @@ -10,4 +10,8 @@ mojom("interfaces") { public_deps = [ "//mojo/public/mojom/base", ] + + deps = [ + "//brave/vendor/bat-native-ads/include/bat/ads/public/interfaces" + ] } diff --git a/components/services/bat_ads/public/interfaces/bat_ads.mojom b/components/services/bat_ads/public/interfaces/bat_ads.mojom index e8d7312c6f58..dfc68fd48a5b 100644 --- a/components/services/bat_ads/public/interfaces/bat_ads.mojom +++ b/components/services/bat_ads/public/interfaces/bat_ads.mojom @@ -2,15 +2,16 @@ // 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/. - module bat_ads.mojom; +import "brave/vendor/bat-native-ads/include/bat/ads/public/interfaces/ads.mojom"; + const string kServiceName = "bat_ads"; // Service which hands out bat ads. interface BatAdsService { Create(associated BatAdsClient bat_ads_client, associated BatAds& database) => (); - SetProduction(bool is_production) => (); + SetEnvironment(ads.mojom.Environment environment) => (); SetTesting(bool is_testing) => (); SetDebug(bool is_debug) => (); }; diff --git a/components/services/bat_ledger/bat_ledger_service_impl.cc b/components/services/bat_ledger/bat_ledger_service_impl.cc index 8222031b0829..88c2f2265989 100644 --- a/components/services/bat_ledger/bat_ledger_service_impl.cc +++ b/components/services/bat_ledger/bat_ledger_service_impl.cc @@ -7,7 +7,6 @@ #include -#include "bat/ledger/ledger.h" #include "brave/components/services/bat_ledger/bat_ledger_impl.h" #include "mojo/public/cpp/bindings/strong_associated_binding.h" @@ -39,9 +38,9 @@ void BatLedgerServiceImpl::Create( initialized_ = true; } -void BatLedgerServiceImpl::SetProduction(bool is_production) { +void BatLedgerServiceImpl::SetEnvironment(ledger::Environment environment) { DCHECK(!initialized_ || testing()); - ledger::is_production = is_production; + ledger::_environment = environment; } void BatLedgerServiceImpl::SetDebug(bool is_debug) { @@ -63,8 +62,8 @@ void BatLedgerServiceImpl::SetTesting() { ledger::is_testing = true; } -void BatLedgerServiceImpl::GetProduction(GetProductionCallback callback) { - std::move(callback).Run(ledger::is_production); +void BatLedgerServiceImpl::GetEnvironment(GetEnvironmentCallback callback) { + std::move(callback).Run(ledger::_environment); } void BatLedgerServiceImpl::GetDebug(GetDebugCallback callback) { diff --git a/components/services/bat_ledger/bat_ledger_service_impl.h b/components/services/bat_ledger/bat_ledger_service_impl.h index ef5a263d579f..f60f7457ab75 100644 --- a/components/services/bat_ledger/bat_ledger_service_impl.h +++ b/components/services/bat_ledger/bat_ledger_service_impl.h @@ -8,6 +8,7 @@ #include +#include "bat/ledger/ledger.h" #include "brave/components/services/bat_ledger/public/interfaces/bat_ledger.mojom.h" #include "services/service_manager/public/cpp/service_context_ref.h" @@ -23,13 +24,13 @@ class BatLedgerServiceImpl : public mojom::BatLedgerService { void Create(mojom::BatLedgerClientAssociatedPtrInfo client_info, mojom::BatLedgerAssociatedRequest bat_ledger) override; - void SetProduction(bool isProduction) override; + void SetEnvironment(ledger::Environment environment) override; void SetDebug(bool isDebug) override; void SetReconcileTime(int32_t time) override; void SetShortRetries(bool short_retries) override; void SetTesting() override; - void GetProduction(GetProductionCallback callback) override; + void GetEnvironment(GetEnvironmentCallback callback) override; void GetDebug(GetDebugCallback callback) override; void GetReconcileTime(GetReconcileTimeCallback callback) override; void GetShortRetries(GetShortRetriesCallback callback) override; diff --git a/components/services/bat_ledger/public/interfaces/bat_ledger.mojom b/components/services/bat_ledger/public/interfaces/bat_ledger.mojom index 8f7598a33163..acc0132f298b 100644 --- a/components/services/bat_ledger/public/interfaces/bat_ledger.mojom +++ b/components/services/bat_ledger/public/interfaces/bat_ledger.mojom @@ -10,13 +10,13 @@ const string kServiceName = "bat_ledger"; interface BatLedgerService { Create(associated BatLedgerClient bat_ledger_client, associated BatLedger& bat_ledger); - SetProduction(bool isProduction); + SetEnvironment(ledger.mojom.Environment environment); SetDebug(bool isDebug); SetReconcileTime(int32 time); SetShortRetries(bool short_retries); SetTesting(); - GetProduction() => (bool production); + GetEnvironment() => (ledger.mojom.Environment environment); GetDebug() => (bool debug); GetReconcileTime() => (int32 time); GetShortRetries() => (bool short_retries); diff --git a/vendor/bat-native-ads/BUILD.gn b/vendor/bat-native-ads/BUILD.gn index b7f6dc11af06..093fbe35ae6a 100644 --- a/vendor/bat-native-ads/BUILD.gn +++ b/vendor/bat-native-ads/BUILD.gn @@ -12,7 +12,10 @@ config("external_config") { visibility = [ ":*", ] - include_dirs = [ "include" ] + include_dirs = [ + "include", + "$target_gen_dir/include", + ] } config("internal_config") { @@ -50,19 +53,13 @@ static_library("bat-native-ads-standalone") { ] } -source_set("ads") { - public_configs = [ ":external_config" ] - configs += [ ":internal_config" ] - +source_set("headers") { visibility = [ ":*", - # add this only when ledger and confirmations are in the same process - # rebase_path("bat-native-ledger", dep_base), - # rebase_path("bat-native-ads", dep_base), "//brave/test:*", ] - output_name = "bat_native_ads" + public_configs = [ ":external_config" ] sources = [ "include/bat/ads/ad_content.h", @@ -82,6 +79,19 @@ source_set("ads") { "include/bat/ads/notification_event_type.h", "include/bat/ads/notification_info.h", "include/bat/ads/result.h", + ] + + public_deps = [ + "include/bat/ads/public/interfaces" + ] +} + +source_set("ads") { + configs += [ ":internal_config" ] + + output_name = "bat_native_ads" + + sources = [ "src/bat/ads/ad_content.cc", "src/bat/ads/ad_history_detail.cc", "src/bat/ads/ad_info.cc", @@ -162,7 +172,7 @@ source_set("ads") { "src/bat/ads/internal/uri_helper.cc", "src/bat/ads/internal/uri_helper.h", ] - + deps = [ "//base", "//url", @@ -170,4 +180,8 @@ source_set("ads") { rebase_path("bat-native-rapidjson", dep_base), rebase_path("brave_base", dep_base), ] + + public_deps = [ + ":headers", + ] } diff --git a/vendor/bat-native-ads/README.md b/vendor/bat-native-ads/README.md index ce8c298531f7..4768aa947d46 100644 --- a/vendor/bat-native-ads/README.md +++ b/vendor/bat-native-ads/README.md @@ -19,6 +19,12 @@ Default for non official builds, i.e. Debug --brave-ads-staging ``` +Use development Ads Serve as defined by `DEVELOPMENT_SERVER` in `static_values.h`. + +``` +--brave-ads-development +``` + Collect initial activity after 25 seconds instead of 1 hour as defined by `kDebugOneHourInSeconds` in `static_values.h`. Download the catalog after 15 minutes instead of 2 hours as defined by `kDebugCatalogPing` in diff --git a/vendor/bat-native-ads/include/bat/ads/ads.h b/vendor/bat-native-ads/include/bat/ads/ads.h index 36bd4bb8ef8b..abe53dcbf5f3 100644 --- a/vendor/bat-native-ads/include/bat/ads/ads.h +++ b/vendor/bat-native-ads/include/bat/ads/ads.h @@ -18,19 +18,21 @@ #include "bat/ads/export.h" #include "bat/ads/notification_event_type.h" #include "bat/ads/notification_info.h" +#include "bat/ads/public/interfaces/ads.mojom.h" namespace ads { struct AdsHistory; +using Environment = mojom::Environment; + using InitializeCallback = std::function; using ShutdownCallback = std::function; using RemoveAllHistoryCallback = std::function; -// |_is_production| indicates that URL requests should use production servers if -// set to |true| or staging servers if set to |false| but can be overridden via -// command-line arguments -extern bool _is_production; +// |_environment| indicates that URL requests should use production, staging or +// development servers but can be overridden via command-line arguments +extern Environment _environment; // |_is_debug| indicates that the next catalogue download should be reduced from // ~1 hour to ~25 seconds. This value should be set to |false| on production diff --git a/vendor/bat-native-ads/include/bat/ads/public/interfaces/BUILD.gn b/vendor/bat-native-ads/include/bat/ads/public/interfaces/BUILD.gn new file mode 100644 index 000000000000..fe366dfee718 --- /dev/null +++ b/vendor/bat-native-ads/include/bat/ads/public/interfaces/BUILD.gn @@ -0,0 +1,11 @@ +import("//mojo/public/tools/bindings/mojom.gni") + +mojom("interfaces") { + sources = [ + "ads.mojom", + ] + + public_deps = [ + "//mojo/public/mojom/base", + ] +} diff --git a/vendor/bat-native-ads/include/bat/ads/public/interfaces/ads.mojom b/vendor/bat-native-ads/include/bat/ads/public/interfaces/ads.mojom new file mode 100644 index 000000000000..332ab349f047 --- /dev/null +++ b/vendor/bat-native-ads/include/bat/ads/public/interfaces/ads.mojom @@ -0,0 +1,11 @@ +// Copyright (c) 2019 The Brave Authors. All rights reserved. +// 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/. +module ads.mojom; + +enum Environment { + STAGING = 0, + PRODUCTION = 1, + DEVELOPMENT = 2 +}; diff --git a/vendor/bat-native-ads/src/bat/ads/ads.cc b/vendor/bat-native-ads/src/bat/ads/ads.cc index f34b4d101456..dfd11145d12f 100644 --- a/vendor/bat-native-ads/src/bat/ads/ads.cc +++ b/vendor/bat-native-ads/src/bat/ads/ads.cc @@ -13,7 +13,7 @@ namespace ads { bool _is_debug = false; bool _is_testing = false; -bool _is_production = false; +Environment _environment = Environment::DEVELOPMENT; const char _bundle_schema_resource_name[] = "bundle-schema.json"; const char _catalog_schema_resource_name[] = "catalog-schema.json"; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads_serve.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads_serve.cc index 39d50b5091e2..b7e603aa43ee 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads_serve.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads_serve.cc @@ -33,10 +33,21 @@ AdsServe::AdsServe(AdsImpl* ads, AdsClient* ads_client, Bundle* bundle) : AdsServe::~AdsServe() = default; void AdsServe::BuildUrl() { - if (_is_production) { - url_ = PRODUCTION_SERVER; - } else { - url_ = STAGING_SERVER; + switch (_environment) { + case Environment::PRODUCTION: { + url_ = PRODUCTION_SERVER; + break; + } + + case Environment::STAGING: { + url_ = STAGING_SERVER; + break; + } + + case Environment::DEVELOPMENT: { + url_ = DEVELOPMENT_SERVER; + break; + } } url_ += CATALOG_PATH; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/static_values.h b/vendor/bat-native-ads/src/bat/ads/internal/static_values.h index 5c39e1a0421c..aa1fb943fcff 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/static_values.h +++ b/vendor/bat-native-ads/src/bat/ads/internal/static_values.h @@ -14,8 +14,9 @@ namespace ads { -#define STAGING_SERVER "https://ads-serve.bravesoftware.com" #define PRODUCTION_SERVER "https://ads-serve.brave.com" +#define STAGING_SERVER "https://ads-serve.bravesoftware.com" +#define DEVELOPMENT_SERVER "https://ads-serve.brave.software.com" #define CATALOG_PATH "/v1/catalog" diff --git a/vendor/bat-native-confirmations/README.md b/vendor/bat-native-confirmations/README.md index 67ffb402748e..3ab795499dc8 100644 --- a/vendor/bat-native-confirmations/README.md +++ b/vendor/bat-native-confirmations/README.md @@ -21,6 +21,12 @@ Default for non offical builds, i.e. Debug --rewards=staging=true ``` +Use development Ads Server as defined by `DEVELOPMENT_SERVER` in `static_values.h`. + +``` +--rewards=development=true +``` + Use shorter timers to help with testing token redemption as defined by `kDebugNextTokenRedemptionAfterSeconds` in `static_values.h`. diff --git a/vendor/bat-native-confirmations/include/bat/confirmations/confirmations.h b/vendor/bat-native-confirmations/include/bat/confirmations/confirmations.h index 33d0a128e60b..5e10507cef7e 100644 --- a/vendor/bat-native-confirmations/include/bat/confirmations/confirmations.h +++ b/vendor/bat-native-confirmations/include/bat/confirmations/confirmations.h @@ -26,10 +26,9 @@ using TransactionsInfo = ::ledger::TransactionsInfo; using OnGetTransactionHistory = ::ledger::GetTransactionHistoryCallback; -// |_is_production| indicates that URL requests should use production servers if -// set to |true| or staging servers if set to |false| but can be overridden via -// command-line arguments -extern bool _is_production; +// |_environment| indicates that URL requests should use production, staging or +// development servers but can be overridden via command-line arguments +extern ledger::Environment _environment; // |_is_debug| indicates that the next token redemption date should be reduced // from ~7 days to ~25 minutes. This value should be set to |false| on diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/confirmations.cc b/vendor/bat-native-confirmations/src/bat/confirmations/confirmations.cc index 50b6bf3dfef5..bc2089d795b4 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/confirmations.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/confirmations.cc @@ -9,7 +9,7 @@ namespace confirmations { -bool _is_production = false; +ledger::Environment _environment = ledger::Environment::STAGING; bool _is_debug = false; const char _confirmations_resource_name[] = "confirmations.json"; diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/ads_serve_helper.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/ads_serve_helper.cc index 429e78ad46d8..b729c7245dda 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/ads_serve_helper.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/ads_serve_helper.cc @@ -11,10 +11,18 @@ namespace helper { std::string AdsServe::GetURL() { - if (confirmations::_is_production) { - return BAT_ADS_PRODUCTION_SERVER; - } else { - return BAT_ADS_STAGING_SERVER; + switch (confirmations::_environment) { + case ledger::Environment::PRODUCTION: { + return BAT_ADS_PRODUCTION_SERVER; + } + + case ledger::Environment::STAGING: { + return BAT_ADS_STAGING_SERVER; + } + + case ledger::Environment::DEVELOPMENT: { + return BAT_ADS_DEVELOPMENT_SERVER; + } } } diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/ledger_serve_helper.cc b/vendor/bat-native-confirmations/src/bat/confirmations/internal/ledger_serve_helper.cc index 1dc65f37cd04..d55bb4b08ff7 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/ledger_serve_helper.cc +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/ledger_serve_helper.cc @@ -11,10 +11,18 @@ namespace helper { std::string LedgerServe::GetURL() { - if (confirmations::_is_production) { - return BAT_LEDGER_PRODUCTION_SERVER; - } else { - return BAT_LEDGER_STAGING_SERVER; + switch (confirmations::_environment) { + case ledger::Environment::PRODUCTION: { + return BAT_LEDGER_PRODUCTION_SERVER; + } + + case ledger::Environment::STAGING: { + return BAT_LEDGER_STAGING_SERVER; + } + + case ledger::Environment::DEVELOPMENT: { + return BAT_LEDGER_DEVELOPMENT_SERVER; + } } } diff --git a/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h b/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h index 53a237ad66e8..819ad75058bf 100644 --- a/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h +++ b/vendor/bat-native-confirmations/src/bat/confirmations/internal/static_values.h @@ -12,11 +12,13 @@ namespace confirmations { -#define BAT_ADS_STAGING_SERVER "https://ads-serve.bravesoftware.com" #define BAT_ADS_PRODUCTION_SERVER "https://ads-serve.brave.com" +#define BAT_ADS_STAGING_SERVER "https://ads-serve.bravesoftware.com" +#define BAT_ADS_DEVELOPMENT_SERVER "https://ads-serve.brave.software.com" -#define BAT_LEDGER_STAGING_SERVER "https://ledger-staging.mercury.basicattentiontoken.org" // NOLINT #define BAT_LEDGER_PRODUCTION_SERVER "https://ledger.mercury.basicattentiontoken.org" // NOLINT +#define BAT_LEDGER_STAGING_SERVER "https://ledger-staging.mercury.basicattentiontoken.org" // NOLINT +#define BAT_LEDGER_DEVELOPMENT_SERVER "https://ledger.rewards.brave.software.org" // NOLINT static const int kNextPaymentDay = 5; diff --git a/vendor/bat-native-ledger/include/bat/ledger/ledger.h b/vendor/bat-native-ledger/include/bat/ledger/ledger.h index 2d4faf478cbb..efb4ef0bd452 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/ledger.h +++ b/vendor/bat-native-ledger/include/bat/ledger/ledger.h @@ -20,7 +20,7 @@ namespace ledger { -extern bool is_production; +extern Environment _environment; extern bool is_debug; extern bool is_testing; extern int reconcile_time; // minutes 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 5a67c2353bbd..3040dfcf3162 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/mojom_structs.h +++ b/vendor/bat-native-ledger/include/bat/ledger/mojom_structs.h @@ -46,6 +46,8 @@ using ContributionQueuePublisherList = using ContributionRetry = mojom::ContributionRetry; +using Environment = ledger::mojom::Environment; + using ExcludeFilter = mojom::ExcludeFilter; using ExternalWallet = mojom::ExternalWallet; 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 95df9efcb89f..1bdc2a5350b4 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 @@ -312,4 +312,10 @@ struct ContributionQueue { struct ContributionQueuePublisher { string publisher_key; double amount_percent; -}; \ No newline at end of file +}; + +enum Environment { + STAGING = 0, + PRODUCTION = 1, + DEVELOPMENT = 2 +}; diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc index 5e58947f449a..5d12dc6f1cb5 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc @@ -2218,31 +2218,55 @@ std::string buildURL(const std::string& path, std::string url; switch (server) { case SERVER_TYPES::BALANCE: - if (ledger::is_production) { - url = BALANCE_PRODUCTION_SERVER; - } else { - url = BALANCE_STAGING_SERVER; + switch (ledger::_environment) { + case ledger::Environment::STAGING: + url = BALANCE_STAGING_SERVER; + break; + case ledger::Environment::PRODUCTION: + url = BALANCE_PRODUCTION_SERVER; + break; + case ledger::Environment::DEVELOPMENT: + url = BALANCE_DEVELOPMENT_SERVER; + break; } break; case SERVER_TYPES::PUBLISHER: - if (ledger::is_production) { - url = PUBLISHER_PRODUCTION_SERVER; - } else { - url = PUBLISHER_STAGING_SERVER; + switch (ledger::_environment) { + case ledger::Environment::STAGING: + url = PUBLISHER_STAGING_SERVER; + break; + case ledger::Environment::PRODUCTION: + url = PUBLISHER_PRODUCTION_SERVER; + break; + case ledger::Environment::DEVELOPMENT: + url = PUBLISHER_DEVELOPMENT_SERVER; + break; } break; case SERVER_TYPES::PUBLISHER_DISTRO: - if (ledger::is_production) { - url = PUBLISHER_DISTRO_PRODUCTION_SERVER; - } else { - url = PUBLISHER_DISTRO_STAGING_SERVER; + switch (ledger::_environment) { + case ledger::Environment::STAGING: + url = PUBLISHER_DISTRO_STAGING_SERVER; + break; + case ledger::Environment::PRODUCTION: + url = PUBLISHER_DISTRO_PRODUCTION_SERVER; + break; + case ledger::Environment::DEVELOPMENT: + url = PUBLISHER_DISTRO_DEVELOPMENT_SERVER; + break; } break; - default: - if (ledger::is_production) { - url = LEDGER_PRODUCTION_SERVER; - } else { - url = LEDGER_STAGING_SERVER; + case SERVER_TYPES::LEDGER: + switch (ledger::_environment) { + case ledger::Environment::STAGING: + url = LEDGER_STAGING_SERVER; + break; + case ledger::Environment::PRODUCTION: + url = LEDGER_PRODUCTION_SERVER; + break; + case ledger::Environment::DEVELOPMENT: + url = LEDGER_DEVELOPMENT_SERVER; + break; } break; } 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 7f78d5f53fc5..7240742fdf82 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 @@ -322,7 +322,7 @@ void LedgerImpl::OnLedgerStateLoaded( void LedgerImpl::SetConfirmationsWalletInfo( const braveledger_bat_helper::WALLET_INFO_ST& wallet_info) { if (!bat_confirmations_) { - confirmations::_is_production = ledger::is_production; + confirmations::_environment = ledger::_environment; confirmations::_is_debug = ledger::is_debug; bat_confirmations_.reset( diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/static_values.h b/vendor/bat-native-ledger/src/bat/ledger/internal/static_values.h index ef9a14922e84..359b06ca7bd0 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/static_values.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/static_values.h @@ -14,18 +14,29 @@ "https://ledger-staging.mercury.basicattentiontoken.org" #define LEDGER_PRODUCTION_SERVER \ "https://ledger.mercury.basicattentiontoken.org" +#define LEDGER_DEVELOPMENT_SERVER \ +"https://ledger.rewards.brave.software" + #define BALANCE_STAGING_SERVER \ "https://balance-staging.mercury.basicattentiontoken.org" #define BALANCE_PRODUCTION_SERVER \ "https://balance.mercury.basicattentiontoken.org" +#define BALANCE_DEVELOPMENT_SERVER \ +"https://balance.rewards.brave.software" + #define PUBLISHER_STAGING_SERVER \ "https://publishers-staging.basicattentiontoken.org" #define PUBLISHER_PRODUCTION_SERVER \ "https://publishers.basicattentiontoken.org" +#define PUBLISHER_DEVELOPMENT_SERVER \ +"https://creators.brave.software" + #define PUBLISHER_DISTRO_STAGING_SERVER \ "https://publishers-staging-distro.basicattentiontoken.org" #define PUBLISHER_DISTRO_PRODUCTION_SERVER \ "https://publishers-distro.basicattentiontoken.org" +#define PUBLISHER_DISTRO_DEVELOPMENT_SERVER \ +"https://creators-distro.brave.software" #define PREFIX_V1 "/v1" #define PREFIX_V2 "/v2" diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc index a5b4c277aa6a..cd5f4fbf4ba8 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util.cc @@ -16,26 +16,26 @@ namespace braveledger_uphold { std::string GetClientId() { - return ledger::is_production + return ledger::_environment == ledger::Environment::PRODUCTION ? kClientIdProduction : kClientIdStaging; } std::string GetClientSecret() { - return ledger::is_production + return ledger::_environment == ledger::Environment::PRODUCTION ? kClientSecretProduction : kClientSecretStaging; } std::string GetUrl() { - return ledger::is_production + return ledger::_environment == ledger::Environment::PRODUCTION ? kUrlProduction : kUrlStaging; } std::string GetAPIUrl(const std::string& path) { std::string url; - if (ledger::is_production) { + if (ledger::_environment == ledger::Environment::PRODUCTION) { url = kAPIUrlProduction; } else { url = kAPIUrlStaging; @@ -45,7 +45,7 @@ std::string GetAPIUrl(const std::string& path) { } std::string GetFeeAddress() { - return ledger::is_production + return ledger::_environment == ledger::Environment::PRODUCTION ? kFeeAddressProduction : kFeeAddressStaging; } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util_unittest.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util_unittest.cc index 6aa2e6b39a72..9b9034c6db78 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util_unittest.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util_unittest.cc @@ -20,53 +20,53 @@ class UpholdUtilTest : public testing::Test { TEST(UpholdUtilTest, GetClientId) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetClientId(); ASSERT_EQ(result, kClientIdProduction); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetClientId(); ASSERT_EQ(result, kClientIdStaging); } TEST(UpholdUtilTest, GetClientSecret) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetClientSecret(); ASSERT_EQ(result, kClientSecretProduction); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetClientSecret(); ASSERT_EQ(result, kClientSecretStaging); } TEST(UpholdUtilTest, GetAPIUrl) { // empty path, production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetAPIUrl(""); ASSERT_EQ(result, kAPIUrlProduction); // empty path, staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetAPIUrl(""); ASSERT_EQ(result, kAPIUrlStaging); // with path - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetAPIUrl("/v0/testing"); ASSERT_EQ(result, static_cast(kAPIUrlStaging) + "/v0/testing"); } TEST(UpholdUtilTest, GetFeeAddress) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetFeeAddress(); ASSERT_EQ(result, kFeeAddressProduction); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetFeeAddress(); ASSERT_EQ(result, kFeeAddressStaging); } @@ -95,7 +95,7 @@ TEST(UpholdUtilTest, ConvertToProbi) { TEST(UpholdUtilTest, GetVerifyUrl) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetVerifyUrl("rdfdsfsdfsdf"); ASSERT_EQ(result, "https://uphold.com/authorize/" @@ -104,7 +104,7 @@ TEST(UpholdUtilTest, GetVerifyUrl) { "transactions:transfer:others&intention=kyc&state=rdfdsfsdfsdf"); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetVerifyUrl("rdfdsfsdfsdf"); ASSERT_EQ(result, "https://sandbox.uphold.com/authorize/" @@ -119,12 +119,12 @@ TEST(UpholdUtilTest, GetAddUrl) { ASSERT_EQ(result, ""); // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; result = braveledger_uphold::GetAddUrl("9324i5i32459i"); ASSERT_EQ(result, "https://uphold.com/dashboard/cards/9324i5i32459i/add"); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetAddUrl("9324i5i32459i"); ASSERT_EQ(result, "https://sandbox.uphold.com/dashboard/cards/9324i5i32459i/add"); @@ -136,12 +136,12 @@ TEST(UpholdUtilTest, GetWithdrawUrl) { ASSERT_EQ(result, ""); // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; result = braveledger_uphold::GetWithdrawUrl("9324i5i32459i"); ASSERT_EQ(result, "https://uphold.com/dashboard/cards/9324i5i32459i/use"); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetWithdrawUrl("9324i5i32459i"); ASSERT_EQ(result, "https://sandbox.uphold.com/dashboard/cards/9324i5i32459i/use"); @@ -149,14 +149,14 @@ TEST(UpholdUtilTest, GetWithdrawUrl) { TEST(UpholdUtilTest, GetSecondStepVerify) { // production - ledger::is_production = true; + ledger::_environment = ledger::Environment::PRODUCTION; std::string result = braveledger_uphold::GetSecondStepVerify(); ASSERT_EQ(result, "https://uphold.com/signup/step2?" "application_id=6d8d9473ed20be627f71ed46e207f40c004c5b1a&intention=kyc"); // staging - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GetSecondStepVerify(); ASSERT_EQ(result, "https://sandbox.uphold.com/signup/step2?" @@ -193,7 +193,7 @@ TEST(UpholdUtilTest, RequestAuthorization) { // token is not defined - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::RequestAuthorization(); ASSERT_EQ(result.at(0), "Authorization: Basic NGMyYjY2NWNhMDYwZDkxMmZlYzVjNzM1YzczNDg1OWEwNjEx" @@ -206,13 +206,13 @@ TEST(UpholdUtilTest, GenerateRandomString) { ASSERT_EQ(result, "123456789"); // random string - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; result = braveledger_uphold::GenerateRandomString(false); ASSERT_EQ(result.length(), 64u); } TEST(UpholdUtilTest, GenerateLinks) { - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; auto wallet = ledger::ExternalWallet::New(); wallet->address = "123123123124234234234"; @@ -295,7 +295,7 @@ TEST(UpholdUtilTest, GenerateLinks) { } TEST(UpholdUtilTest, GenerateVerifyLink) { - ledger::is_production = false; + ledger::_environment = ledger::Environment::STAGING; auto wallet = ledger::ExternalWallet::New(); wallet->one_time_string = "123123123124234234234"; diff --git a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc index 40a231732f4f..ab5a2c5e96ee 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc @@ -13,7 +13,8 @@ namespace ledger { -bool is_production = true; +Environment _environment = Environment::PRODUCTION; + bool is_debug = false; bool is_testing = false; int reconcile_time = 0; // minutes diff --git a/vendor/brave-ios/Ads/BATBraveAds.h b/vendor/brave-ios/Ads/BATBraveAds.h index 9b8fa1bd167e..cae8f772acdc 100644 --- a/vendor/brave-ios/Ads/BATBraveAds.h +++ b/vendor/brave-ios/Ads/BATBraveAds.h @@ -50,8 +50,9 @@ NS_SWIFT_NAME(BraveAds) /// Whether or not to use staging servers. Defaults to false @property (nonatomic, class, getter=isDebug) BOOL debug; -/// Whether or not to use production servers. Defaults to true -@property (nonatomic, class, getter=isProduction) BOOL production; +/// The environment that ads is communicating with. See ledger's BATEnvironment +/// for appropriate values. +@property (nonatomic, class) int environment; /// Marks if this is being ran in a test environment. Defaults to false @property (nonatomic, class, getter=isTesting) BOOL testing; diff --git a/vendor/brave-ios/Ads/BATBraveAds.mm b/vendor/brave-ios/Ads/BATBraveAds.mm index c23a47b9c954..82afd129f3b3 100644 --- a/vendor/brave-ios/Ads/BATBraveAds.mm +++ b/vendor/brave-ios/Ads/BATBraveAds.mm @@ -104,7 +104,16 @@ + (BOOL)isCurrentRegionSupported BATClassAdsBridge(BOOL, isDebug, setDebug, _is_debug) BATClassAdsBridge(BOOL, isTesting, setTesting, _is_testing) -BATClassAdsBridge(BOOL, isProduction, setProduction, _is_production) + ++ (int)environment +{ + return static_cast(ads::_environment); +} + ++ (void)setEnvironment:(int)environment +{ + ads::_environment = static_cast(environment); +} #pragma mark - Configuration diff --git a/vendor/brave-ios/BATBraveRewards.h b/vendor/brave-ios/BATBraveRewards.h index 3021465459f6..0fcb90de251e 100644 --- a/vendor/brave-ios/BATBraveRewards.h +++ b/vendor/brave-ios/BATBraveRewards.h @@ -15,8 +15,9 @@ NS_SWIFT_NAME(BraveRewardsConfiguration) /// Whether or not rewards is being tested @property (nonatomic, getter=isTesting) BOOL testing; -/// Whether or not rewards is in production -@property (nonatomic, getter=isProduction) BOOL production; +//@property (nonatomic, getter=isDebug) BOOL debug; +/// The rewards environment +@property (nonatomic) BATEnvironment environment; /// Where ledger and ads should save their state @property (nonatomic, copy) NSString *stateStoragePath; /// The number of seconds between overrides. Defaults to 0 (no override) which means reconciles @@ -25,16 +26,20 @@ NS_SWIFT_NAME(BraveRewardsConfiguration) /// Whether or not to enable short retries between contribution attempts @property (nonatomic) BOOL useShortRetries; -/// The default configuration. Channel is debug, no changes to ledger configuration +/// The default configuration. Environment is dev, no changes to ledger configuration /// /// State is stored in Application Support @property (nonatomic, class, readonly) BATBraveRewardsConfiguration *defaultConfiguration NS_SWIFT_NAME(default); -/// The production configuration. Channel is production, no changes to ledger configuration +/// The staging configuration. Environment is staging, no changes to ledger configuration +/// +/// State is stored in Application Support +@property (nonatomic, class, readonly) BATBraveRewardsConfiguration *stagingConfiguration NS_SWIFT_NAME(staging); +/// The production configuration. Environment is production, no changes to ledger configuration /// /// State is stored in Application Support @property (nonatomic, class, readonly) BATBraveRewardsConfiguration *productionConfiguration NS_SWIFT_NAME(production); -/// The testing configuration. Channel is debug & testing. Short retries are enabled, number of -/// seconds between reconciles is set to 30 seconds instead of 30 days. +/// The testing configuration. Environment is development & is_testing is set to true. Short retries are enabled, +/// number of seconds between reconciles is set to 30 seconds instead of 30 days. /// /// State is saved to a directory created in /tmp @property (nonatomic, class, readonly) BATBraveRewardsConfiguration *testingConfiguration NS_SWIFT_NAME(testing); diff --git a/vendor/brave-ios/BATBraveRewards.m b/vendor/brave-ios/BATBraveRewards.m index 79ba4f9205e9..ee8aee9dcfbe 100644 --- a/vendor/brave-ios/BATBraveRewards.m +++ b/vendor/brave-ios/BATBraveRewards.m @@ -10,14 +10,22 @@ @implementation BATBraveRewardsConfiguration + (BATBraveRewardsConfiguration *)defaultConfiguration { __auto_type config = [[BATBraveRewardsConfiguration alloc] init]; + config.environment = BATEnvironmentDevelopment; config.stateStoragePath = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES).firstObject; return config; } ++ (BATBraveRewardsConfiguration *)stagingConfiguration +{ + __auto_type config = [self defaultConfiguration]; + config.environment = BATEnvironmentStaging; + return config; +} + + (BATBraveRewardsConfiguration *)productionConfiguration { __auto_type config = [self defaultConfiguration]; - config.production = YES; + config.environment = BATEnvironmentProduction; return config; } @@ -35,7 +43,7 @@ - (id)copyWithZone:(NSZone *)zone { __auto_type config = [[BATBraveRewardsConfiguration alloc] init]; config.stateStoragePath = self.stateStoragePath; - config.production = self.production; + config.environment = self.environment; config.testing = self.testing; config.useShortRetries = self.useShortRetries; config.overridenNumberOfSecondsBetweenReconcile = self.overridenNumberOfSecondsBetweenReconcile; @@ -80,12 +88,12 @@ - (instancetype)initWithConfiguration:(BATBraveRewardsConfiguration *)configurat self.ledgerClass = ledgerClass ?: BATBraveLedger.class; self.adsClass = adsClass ?: BATBraveAds.class; - BATBraveAds.debug = !configuration.production; - BATBraveAds.production = configuration.production; + BATBraveAds.debug = configuration.environment != BATEnvironmentProduction; + BATBraveAds.environment = configuration.environment; BATBraveAds.testing = configuration.testing; - BATBraveLedger.debug = !configuration.production; - BATBraveLedger.production = configuration.production; + BATBraveLedger.debug = configuration.environment != BATEnvironmentProduction; + BATBraveLedger.environment = configuration.environment; BATBraveLedger.testing = configuration.testing; BATBraveLedger.useShortRetries = configuration.useShortRetries; BATBraveLedger.reconcileTime = configuration.overridenNumberOfSecondsBetweenReconcile; diff --git a/vendor/brave-ios/Ledger/BATBraveLedger.h b/vendor/brave-ios/Ledger/BATBraveLedger.h index 133393a8420e..b2c81daf9406 100644 --- a/vendor/brave-ios/Ledger/BATBraveLedger.h +++ b/vendor/brave-ios/Ledger/BATBraveLedger.h @@ -45,8 +45,8 @@ NS_SWIFT_NAME(BraveLedger) /// Whether or not to use staging servers. Defaults to false @property (nonatomic, class, getter=isDebug) BOOL debug; -/// Whether or not to use production servers. Defaults to true -@property (nonatomic, class, getter=isProduction) BOOL production; +/// The environment that ledger is communicating with +@property (nonatomic, class) BATEnvironment environment; /// Marks if this is being ran in a test environment. Defaults to false @property (nonatomic, class, getter=isTesting) BOOL testing; /// Number of minutes between reconciles override. Defaults to 0 (no override) diff --git a/vendor/brave-ios/Ledger/BATBraveLedger.mm b/vendor/brave-ios/Ledger/BATBraveLedger.mm index d00fddbfcefd..a50d737ddd1a 100644 --- a/vendor/brave-ios/Ledger/BATBraveLedger.mm +++ b/vendor/brave-ios/Ledger/BATBraveLedger.mm @@ -193,10 +193,19 @@ - (void)removeObserver:(BATBraveLedgerObserver *)observer BATClassLedgerBridge(BOOL, isDebug, setDebug, is_debug) BATClassLedgerBridge(BOOL, isTesting, setTesting, is_testing) -BATClassLedgerBridge(BOOL, isProduction, setProduction, is_production) BATClassLedgerBridge(int, reconcileTime, setReconcileTime, reconcile_time) BATClassLedgerBridge(BOOL, useShortRetries, setUseShortRetries, short_retries) ++ (BATEnvironment)environment +{ + return static_cast(ledger::_environment); +} + ++ (void)setEnvironment:(BATEnvironment)environment +{ + ledger::_environment = static_cast(environment); +} + #pragma mark - Wallet BATLedgerReadonlyBridge(BOOL, isWalletCreated, IsWalletCreated)