diff --git a/browser/ui/webui/brave_rewards_ui.cc b/browser/ui/webui/brave_rewards_ui.cc index f11c9658daae..23894b3157a3 100644 --- a/browser/ui/webui/brave_rewards_ui.cc +++ b/browser/ui/webui/brave_rewards_ui.cc @@ -108,8 +108,10 @@ class RewardsDOMHandler : public WebUIMessageHandler, void GetConfirmationsHistory(const base::ListValue* args); void GetRewardsMainEnabled(const base::ListValue* args); void OnGetRewardsMainEnabled(bool enabled); + void OnGetAdsIsSupportedRegion(bool is_supported); void GetExcludedPublishersNumber(const base::ListValue* args); + void GetAdsIsSupportedRegion(const base::ListValue* args); void OnConfirmationsHistory(int total_viewed, double estimated_earnings); @@ -283,6 +285,9 @@ void RewardsDOMHandler::RegisterMessages() { web_ui()->RegisterMessageCallback("brave_rewards.getExcludedPublishersNumber", base::BindRepeating(&RewardsDOMHandler::GetExcludedPublishersNumber, base::Unretained(this))); + web_ui()->RegisterMessageCallback("brave_rewards.getAdsIsSupportedRegion", + base::BindRepeating(&RewardsDOMHandler::GetAdsIsSupportedRegion, + base::Unretained(this))); } void RewardsDOMHandler::Init() { @@ -1020,6 +1025,21 @@ void RewardsDOMHandler::GetExcludedPublishersNumber( } } +void RewardsDOMHandler::GetAdsIsSupportedRegion( + const base::ListValue* args) { + ads_service_->IsSupportedRegion(base::Bind( + &RewardsDOMHandler::OnGetAdsIsSupportedRegion, + weak_factory_.GetWeakPtr())); +} + +void RewardsDOMHandler::OnGetAdsIsSupportedRegion( + bool is_supported) { + if (web_ui()->CanCallJavascript()) { + web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.adsIsSupportedRegion", + base::Value(is_supported)); + } +} + } // namespace BraveRewardsUI::BraveRewardsUI(content::WebUI* web_ui, const std::string& name) diff --git a/browser/ui/webui/brave_webui_source.cc b/browser/ui/webui/brave_webui_source.cc index 37a9d4f14306..b5548b9c0f31 100644 --- a/browser/ui/webui/brave_webui_source.cc +++ b/browser/ui/webui/brave_webui_source.cc @@ -195,6 +195,7 @@ void CustomizeWebUIHTMLSource(const std::string &name, { "adsDisabledTextOne", IDS_BRAVE_REWARDS_LOCAL_ADS_DISABLED_TEXT_ONE }, // NOLINT { "adsDisabledTextTwo", IDS_BRAVE_REWARDS_LOCAL_ADS_DISABLED_TEXT_TWO }, // NOLINT { "adsNotificationsReceived", IDS_BRAVE_REWARDS_LOCAL_ADS_NOTIFICATIONS_RECEIVED }, // NOLINT + { "adsNotSupported", IDS_BRAVE_REWARDS_LOCAL_ADS_NOT_SUPPORTED }, { "adsPaymentDate", IDS_BRAVE_REWARDS_LOCAL_ADS_PAYMENT_DATE }, { "adsPagesViewed", IDS_BRAVE_REWARDS_LOCAL_ADS_PAGES_VIEWED }, { "adsPerHour", IDS_BRAVE_REWARDS_LOCAL_ADS_PER_HOUR }, diff --git a/components/brave_ads/browser/ads_service.h b/components/brave_ads/browser/ads_service.h index 5d0c464c688d..5dafe50e8728 100644 --- a/components/brave_ads/browser/ads_service.h +++ b/components/brave_ads/browser/ads_service.h @@ -16,6 +16,8 @@ namespace brave_ads { +using IsSupportedRegionCallback = base::Callback; + class AdsService : public KeyedService { public: AdsService() = default; @@ -37,6 +39,8 @@ class AdsService : public KeyedService { virtual void ClassifyPage(const std::string& url, const std::string& page) = 0; virtual void SetConfirmationsIsReady(const bool is_ready) = 0; + virtual void IsSupportedRegion( + const IsSupportedRegionCallback& callback) = 0; private: DISALLOW_COPY_AND_ASSIGN(AdsService); diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index adae14350ab5..b4750f55bcd9 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -998,4 +998,12 @@ bool AdsServiceImpl::connected() { return bat_ads_.is_bound(); } +void AdsServiceImpl::IsSupportedRegion( + const IsSupportedRegionCallback& callback) { + if (!connected()) + return; + + bat_ads_->IsSupportedRegion(callback); +} + } // namespace brave_ads diff --git a/components/brave_ads/browser/ads_service_impl.h b/components/brave_ads/browser/ads_service_impl.h index f7ee977e8fd4..e73515a7ef74 100644 --- a/components/brave_ads/browser/ads_service_impl.h +++ b/components/brave_ads/browser/ads_service_impl.h @@ -71,6 +71,8 @@ class AdsServiceImpl : public AdsService, void OnMediaStop(SessionID tab_id) override; void ClassifyPage(const std::string& url, const std::string& page) override; void SetConfirmationsIsReady(const bool is_ready) override; + void IsSupportedRegion( + const IsSupportedRegionCallback& callback) override; void Shutdown() override; diff --git a/components/brave_rewards/resources/ui/actions/rewards_actions.ts b/components/brave_rewards/resources/ui/actions/rewards_actions.ts index 8f50bb258f5f..28e6dc60bf9b 100644 --- a/components/brave_rewards/resources/ui/actions/rewards_actions.ts +++ b/components/brave_rewards/resources/ui/actions/rewards_actions.ts @@ -185,3 +185,9 @@ export const getConfirmationsHistory = () => action(types.GET_CONFIRMATIONS_HIST export const onConfirmationsHistoryChanged = () => action(types.ON_CONFIRMATIONS_HISTORY_CHANGED) export const getExcludedPublishersNumber = () => action(types.GET_EXCLUDED_PUBLISHERS_NUMBER) + +export const getAdsIsSupportedRegion = () => action(types.GET_ADS_IS_SUPPORTED_REGION) + +export const onAdsIsSupportedRegion = (supported: boolean) => action(types.ON_ADS_IS_SUPPORTED_REGION, { + supported +}) diff --git a/components/brave_rewards/resources/ui/brave_rewards.tsx b/components/brave_rewards/resources/ui/brave_rewards.tsx index a28ed35d95d9..ef9a96eda186 100644 --- a/components/brave_rewards/resources/ui/brave_rewards.tsx +++ b/components/brave_rewards/resources/ui/brave_rewards.tsx @@ -155,6 +155,10 @@ window.cr.define('brave_rewards', function () { getActions().onConfirmationsHistoryChanged() } + function adsIsSupportedRegion (supported: boolean) { + getActions().onAdsIsSupportedRegion(supported) + } + return { initialize, walletCreated, @@ -182,7 +186,8 @@ window.cr.define('brave_rewards', function () { rewardsEnabled, addressesForPaymentId, confirmationsHistory, - confirmationsHistoryChanged + confirmationsHistoryChanged, + adsIsSupportedRegion } }) diff --git a/components/brave_rewards/resources/ui/components/adsBox.tsx b/components/brave_rewards/resources/ui/components/adsBox.tsx index 9ca5ae2ccd51..c5ce413130a4 100644 --- a/components/brave_rewards/resources/ui/components/adsBox.tsx +++ b/components/brave_rewards/resources/ui/components/adsBox.tsx @@ -9,6 +9,7 @@ import { connect } from 'react-redux' // Components import { Box, + BoxAlert, DisabledContent, List, NextContribution, @@ -56,6 +57,16 @@ class AdsBox extends React.Component { ) } + adsNotSupportedAlert = (supported: boolean) => { + if (supported) { + return null + } + + return ( + + ) + } + onAdsSettingChange = (key: string, value: string) => { let newValue: any = value const { adsEnabled } = this.props.rewardsData.adsData @@ -106,6 +117,7 @@ class AdsBox extends React.Component { let adsUIEnabled = false let notificationsReceived = 0 let estimatedEarnings = '0' + let adsIsSupported = true const { adsData, @@ -119,10 +131,12 @@ class AdsBox extends React.Component { adsUIEnabled = adsData.adsUIEnabled notificationsReceived = adsData.adsNotificationsReceived || 0 estimatedEarnings = (adsData.adsEstimatedEarnings || 0).toFixed(2) + adsIsSupported = adsData.adsIsSupported } - const toggle = !(!enabledMain || !adsUIEnabled) - const showDisabled = firstLoad !== false || !toggle || !adsEnabled + const enabled = adsEnabled && adsIsSupported + const toggle = !(!enabledMain || !adsUIEnabled || !adsIsSupported) + const showDisabled = firstLoad !== false || !toggle || !adsEnabled || !adsIsSupported return ( { type={'ads'} description={getLocale('adsDesc')} toggle={toggle} - checked={adsEnabled} - settingsChild={this.adsSettings(adsEnabled && enabledMain)} + checked={enabled} + settingsChild={this.adsSettings(enabled && enabledMain)} testId={'braveAdsSettings'} disabledContent={showDisabled ? this.adsDisabled() : null} onToggle={this.onAdsSettingChange.bind(this, 'adsEnabled', '')} settingsOpened={this.state.settings} onSettingsClick={this.onSettingsToggle} + attachedAlert={this.adsNotSupportedAlert(adsIsSupported)} > { importAlert = (walletImported: boolean) => { return ( walletImported - ? + ? : null ) } diff --git a/components/brave_rewards/resources/ui/components/settingsPage.tsx b/components/brave_rewards/resources/ui/components/settingsPage.tsx index 566a90b94ff6..b369b86f23d1 100644 --- a/components/brave_rewards/resources/ui/components/settingsPage.tsx +++ b/components/brave_rewards/resources/ui/components/settingsPage.tsx @@ -41,6 +41,7 @@ class SettingsPage extends React.Component { this.actions.getConfirmationsHistory() this.actions.getExcludedPublishersNumber() this.actions.getAdsData() + this.actions.getAdsIsSupportedRegion() } componentDidMount () { diff --git a/components/brave_rewards/resources/ui/constants/rewards_types.ts b/components/brave_rewards/resources/ui/constants/rewards_types.ts index 622874ef61aa..89d2b4b8d096 100644 --- a/components/brave_rewards/resources/ui/constants/rewards_types.ts +++ b/components/brave_rewards/resources/ui/constants/rewards_types.ts @@ -57,5 +57,7 @@ export const enum types { GET_CONFIRMATIONS_HISTORY = '@@rewards/GET_CONFIRMATIONS_HISTORY', ON_CONFIRMATIONS_HISTORY = '@@rewards/ON_CONFIRMATIONS_HISTORY', ON_CONFIRMATIONS_HISTORY_CHANGED = '@@rewards/ON_CONFIRMATIONS_HISTORY_CHANGED', - GET_EXCLUDED_PUBLISHERS_NUMBER = '@@rewards/GET_EXCLUDED_PUBLISHERS_NUMBER' + GET_EXCLUDED_PUBLISHERS_NUMBER = '@@rewards/GET_EXCLUDED_PUBLISHERS_NUMBER', + GET_ADS_IS_SUPPORTED_REGION = '@@rewards/GET_ADS_IS_SUPPORTED_REGION', + ON_ADS_IS_SUPPORTED_REGION = '@@rewards/ON_ADS_IS_SUPPORTED_REGION' } diff --git a/components/brave_rewards/resources/ui/reducers/rewards_reducer.ts b/components/brave_rewards/resources/ui/reducers/rewards_reducer.ts index a18ec8871598..071c3355759c 100644 --- a/components/brave_rewards/resources/ui/reducers/rewards_reducer.ts +++ b/components/brave_rewards/resources/ui/reducers/rewards_reducer.ts @@ -154,6 +154,14 @@ const rewardsReducer: Reducer = (state: Rewards.State state.adsData.adsEstimatedEarnings = data.adsEstimatedEarnings break } + case types.GET_ADS_IS_SUPPORTED_REGION: { + chrome.send('brave_rewards.getAdsIsSupportedRegion', []) + break + } + case types.ON_ADS_IS_SUPPORTED_REGION: { + state.adsData.adsIsSupported = action.payload.supported + break + } } return state diff --git a/components/brave_rewards/resources/ui/storage.ts b/components/brave_rewards/resources/ui/storage.ts index a97a17d5680f..84a45d21ff94 100644 --- a/components/brave_rewards/resources/ui/storage.ts +++ b/components/brave_rewards/resources/ui/storage.ts @@ -53,7 +53,8 @@ export const defaultState: Rewards.State = { adsPerHour: 0, adsUIEnabled: false, adsNotificationsReceived: 0, - adsEstimatedEarnings: 0 + adsEstimatedEarnings: 0, + adsIsSupported: true }, pendingContributionTotal: 0, grants: [], diff --git a/components/definitions/rewards.d.ts b/components/definitions/rewards.d.ts index 7ce0e4c76071..86bc06f485ad 100644 --- a/components/definitions/rewards.d.ts +++ b/components/definitions/rewards.d.ts @@ -154,5 +154,6 @@ declare namespace Rewards { adsUIEnabled: boolean adsNotificationsReceived: number adsEstimatedEarnings: number + adsIsSupported: boolean } } diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index c810d1b14de7..bfcf6362e692 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -199,6 +199,7 @@ Current earnings this month (Estimated) Payment date Ad notifications received + Sorry! Ads are not yet available in your region. Ad pages viewed Maximum number of ads displayed 1 ad per hour diff --git a/components/services/bat_ads/bat_ads_impl.cc b/components/services/bat_ads/bat_ads_impl.cc index 1539becd2760..82510f3a64db 100644 --- a/components/services/bat_ads/bat_ads_impl.cc +++ b/components/services/bat_ads/bat_ads_impl.cc @@ -113,4 +113,9 @@ void BatAdsImpl::GenerateAdReportingNotificationResultEvent( } } +void BatAdsImpl::IsSupportedRegion( + IsSupportedRegionCallback callback) { + std::move(callback).Run(ads_->IsSupportedRegion()); +} + } // namespace bat_ads diff --git a/components/services/bat_ads/bat_ads_impl.h b/components/services/bat_ads/bat_ads_impl.h index 6874b05c036f..9d895f430114 100644 --- a/components/services/bat_ads/bat_ads_impl.h +++ b/components/services/bat_ads/bat_ads_impl.h @@ -49,6 +49,8 @@ class BatAdsImpl : public mojom::BatAds { void GenerateAdReportingNotificationResultEvent( const std::string& notification_info, int32_t event_type) override; + void IsSupportedRegion( + IsSupportedRegionCallback callback) override; private: std::unique_ptr bat_ads_client_mojo_proxy_; diff --git a/components/services/bat_ads/public/interfaces/bat_ads.mojom b/components/services/bat_ads/public/interfaces/bat_ads.mojom index 0a242a9164cf..15d0dd56619f 100644 --- a/components/services/bat_ads/public/interfaces/bat_ads.mojom +++ b/components/services/bat_ads/public/interfaces/bat_ads.mojom @@ -77,4 +77,5 @@ interface BatAds { GenerateAdReportingNotificationShownEvent(string notification_info); GenerateAdReportingNotificationResultEvent( string notification_info, int32 result_type); + IsSupportedRegion() => (bool is_supported); }; diff --git a/package-lock.json b/package-lock.json index 33ab32b367d8..4057cdef1d84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1337,8 +1337,8 @@ } }, "brave-ui": { - "version": "github:brave/brave-ui#9568cc934ec7f4fdc935a8beb1474636f59f8ede", - "from": "github:brave/brave-ui#9568cc934ec7f4fdc935a8beb1474636f59f8ede", + "version": "github:brave/brave-ui#4ab1b185bc7b65aecbf98d5b54b4327c16d85513", + "from": "github:brave/brave-ui#4ab1b185bc7b65aecbf98d5b54b4327c16d85513", "dev": true, "requires": { "@ctrl/tinycolor": "^2.2.1", diff --git a/package.json b/package.json index f55f45638184..a874092a066e 100644 --- a/package.json +++ b/package.json @@ -277,7 +277,7 @@ "@types/react-redux": "6.0.4", "@types/redux-logger": "^3.0.7", "awesome-typescript-loader": "^5.2.1", - "brave-ui": "github:brave/brave-ui#9568cc934ec7f4fdc935a8beb1474636f59f8ede", + "brave-ui": "github:brave/brave-ui#4ab1b185bc7b65aecbf98d5b54b4327c16d85513", "css-loader": "^0.28.9", "csstype": "^2.5.5", "deep-freeze-node": "^1.1.3",