Skip to content

Commit

Permalink
Merge pull request #13474 from brave/sszaloki-22508-capabilities-endp…
Browse files Browse the repository at this point in the history
…oint

Implements `/v0/me/capabilities`, `upholdInsufficientCapabilitiesModal`.
  • Loading branch information
szilardszaloki authored and bsclifton committed May 27, 2022
1 parent e1d033b commit 3707840
Show file tree
Hide file tree
Showing 25 changed files with 1,132 additions and 341 deletions.
10 changes: 2 additions & 8 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,8 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "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
{ "redirectModalUpholdBlockedUserTitle", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_BLOCKED_USER_TITLE}, // NOLINT
{ "redirectModalUpholdCustomerDueDiligenceRequiredText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED_TEXT}, // NOLINT
{ "redirectModalUpholdCustomerDueDiligenceRequiredTitle", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED_TITLE}, // NOLINT
{ "redirectModalUpholdPendingUserText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_PENDING_USER_TEXT}, // NOLINT
{ "redirectModalUpholdPendingUserTitle", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_PENDING_USER_TITLE}, // NOLINT
{ "redirectModalUpholdRestrictedUserText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_RESTRICTED_USER_TEXT}, // NOLINT
{ "redirectModalUpholdRestrictedUserTitle", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_RESTRICTED_USER_TITLE}, // NOLINT
{ "redirectModalUpholdInsufficientCapabilitiesText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_INSUFFICIENT_CAPABILITIES_TEXT}, // NOLINT
{ "redirectModalUpholdInsufficientCapabilitiesTitle", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_INSUFFICIENT_CAPABILITIES_TITLE}, // NOLINT
{ "redirectModalWalletOwnershipVerificationFailureText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_WALLET_OWNERSHIP_VERIFICATION_FAILURE_TEXT}, // NOLINT
{ "redirectModalWalletOwnershipVerificationFailureTitle", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_WALLET_OWNERSHIP_VERIFICATION_FAILURE_TITLE}, // NOLINT
{ "tosAndPp", IDS_BRAVE_REWARDS_LOCAL_TOS_AND_PP}, // NOLINT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,52 +303,12 @@ class SettingsPage extends React.Component<Props, State> {
onClick={this.actions.hideRedirectModal}
/>
)
case 'upholdBlockedUserModal':
case 'upholdInsufficientCapabilitiesModal':
return (
<ModalRedirect
id={'redirect-modal-uphold-blocked-user'}
errorText={[getLocale('redirectModalUpholdBlockedUserText')]}
titleText={getLocale('redirectModalUpholdBlockedUserTitle')}
learnMore={'https://support.uphold.com/hc/en-us/articles/360045765351-Why-we-block-or-restrict-accounts-and-how-to-reduce-the-risk'}
buttonText={getLocale('redirectModalClose')}
walletType={walletType}
isMobile={true}
onClick={this.actions.hideRedirectModal}
/>
)
case 'upholdCustomerDueDiligenceRequiredModal':
return (
<ModalRedirect
id={'redirect-modal-uphold-customer-due-diligence-required'}
errorText={[getLocale('redirectModalUpholdCustomerDueDiligenceRequiredText')]}
titleText={getLocale('redirectModalUpholdCustomerDueDiligenceRequiredTitle')}
learnMore={'https://wallet.uphold.com/customer-due-diligence'}
buttonText={getLocale('redirectModalClose')}
walletType={walletType}
isMobile={true}
onClick={this.actions.hideRedirectModal}
/>
)
case 'upholdPendingUserModal':
return (
<ModalRedirect
id={'redirect-modal-uphold-pending-user'}
errorText={[getLocale('redirectModalUpholdPendingUserText')]}
titleText={getLocale('redirectModalUpholdPendingUserTitle')}
learnMore={'https://support.uphold.com/hc/en-us/articles/206695986-How-do-I-sign-up-for-Uphold-Web-'}
buttonText={getLocale('redirectModalClose')}
walletType={walletType}
isMobile={true}
onClick={this.actions.hideRedirectModal}
/>
)
case 'upholdRestrictedUserModal':
return (
<ModalRedirect
id={'redirect-modal-uphold-restricted-user'}
errorText={[getLocale('redirectModalUpholdRestrictedUserText')]}
titleText={getLocale('redirectModalUpholdRestrictedUserTitle')}
learnMore={'https://support.uphold.com/hc/en-us/articles/360045765351-Why-we-block-or-restrict-accounts-and-how-to-reduce-the-risk'}
id={'redirect-modal-uphold-insufficient-capabilities'}
errorText={[getLocale('redirectModalUpholdInsufficientCapabilitiesText')]}
titleText={getLocale('redirectModalUpholdInsufficientCapabilitiesTitle')}
buttonText={getLocale('redirectModalClose')}
walletType={walletType}
isMobile={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,8 @@ const walletReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
break
}

if (action.payload.result === 38) { // type::Result::UPHOLD_BLOCKED_USER
state.ui.modalRedirect = 'upholdBlockedUserModal'
break
}

if (action.payload.result === 39) { // type::Result::UPHOLD_PENDING_USER
state.ui.modalRedirect = 'upholdPendingUserModal'
break
}

if (action.payload.result === 40) { // type::Result::UPHOLD_RESTRICTED_USER
state.ui.modalRedirect = 'upholdRestrictedUserModal'
break
}

if (action.payload.result === 43) { // type::Result::UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED
state.ui.modalRedirect = 'upholdCustomerDueDiligenceRequiredModal'
if (action.payload.result === 43) { // type::Result::UPHOLD_INSUFFICIENT_CAPABILITIES
state.ui.modalRedirect = 'upholdInsufficientCapabilitiesModal'
break
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,49 +306,12 @@ class SettingsPage extends React.Component<Props, State> {
onClick={this.actions.hideRedirectModal}
/>
)
case 'upholdBlockedUserModal':
case 'upholdInsufficientCapabilitiesModal':
return (
<ModalRedirect
id={'redirect-modal-uphold-blocked-user'}
errorText={[getLocale('redirectModalUpholdBlockedUserText')]}
titleText={getLocale('redirectModalUpholdBlockedUserTitle')}
learnMore={'https://support.uphold.com/hc/en-us/articles/360045765351-Why-we-block-or-restrict-accounts-and-how-to-reduce-the-risk'}
buttonText={getLocale('redirectModalClose')}
walletType={walletType}
onClick={this.actions.hideRedirectModal}
/>
)
case 'upholdCustomerDueDiligenceRequiredModal':
return (
<ModalRedirect
id={'redirect-modal-uphold-customer-due-diligence-required'}
errorText={[getLocale('redirectModalUpholdCustomerDueDiligenceRequiredText')]}
titleText={getLocale('redirectModalUpholdCustomerDueDiligenceRequiredTitle')}
learnMore={'https://wallet.uphold.com/customer-due-diligence'}
buttonText={getLocale('redirectModalClose')}
walletType={walletType}
onClick={this.actions.hideRedirectModal}
/>
)
case 'upholdPendingUserModal':
return (
<ModalRedirect
id={'redirect-modal-uphold-pending-user'}
errorText={[getLocale('redirectModalUpholdPendingUserText')]}
titleText={getLocale('redirectModalUpholdPendingUserTitle')}
learnMore={'https://support.uphold.com/hc/en-us/articles/206695986-How-do-I-sign-up-for-Uphold-Web-'}
buttonText={getLocale('redirectModalClose')}
walletType={walletType}
onClick={this.actions.hideRedirectModal}
/>
)
case 'upholdRestrictedUserModal':
return (
<ModalRedirect
id={'redirect-modal-uphold-restricted-user'}
errorText={[getLocale('redirectModalUpholdRestrictedUserText')]}
titleText={getLocale('redirectModalUpholdRestrictedUserTitle')}
learnMore={'https://support.uphold.com/hc/en-us/articles/360045765351-Why-we-block-or-restrict-accounts-and-how-to-reduce-the-risk'}
id={'redirect-modal-uphold-insufficient-capabilities'}
errorText={[getLocale('redirectModalUpholdInsufficientCapabilitiesText')]}
titleText={getLocale('redirectModalUpholdInsufficientCapabilitiesTitle')}
buttonText={getLocale('redirectModalClose')}
walletType={walletType}
onClick={this.actions.hideRedirectModal}
Expand Down
19 changes: 2 additions & 17 deletions components/brave_rewards/resources/page/reducers/wallet_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,13 @@ const walletReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
break
}

if (action.payload.result === 38) { // type::Result::UPHOLD_BLOCKED_USER
state.ui.modalRedirect = 'upholdBlockedUserModal'
break
}

if (action.payload.result === 39) { // type::Result::UPHOLD_PENDING_USER
state.ui.modalRedirect = 'upholdPendingUserModal'
break
}

if (action.payload.result === 40) { // type::Result::UPHOLD_RESTRICTED_USER
state.ui.modalRedirect = 'upholdRestrictedUserModal'
break
}

if (action.payload.result === 41) { // type::Result::UPHOLD_TRANSACTION_VERIFICATION_FAILURE
state.ui.modalRedirect = 'walletOwnershipVerificationFailureModal'
break
}

if (action.payload.result === 43) { // type::Result::UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED
state.ui.modalRedirect = 'upholdCustomerDueDiligenceRequiredModal'
if (action.payload.result === 43) { // type::Result::UPHOLD_INSUFFICIENT_CAPABILITIES
state.ui.modalRedirect = 'upholdInsufficientCapabilitiesModal'
break
}

Expand Down
5 changes: 1 addition & 4 deletions components/definitions/rewards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ declare namespace Rewards {
| 'regionNotSupportedModal'
| 'show'
| 'upholdBATNotAllowedModal'
| 'upholdBlockedUserModal'
| 'upholdCustomerDueDiligenceRequiredModal'
| 'upholdPendingUserModal'
| 'upholdRestrictedUserModal'
| 'upholdInsufficientCapabilitiesModal'
| 'walletOwnershipVerificationFailureModal'
paymentIdCheck: boolean
promosDismissed?: {
Expand Down
10 changes: 2 additions & 8 deletions components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,8 @@
<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>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_BLOCKED_USER_TITLE" desc="">Error: Blocked account</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED_TEXT" desc="">Uphold is required to collect a little more information about you before enabling full Uphold account functionality. Please try again once you've submitted this information in your Uphold account.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED_TITLE" desc="">Error: Limited Uphold account functionality</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_PENDING_USER_TEXT" desc="">Your account at Uphold is still pending.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_PENDING_USER_TITLE" desc="">Error: Pending account</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_RESTRICTED_USER_TEXT" desc="">Your account at Uphold is currently restricted.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_RESTRICTED_USER_TITLE" desc="">Error: Restricted account</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_INSUFFICIENT_CAPABILITIES_TEXT" desc="">According to Uphold, there are currently some limitations on your Uphold account. Please log in to your Uphold account and check whether there are any notices or remaining account requirements to complete, then try again. For example, you may need to submit more information to Uphold.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_UPHOLD_INSUFFICIENT_CAPABILITIES_TITLE" desc="">Error: Limited Uphold account functionality</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_WALLET_OWNERSHIP_VERIFICATION_FAILURE_TEXT" desc="">There was a problem validating your browser's request to connect Brave Rewards to your <ph name="PROVIDER">$1<ex>Uphold</ex></ph> account. You can <ph name="BEGIN_LINK">$2</ph>contact support<ph name="END_LINK">$3</ph> for more help.</message>
<message name="IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_WALLET_OWNERSHIP_VERIFICATION_FAILURE_TITLE" desc="">Error: Request could not be validated</message>

Expand Down
3 changes: 3 additions & 0 deletions vendor/bat-native-ledger/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ source_set("ledger") {
"src/bat/ledger/internal/endpoint/rewards/rewards_server.h",
"src/bat/ledger/internal/endpoint/rewards/rewards_util.cc",
"src/bat/ledger/internal/endpoint/rewards/rewards_util.h",
"src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.cc",
"src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.h",
"src/bat/ledger/internal/endpoint/uphold/get_card/get_card.cc",
"src/bat/ledger/internal/endpoint/uphold/get_card/get_card.h",
"src/bat/ledger/internal/endpoint/uphold/get_cards/get_cards.cc",
Expand Down Expand Up @@ -570,6 +572,7 @@ source_set("ledger") {
"src/bat/ledger/internal/uphold/uphold.h",
"src/bat/ledger/internal/uphold/uphold_authorization.cc",
"src/bat/ledger/internal/uphold/uphold_authorization.h",
"src/bat/ledger/internal/uphold/uphold_capabilities.h",
"src/bat/ledger/internal/uphold/uphold_card.cc",
"src/bat/ledger/internal/uphold/uphold_card.h",
"src/bat/ledger/internal/uphold/uphold_transfer.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,9 @@ enum Result {

DEVICE_LIMIT_REACHED = 36,
MISMATCHED_PROVIDER_ACCOUNTS = 37,
UPHOLD_BLOCKED_USER = 38,
UPHOLD_PENDING_USER = 39,
UPHOLD_RESTRICTED_USER = 40,
UPHOLD_TRANSACTION_VERIFICATION_FAILURE = 41,
REQUEST_SIGNATURE_VERIFICATION_FAILURE = 42,
UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED = 43,
UPHOLD_INSUFFICIENT_CAPABILITIES = 43,
FLAGGED_WALLET = 44,
REGION_NOT_SUPPORTED = 45
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* Copyright (c) 2022 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/. */

#include "bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.h"

#include <utility>

#include "base/json/json_reader.h"
#include "bat/ledger/internal/endpoint/uphold/uphold_utils.h"
#include "bat/ledger/internal/ledger_impl.h"
#include "net/http/http_status_code.h"

using ledger::uphold::Capabilities;
using std::placeholders::_1;

namespace ledger {
namespace endpoint {
namespace uphold {

GetCapabilities::GetCapabilities(LedgerImpl* ledger)
: ledger_((DCHECK(ledger), ledger)) {}

GetCapabilities::~GetCapabilities() = default;

void GetCapabilities::Request(const std::string& token,
GetCapabilitiesCallback callback) {
auto request = type::UrlRequest::New();
request->url = GetServerUrl("/v0/me/capabilities");
request->headers = RequestAuthorization(token);
ledger_->LoadURL(
std::move(request),
std::bind(&GetCapabilities::OnRequest, this, _1, std::move(callback)));
}

void GetCapabilities::OnRequest(const type::UrlResponse& response,
GetCapabilitiesCallback callback) {
ledger::LogUrlResponse(__func__, response);

auto [result, capability_map] = ProcessResponse(response);

Capabilities capabilities;
if (capability_map.count("receives") && capability_map.count("sends")) {
capabilities.can_receive = capability_map["receives"];
capabilities.can_send = capability_map["sends"];
}

callback(result, std::move(capabilities));
}

std::pair<type::Result, std::map<std::string, bool>>
GetCapabilities::ProcessResponse(const type::UrlResponse& response) {
const auto status_code = response.status_code;

if (status_code == net::HTTP_UNAUTHORIZED) {
BLOG(1, "Unauthorized access, HTTP status: " << status_code);
return {type::Result::EXPIRED_TOKEN, {}};
}

if (status_code != net::HTTP_OK) {
BLOG(0, "Unexpected HTTP status: " << status_code);
return {type::Result::LEDGER_ERROR, {}};
}

auto capability_map = ParseBody(response.body);
return {!capability_map.empty() ? type::Result::LEDGER_OK
: type::Result::LEDGER_ERROR,
std::move(capability_map)};
}

std::map<std::string, bool> GetCapabilities::ParseBody(
const std::string& body) {
std::map<std::string, bool> capability_map;

const auto value = base::JSONReader::Read(body);
const base::ListValue* list_value = nullptr;

if (value && value->GetAsList(&list_value)) {
DCHECK(list_value);

for (const auto& item : list_value->GetList()) {
const auto* key = item.FindStringKey("key");
const auto enabled = item.FindBoolKey("enabled");

if (!key || !enabled) {
capability_map.clear();
break;
}

capability_map.emplace(*key, *enabled);
}
}

if (capability_map.empty()) {
BLOG(0, "Invalid body format!");
}

return capability_map;
}

} // namespace uphold
} // namespace endpoint
} // namespace ledger
Loading

0 comments on commit 3707840

Please sign in to comment.