Skip to content

Commit

Permalink
Show error text to users that are not in allowed regions
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Sep 3, 2019
1 parent d225260 commit 525ed74
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 13 deletions.
17 changes: 16 additions & 1 deletion browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
#include <map>
#include <vector>

#include "base/strings/utf_string_conversions.h"
#include "brave/common/url_constants.h"
#include "components/grit/brave_components_resources.h"
#include "components/grit/brave_components_strings.h"
#include "components/grit/components_resources.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/base/l10n/l10n_util.h"

#if !defined(OS_ANDROID)
#include "brave/browser/ui/webui/navigation_bar_data_provider.h"
Expand Down Expand Up @@ -110,6 +113,16 @@ void CustomizeWebUIHTMLSource(const std::string &name,
};
AddResourcePaths(source, resources[name]);

/**
* REWARDS
*/
// String used to display not supported region for
// uphold wallet connection
base::string16 rewards_not_supported_region = l10n_util::GetStringFUTF16(
IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_NOT_ALLOWED,
base::ASCIIToUTF16(kRewardsUpholdSupport));
source->AddString("redirectModalNotAllowed", rewards_not_supported_region);

static std::map<std::string, std::vector<WebUISimpleItem> >
localized_strings = {
{
Expand Down Expand Up @@ -280,7 +293,9 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "walletCorrupted", IDS_BRAVE_REWARDS_LOCAL_WALLET_CORRUPTED },
{ "walletCorruptedNow", IDS_BRAVE_REWARDS_LOCAL_WALLET_CORRUPTED_NOW },
{ "grantAlreadyClaimedText", IDS_BRAVE_REWARDS_LOCAL_GRANT_ALREADY_CLAIMED_TEXT }, // NOLINT
{ "redirectModalError", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_ERROR }, // NOLINT
{ "redirectModalError", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_ERROR },
{ "redirectModalClose", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_CLOSE },
{ "redirectModalErrorWallet", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_ERROR_WALLET }, // NOLINT

{ "click", IDS_BRAVE_REWARDS_LOCAL_ADS_CONFIRMATION_TYPE_CLICK },
{ "dismiss", IDS_BRAVE_REWARDS_LOCAL_ADS_CONFIRMATION_TYPE_DISMISS },
Expand Down
1 change: 1 addition & 0 deletions common/url_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ const char kMagnetScheme[] = "magnet";
const char kRewardsScheme[] = "rewards";
const char kWidevineMoreInfoURL[] = "https://www.eff.org/issues/drm";
const char kWidevineTOS[] = "https://policies.google.com/terms";
const char kRewardsUpholdSupport[] = "https://uphold.com/en/brave/support";
1 change: 1 addition & 0 deletions common/url_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern const char kMagnetScheme[];
extern const char kRewardsScheme[];
extern const char kWidevineMoreInfoURL[];
extern const char kWidevineTOS[];
extern const char kRewardsUpholdSupport[];

// This is introduced to replace |kDownloadChromeUrl| in
// outdated_upgrade_bubble_view.cc"
Expand Down
15 changes: 10 additions & 5 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,16 @@ class BraveRewardsBrowserTest :
? "2018-08-01T09:53:51.258Z"
: "null";

return
"{"
"\"name\": \"Test User\","
"\"memberAt\": " + verified + ""
"}";
const std::string name = "Test User";

return base::StringPrintf(
"{"
"\"name\": \"%s\","
"\"memberAt\": \"%s\","
"\"currencies\": [\"BAT\"]"
"}",
name.c_str(),
verified.c_str());
}

void GetTestResponse(const std::string& url,
Expand Down
24 changes: 22 additions & 2 deletions components/brave_rewards/resources/ui/components/settingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,33 @@ class SettingsPage extends React.Component<Props, State> {
const { ui } = this.props.rewardsData

if (ui.modalRedirect === 'show') {
return <ModalRedirect />
return (
<ModalRedirect
id={'redirect-modal-show'}
titleText={getLocale('processingRequest')}
/>
)
}

if (ui.modalRedirect === 'notAllowed') {
return (
<ModalRedirect
id={'redirect-modal-not-allowed'}
errorText={{ __html: getLocale('redirectModalNotAllowed') }}
titleText={getLocale('redirectModalErrorWallet')}
buttonText={getLocale('redirectModalClose')}
onClick={this.actions.hideRedirectModal}
/>
)
}

if (ui.modalRedirect === 'error') {
return (
<ModalRedirect
errorText={getLocale('redirectModalError')}
id={'redirect-modal-error'}
errorText={{ __html: getLocale('redirectModalError') }}
buttonText={getLocale('processingRequestButton')}
titleText={getLocale('processingRequest')}
onClick={this.onRedirectError}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ const rewardsReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State
break
}

if (data.result === 25) {
ui.modalRedirect = 'notAllowed'
break
}

if (data.result !== 0) {
ui.modalRedirect = 'error'
break
Expand Down
2 changes: 1 addition & 1 deletion components/definitions/rewards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ declare namespace Rewards {
ui: {
emptyWallet: boolean
modalBackup: boolean
modalRedirect: 'show' | 'hide' | 'error'
modalRedirect: 'show' | 'hide' | 'error' | 'notAllowed'
paymentIdCheck: boolean
walletRecoverySuccess: boolean | null
walletServerProblem: boolean
Expand Down
3 changes: 3 additions & 0 deletions components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@
<message name="IDS_BRAVE_REWARDS_LOCAL_ADS_CONFIRMATION_TYPE_DISMISS" desc="">Dismissed</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_ADS_CONFIRMATION_TYPE_LANDED" desc="">Clicked</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_ADS_CONFIRMATION_TYPE_VIEW" desc="">Viewed</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_NOT_ALLOWED" desc="">BAT is not currently supported in your region. Please refer <ph name="BEGIN_LINK_REGION_TEXT">&lt;a target="_blank" href="$1"&gt;</ph>here<ph name="END_LINK_REGION_TEXT">&lt;/a&gt;</ph> for updates.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_CLOSE" desc="">Close</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_ERROR_WALLET" desc="">Error creating Brave Browser BAT card</message>

<!-- WebUI rewards internals resources -->
<message name="IDS_BRAVE_REWARDS_INTERNALS_AMOUNT" desc="Amount">Amount:</message>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
"@types/storybook__react": "^4.0.2",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.0.6",
"brave-ui": "github:brave/brave-ui#548aaa3f15ba4a64506d636db6f77ccea71c713c",
"brave-ui": "github:brave/brave-ui#fe38628ddf6876198c90ebaad5174a299f70f34e",
"css-loader": "^2.1.1",
"csstype": "^2.5.5",
"deep-freeze-node": "^1.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ enum Result {
PENDING_NOT_ENOUGH_FUNDS = 22,
RECURRING_TABLE_EMPTY = 23,
EXPIRED_TOKEN = 24,
BAT_NOT_ALLOWED = 25,
};

enum PublisherStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ void UpholdAuthorization::OnGetUser(
auto wallet_ptr = ledger::ExternalWallet::New(wallet);
std::map<std::string, std::string> args;

if (user.bat_not_allowed) {
callback(ledger::Result::BAT_NOT_ALLOWED, args);
return;
}

if (user.status == UserStatus::OK) {
wallet_ptr->status = user.verified
? ledger::WalletStatus::VERIFIED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <algorithm>

#include "base/json/json_reader.h"
#include "bat/ledger/internal/ledger_impl.h"
#include "bat/ledger/internal/uphold/uphold_user.h"
Expand All @@ -19,7 +21,8 @@ namespace braveledger_uphold {
name(""),
member_at(""),
verified(false),
status(UserStatus::EMPTY) {}
status(UserStatus::EMPTY),
bat_not_allowed(true) {}

User::~User() {}

Expand Down Expand Up @@ -94,6 +97,16 @@ void UpholdUser::OnGet(
user.verified = !user.member_at.empty();
}

auto* currencies = dictionary->FindKey("currencies");
if (currencies && currencies->is_list()) {
const std::string currency = "BAT";
auto bat_in_list = std::find(
currencies->GetList().begin(),
currencies->GetList().end(),
base::Value(currency));
user.bat_not_allowed = bat_in_list == currencies->GetList().end();
}

auto* status = dictionary->FindKey("status");
if (status && status->is_string()) {
user.status = GetStatus(status->GetString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct User {
std::string member_at;
bool verified;
UserStatus status;
bool bat_not_allowed;

User();
~User();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ void UpholdWallet::OnGenerate(
return;
}

if (user.bat_not_allowed) {
callback(ledger::Result::BAT_NOT_ALLOWED, std::move(wallet_ptr));
return;
}

if (!wallet_ptr || result != ledger::Result::LEDGER_OK) {
callback(result, std::move(wallet_ptr));
return;
Expand Down

0 comments on commit 525ed74

Please sign in to comment.