Skip to content

Commit

Permalink
Merge pull request #12850 from brave/pr12832_sszaloki-21209-http-400-…
Browse files Browse the repository at this point in the history
…region-not-supported_1.38.x

Implement unsupported regions in Rewards linking flow. (uplift to 1.38.x)
  • Loading branch information
kjozwiak authored Apr 7, 2022
2 parents 0afc21f + 202ffa2 commit 68dc27e
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 5 deletions.
2 changes: 2 additions & 0 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "redirectModalKYCRequiredText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_KYC_REQUIRED_TEXT }, // NOLINT
{ "redirectModalMismatchedProviderAccountsText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_MISMATCHED_PROVIDER_ACCOUNTS_TEXT}, // NOLINT
{ "redirectModalMismatchedProviderAccountsTitle", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_MISMATCHED_PROVIDER_ACCOUNTS_TITLE}, // NOLINT
{ "redirectModalRegionNotSupportedText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_REGION_NOT_SUPPORTED_TEXT}, // NOLINT
{ "redirectModalRegionNotSupportedTitle", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_REGION_NOT_SUPPORTED_TITLE}, // NOLINT
{ "redirectModalUpholdBATNotAllowedText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_BAT_NOT_ALLOWED_TEXT}, // NOLINT
{ "redirectModalUpholdBATNotAllowedTitle", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_BAT_NOT_ALLOWED_TITLE}, // NOLINT
{ "redirectModalUpholdBlockedUserText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_BLOCKED_USER_TEXT}, // NOLINT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ class SettingsPage extends React.Component<Props, State> {
onClick={this.actions.hideRedirectModal}
/>
)
case 'regionNotSupportedModal':
return (
<ModalRedirect
id={'redirect-modal-region-not-supported'}
errorText={[getLocale('redirectModalRegionNotSupportedText')]}
titleText={getLocale('redirectModalRegionNotSupportedTitle')}
buttonText={getLocale('redirectModalClose')}
walletType={walletType}
isMobile={true}
onClick={this.actions.hideRedirectModal}
/>
)
case 'show':
return (
<ModalRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ const rewardsReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State
break
}

if (data.result === 45) { // type::Result::REGION_NOT_SUPPORTED
ui.modalRedirect = 'regionNotSupportedModal'
break
}

if (data.result !== 0) {
ui.modalRedirect = 'error'
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ const walletReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
break
}

if (action.payload.result === 45) { // type::Result::REGION_NOT_SUPPORTED
state.ui.modalRedirect = 'regionNotSupportedModal'
break
}

if (action.payload.result === 0) { // type::Result::LEDGER_OK
chrome.send('brave_rewards.fetchBalance')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,17 @@ class SettingsPage extends React.Component<Props, State> {
onClick={this.actions.hideRedirectModal}
/>
)
case 'regionNotSupportedModal':
return (
<ModalRedirect
id={'redirect-modal-region-not-supported'}
errorText={[getLocale('redirectModalRegionNotSupportedText')]}
titleText={getLocale('redirectModalRegionNotSupportedTitle')}
buttonText={getLocale('redirectModalClose')}
walletType={walletType}
onClick={this.actions.hideRedirectModal}
/>
)
case 'show':
return (
<ModalRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ const rewardsReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State
break
}

if (data.result === 45) { // type::Result::REGION_NOT_SUPPORTED
ui.modalRedirect = 'regionNotSupportedModal'
break
}

if (data.result !== 0) {
ui.modalRedirect = 'error'
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ const walletReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
break
}

if (action.payload.result === 45) { // type::Result::REGION_NOT_SUPPORTED
state.ui.modalRedirect = 'regionNotSupportedModal'
break
}

if (action.payload.result === 0) { // type::Result::LEDGER_OK
chrome.send('brave_rewards.fetchBalance')
}
Expand Down
1 change: 1 addition & 0 deletions components/definitions/rewards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ declare namespace Rewards {
| 'hide'
| 'kycRequiredModal'
| 'mismatchedProviderAccountsModal'
| 'regionNotSupportedModal'
| 'show'
| 'upholdBATNotAllowedModal'
| 'upholdBlockedUserModal'
Expand Down
2 changes: 2 additions & 0 deletions components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_KYC_REQUIRED_TITLE" desc="">Error: You need a verified account to log in</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_MISMATCHED_PROVIDER_ACCOUNTS_TEXT" desc="">Hmm, it looks like your Brave Rewards has already been verified with another <ph name="PROVIDER">$1<ex>Uphold</ex></ph> account. Please try verifying again using your previous account.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_MISMATCHED_PROVIDER_ACCOUNTS_TITLE" desc="">Error: Different account</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_REGION_NOT_SUPPORTED_TEXT" desc="">Unfortunately, your Brave Rewards cannot be verified because your region is not supported for Brave Rewards verification at this time.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_REGION_NOT_SUPPORTED_TITLE" desc="">Error: Region not supported</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_BAT_NOT_ALLOWED_TEXT" desc="">BAT is not yet supported in your region on Uphold.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_BAT_NOT_ALLOWED_TITLE" desc="">Error: BAT unavailable</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_BLOCKED_USER_TEXT" desc="">Your account at Uphold is currently blocked.</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ enum Result {
UPHOLD_TRANSACTION_VERIFICATION_FAILURE = 41,
REQUEST_SIGNATURE_VERIFICATION_FAILURE = 42,
UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED = 43,
FLAGGED_WALLET = 44
FLAGGED_WALLET = 44,
REGION_NOT_SUPPORTED = 45
};

enum PublisherStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ void BitflyerAuthorization::OnClaimWallet(
case type::Result::MISMATCHED_PROVIDER_ACCOUNTS:
case type::Result::REQUEST_SIGNATURE_VERIFICATION_FAILURE:
case type::Result::FLAGGED_WALLET:
case type::Result::REGION_NOT_SUPPORTED:
ledger_->database()->SaveEventLog(
log::GetEventLogKeyForLinkingResult(result),
constant::kWalletBitflyer + std::string("/") + address.substr(0, 5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ type::Result PostClaimBitflyer::ParseBody(const std::string& body) const {
} else if (message->find("unable to link - unusual activity") !=
std::string::npos) {
return type::Result::FLAGGED_WALLET;
} else if (message->find("region not supported") != std::string::npos) {
return type::Result::REGION_NOT_SUPPORTED;
} else {
BLOG(0, "Unknown message!");
return type::Result::LEDGER_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ TEST_F(PostClaimBitflyerTest, ServerError400FlaggedWallet) {
});
}

TEST_F(PostClaimBitflyerTest, ServerError400RegionNotSupported) {
ON_CALL(*mock_ledger_client_, LoadURL(_, _))
.WillByDefault(Invoke(
[](type::UrlRequestPtr request, client::LoadURLCallback callback) {
type::UrlResponse response;
response.status_code = 400;
response.url = request->url;
response.body = R"(
{
"message": "region not supported: failed to validate account: invalid country",
"code": 400
}
)";
callback(response);
}));

claim_->Request("83b3b77b-e7c3-455b-adda-e476fa0656d2",
[](type::Result result) {
EXPECT_EQ(result, type::Result::REGION_NOT_SUPPORTED);
});
}

TEST_F(PostClaimBitflyerTest, ServerError400UnknownMessage) {
ON_CALL(*mock_ledger_client_, LoadURL(_, _))
.WillByDefault(Invoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ type::Result PostClaimGemini::ParseBody(const std::string& body) const {
} else if (message->find("unable to link - unusual activity") !=
std::string::npos) {
return type::Result::FLAGGED_WALLET;
} else if (message->find("region not supported") != std::string::npos) {
return type::Result::REGION_NOT_SUPPORTED;
} else {
BLOG(0, "Unknown message!");
return type::Result::LEDGER_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ TEST_F(PostClaimGeminiTest, ServerError400FlaggedWallet) {
});
}

TEST_F(PostClaimGeminiTest, ServerError400RegionNotSupported) {
ON_CALL(*mock_ledger_client_, LoadURL(_, _))
.WillByDefault(Invoke(
[](type::UrlRequestPtr request, client::LoadURLCallback callback) {
type::UrlResponse response;
response.status_code = net::HTTP_BAD_REQUEST;
response.url = request->url;
response.body = R"(
{
"message": "region not supported: failed to validate account: invalid country",
"code": 400
}
)";
callback(response);
}));

claim_->Request("mock_linking_info", "id", [](type::Result result) {
EXPECT_EQ(result, type::Result::REGION_NOT_SUPPORTED);
});
}

TEST_F(PostClaimGeminiTest, ServerError400UnknownMessage) {
ON_CALL(*mock_ledger_client_, LoadURL(_, _))
.WillByDefault(Invoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ type::Result PostClaimUphold::ParseBody(const std::string& body) const {
} else if (message->find("unable to link - unusual activity") !=
std::string::npos) {
return type::Result::FLAGGED_WALLET;
} else if (message->find("region not supported") != std::string::npos) {
return type::Result::REGION_NOT_SUPPORTED;
} else {
BLOG(0, "Unknown message!");
return type::Result::LEDGER_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ TEST_F(PostClaimUpholdTest, ServerError400FlaggedWallet) {
});
}

TEST_F(PostClaimUpholdTest, ServerError400RegionNotSupported) {
ON_CALL(*mock_ledger_client_, LoadURL(_, _))
.WillByDefault(Invoke(
[](type::UrlRequestPtr request, client::LoadURLCallback callback) {
type::UrlResponse response;
response.status_code = 400;
response.url = request->url;
response.body = R"(
{
"message": "region not supported: failed to validate account: invalid country",
"code": 400
}
)";
callback(response);
}));

claim_->Request(30.0, "address",
[](type::Result result, const std::string& address) {
EXPECT_EQ(result, type::Result::REGION_NOT_SUPPORTED);
EXPECT_EQ(address, kExpectedAddress);
});
}

TEST_F(PostClaimUpholdTest, ServerError400UnknownMessage) {
ON_CALL(*mock_ledger_client_, LoadURL(_, _))
.WillByDefault(Invoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ void GeminiAuthorization::OnClaimWallet(
case type::Result::MISMATCHED_PROVIDER_ACCOUNTS:
case type::Result::REQUEST_SIGNATURE_VERIFICATION_FAILURE:
case type::Result::FLAGGED_WALLET:
case type::Result::REGION_NOT_SUPPORTED:
ledger_->database()->SaveEventLog(
log::GetEventLogKeyForLinkingResult(result),
constant::kWalletGemini + std::string("/") +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const char kMismatchedProviderAccounts[] = "mismatched_provider_accounts";
const char kPromotionsClaimed[] = "promotion_claimed";
const char kRecurringTipAdded[] = "recurring_tip_added";
const char kRecurringTipRemoved[] = "recurring_tip_removed";
const char kRegionNotSupported[] = "region_not_supported";
const char kRequestSignatureVerificationFailure[] =
"request_signature_verification_failure";
const char kTransactionVerificationFailure[] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ std::string GetEventLogKeyForLinkingResult(type::Result result) {
switch (result) {
case type::Result::DEVICE_LIMIT_REACHED:
return log::kDeviceLimitReached;
case type::Result::FLAGGED_WALLET:
return log::kFlaggedWallet;
case type::Result::MISMATCHED_PROVIDER_ACCOUNTS:
return log::kMismatchedProviderAccounts;
case type::Result::NOT_FOUND:
return log::kKYCRequired;
case type::Result::REGION_NOT_SUPPORTED:
return log::kRegionNotSupported;
case type::Result::REQUEST_SIGNATURE_VERIFICATION_FAILURE:
return log::kRequestSignatureVerificationFailure;
case type::Result::UPHOLD_TRANSACTION_VERIFICATION_FAILURE:
return log::kTransactionVerificationFailure;
case type::Result::FLAGGED_WALLET:
return log::kFlaggedWallet;
default:
NOTREACHED();
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,42 @@ INSTANTIATE_TEST_SUITE_P(
type::Result::FLAGGED_WALLET,
type::WalletStatus::NOT_CONNECTED
},
LinkWalletParamType{ // Region not supported.
"05_region_not_supported",
R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })",
type::UrlResponse{
{},
{},
net::HttpStatusCode::HTTP_OK,
R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })",
{}
},
type::UrlResponse{
{},
{},
net::HttpStatusCode::HTTP_OK,
R"([ { "id": "962ef3b8-bc12-4619-a349-c8083931b795", "label": "Brave Browser" } ])",
{}
},
false,
R"({ "payment_id": "f375da3c-c206-4f09-9422-665b8e5952db", "recovery_seed": "OG2zYotDSeZ81qLtr/uq5k/GC6WE5/7BclT1lHi4l+w=" })",
type::UrlResponse{
{},
{},
net::HttpStatusCode::HTTP_BAD_REQUEST,
R"(
{
"message": "region not supported: failed to validate account: invalid country",
"code": 400
}
)",
{}
},
type::Result::REGION_NOT_SUPPORTED,
type::WalletStatus::NOT_CONNECTED
},
LinkWalletParamType{ // Rewards Link (Claim) Wallet failed.
"05_link_wallet_failed",
"06_link_wallet_failed",
R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })",
type::UrlResponse{
{},
Expand Down Expand Up @@ -1302,7 +1336,7 @@ INSTANTIATE_TEST_SUITE_P(
type::WalletStatus::PENDING
},
LinkWalletParamType{ // Happy path.
"06_happy_path",
"07_happy_path",
R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })",
type::UrlResponse{
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ void UpholdWallet::OnLinkWallet(const type::Result result,
case type::Result::NOT_FOUND: // KYC required
case type::Result::UPHOLD_TRANSACTION_VERIFICATION_FAILURE:
case type::Result::FLAGGED_WALLET:
case type::Result::REGION_NOT_SUPPORTED:
// Entering NOT_CONNECTED.
ledger_->uphold()->DisconnectWallet("");
ledger_->database()->SaveEventLog(
Expand Down

0 comments on commit 68dc27e

Please sign in to comment.