diff --git a/browser/ui/webui/brave_webui_source.cc b/browser/ui/webui/brave_webui_source.cc index 69ed85e47df9..f57b98905e6c 100644 --- a/browser/ui/webui/brave_webui_source.cc +++ b/browser/ui/webui/brave_webui_source.cc @@ -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 diff --git a/components/brave_rewards/resources/android_page/components/settingsPage.tsx b/components/brave_rewards/resources/android_page/components/settingsPage.tsx index 6634035b6406..f23ef581b2f5 100644 --- a/components/brave_rewards/resources/android_page/components/settingsPage.tsx +++ b/components/brave_rewards/resources/android_page/components/settingsPage.tsx @@ -303,52 +303,12 @@ class SettingsPage extends React.Component { onClick={this.actions.hideRedirectModal} /> ) - case 'upholdBlockedUserModal': + case 'upholdInsufficientCapabilitiesModal': return ( - ) - case 'upholdCustomerDueDiligenceRequiredModal': - return ( - - ) - case 'upholdPendingUserModal': - return ( - - ) - case 'upholdRestrictedUserModal': - return ( - = (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 } diff --git a/components/brave_rewards/resources/page/components/settingsPage.tsx b/components/brave_rewards/resources/page/components/settingsPage.tsx index 2bc43edfc0d1..4436068a4eaa 100644 --- a/components/brave_rewards/resources/page/components/settingsPage.tsx +++ b/components/brave_rewards/resources/page/components/settingsPage.tsx @@ -306,49 +306,12 @@ class SettingsPage extends React.Component { onClick={this.actions.hideRedirectModal} /> ) - case 'upholdBlockedUserModal': + case 'upholdInsufficientCapabilitiesModal': return ( - ) - case 'upholdCustomerDueDiligenceRequiredModal': - return ( - - ) - case 'upholdPendingUserModal': - return ( - - ) - case 'upholdRestrictedUserModal': - return ( - = (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 } diff --git a/components/definitions/rewards.d.ts b/components/definitions/rewards.d.ts index 07961814b081..f8f339599c3c 100644 --- a/components/definitions/rewards.d.ts +++ b/components/definitions/rewards.d.ts @@ -83,10 +83,7 @@ declare namespace Rewards { | 'regionNotSupportedModal' | 'show' | 'upholdBATNotAllowedModal' - | 'upholdBlockedUserModal' - | 'upholdCustomerDueDiligenceRequiredModal' - | 'upholdPendingUserModal' - | 'upholdRestrictedUserModal' + | 'upholdInsufficientCapabilitiesModal' | 'walletOwnershipVerificationFailureModal' paymentIdCheck: boolean promosDismissed?: { diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index 943f4401d881..9cbc01ccaf30 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -503,14 +503,8 @@ Error: Region not supported BAT is not yet supported in your region on Uphold. Error: BAT unavailable - Your account at Uphold is currently blocked. - Error: Blocked account - 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. - Error: Limited Uphold account functionality - Your account at Uphold is still pending. - Error: Pending account - Your account at Uphold is currently restricted. - Error: Restricted account + 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. + Error: Limited Uphold account functionality There was a problem validating your browser's request to connect Brave Rewards to your $1Uphold account. You can $2contact support$3 for more help. Error: Request could not be validated diff --git a/vendor/bat-native-ledger/BUILD.gn b/vendor/bat-native-ledger/BUILD.gn index 542d88707f7a..7ad079058d2b 100644 --- a/vendor/bat-native-ledger/BUILD.gn +++ b/vendor/bat-native-ledger/BUILD.gn @@ -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", @@ -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", 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 063d23870d70..15d0f9c38acc 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 @@ -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 }; diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.cc new file mode 100644 index 000000000000..c649fda5261a --- /dev/null +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.cc @@ -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 + +#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> +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 GetCapabilities::ParseBody( + const std::string& body) { + std::map 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 diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.h b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.h new file mode 100644 index 000000000000..f9420e0dd2a4 --- /dev/null +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.h @@ -0,0 +1,200 @@ +/* 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/. */ + +#ifndef BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_ENDPOINT_UPHOLD_GET_CAPABILITIES_GET_CAPABILITIES_H_ +#define BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_ENDPOINT_UPHOLD_GET_CAPABILITIES_GET_CAPABILITIES_H_ + +#include +#include +#include + +#include "bat/ledger/internal/uphold/uphold_capabilities.h" +#include "bat/ledger/ledger.h" + +// GET https://api.uphold.com/v0/me/capabilities +// +// Success code: +// HTTP_OK (200) +// +// Error codes: +// HTTP_UNAUTHORIZED (401) +// HTTP_TOO_MANY_REQUESTS (429) +// HTTP_INTERNAL_SERVER_ERROR (500) +// +// Response body: +// [ +// { +// "category": "features", +// "enabled": true, +// "key": "change_phone", +// "name": "Change Phone", +// "requirements": [], +// "restrictions": [] +// }, +// { +// "category": "features", +// "enabled": true, +// "key": "change_pii", +// "name": "ChangePII", +// "requirements": [], +// "restrictions": [] +// }, +// { +// "category": "features", +// "enabled": true, +// "key": "equities", +// "name": "Equities", +// "requirements": [ +// "user-must-accept-equities-terms-of-services" +// ], +// "restrictions": [] +// }, +// { +// "category": "features", +// "enabled": true, +// "key": "limit_orders", +// "name": "Limit Orders", +// "requirements": [], +// "restrictions": [] +// }, +// { +// "category": "features", +// "enabled": false, +// "key": "physical_card_eea", +// "name": "Physical Card EEA", +// "requirements": [], +// "restrictions": [ +// "user-country-not-supported" +// ] +// }, +// { +// "category": "features", +// "enabled": false, +// "key": "physical_card_us", +// "name": "Physical Card US", +// "requirements": [], +// "restrictions": [ +// "user-country-not-supported" +// ] +// }, +// { +// "category": "features", +// "enabled": false, +// "key": "physical_card", +// "name": "Physical Card", +// "requirements": [], +// "restrictions": [ +// "user-country-not-supported" +// ] +// }, +// { +// "category": "features", +// "enabled": true, +// "key": "referrals", +// "name": "Referrals", +// "requirements": [], +// "restrictions": [] +// }, +// { +// "category": "features", +// "enabled": true, +// "key": "staking", +// "name": "Staking", +// "requirements": [], +// "restrictions": [] +// }, +// { +// "category": "features", +// "enabled": true, +// "key": "virtual_iban", +// "name": "Virtual IBAN", +// "requirements": [ +// "user-must-accept-virtual-iban-terms-of-services" +// ], +// "restrictions": [] +// }, +// { +// "category": "permissions", +// "enabled": true, +// "key": "deposits", +// "name": "Deposits", +// "requirements": [], +// "restrictions": [] +// }, +// { +// "category": "permissions", +// "enabled": true, +// "key": "invites", +// "name": "Invites", +// "requirements": [], +// "restrictions": [] +// }, +// { +// "category": "permissions", +// "enabled": true, +// "key": "receives", +// "name": "Receives", +// "requirements": [], +// "restrictions": [] +// }, +// { +// "category": "permissions", +// "enabled": true, +// "key": "sends", +// "name": "Sends", +// "requirements": [], +// "restrictions": [] +// }, +// { +// "category": "permissions", +// "enabled": true, +// "key": "trades", +// "name": "Trades", +// "requirements": [], +// "restrictions": [] +// }, +// { +// "category": "permissions", +// "enabled": true, +// "key": "withdrawals", +// "name": "Withdrawals", +// "requirements": [], +// "restrictions": [] +// } +// ] + +namespace ledger { +class LedgerImpl; + +namespace endpoint { +namespace uphold { + +using GetCapabilitiesCallback = + std::function; + +class GetCapabilities { + public: + explicit GetCapabilities(LedgerImpl* ledger); + ~GetCapabilities(); + + void Request(const std::string& token, GetCapabilitiesCallback callback); + + private: + void OnRequest(const type::UrlResponse& response, + GetCapabilitiesCallback callback); + + std::pair> ProcessResponse( + const type::UrlResponse& response); + + std::map ParseBody(const std::string& body); + + LedgerImpl* ledger_; // NOT OWNED +}; + +} // namespace uphold +} // namespace endpoint +} // namespace ledger + +#endif // BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_ENDPOINT_UPHOLD_GET_CAPABILITIES_GET_CAPABILITIES_H_ diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities_unittest.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities_unittest.cc new file mode 100644 index 000000000000..e24e11125421 --- /dev/null +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities_unittest.cc @@ -0,0 +1,246 @@ +/* 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 +#include +#include +#include + +#include "base/test/task_environment.h" +#include "bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.h" +#include "bat/ledger/internal/ledger_client_mock.h" +#include "bat/ledger/internal/ledger_impl_mock.h" +#include "bat/ledger/internal/uphold/uphold_capabilities.h" +#include "bat/ledger/ledger.h" +#include "net/http/http_status_code.h" +#include "testing/gtest/include/gtest/gtest.h" + +// npm run test -- brave_unit_tests --filter=GetCapabilitiesTest.* + +using ledger::uphold::Capabilities; +using ::testing::_; +using ::testing::Invoke; + +namespace ledger { +namespace endpoint { +namespace uphold { + +class GetCapabilitiesTest : public testing::Test { + protected: + GetCapabilitiesTest() + : mock_ledger_client_(std::make_unique()), + mock_ledger_impl_(std::make_unique( + mock_ledger_client_.get())), + get_capabilities_( + std::make_unique(mock_ledger_impl_.get())) {} + + private: + base::test::TaskEnvironment scoped_task_environment_; + + protected: + std::unique_ptr mock_ledger_client_; + std::unique_ptr mock_ledger_impl_; + std::unique_ptr get_capabilities_; +}; + +TEST_F(GetCapabilitiesTest, ServerReturns200OK) { + ON_CALL(*mock_ledger_client_, LoadURL(_, _)) + .WillByDefault( + Invoke([](type::UrlRequestPtr, client::LoadURLCallback callback) { + type::UrlResponse response; + response.status_code = net::HTTP_OK; + response.body = R"( +[ + { + "category": "features", + "enabled": true, + "key": "change_phone", + "name": "Change Phone", + "requirements": [], + "restrictions": [] + }, + { + "category": "features", + "enabled": true, + "key": "change_pii", + "name": "ChangePII", + "requirements": [], + "restrictions": [] + }, + { + "category": "features", + "enabled": true, + "key": "equities", + "name": "Equities", + "requirements": [ + "user-must-accept-equities-terms-of-services" + ], + "restrictions": [] + }, + { + "category": "features", + "enabled": true, + "key": "limit_orders", + "name": "Limit Orders", + "requirements": [], + "restrictions": [] + }, + { + "category": "features", + "enabled": false, + "key": "physical_card_eea", + "name": "Physical Card EEA", + "requirements": [], + "restrictions": [ + "user-country-not-supported" + ] + }, + { + "category": "features", + "enabled": false, + "key": "physical_card_us", + "name": "Physical Card US", + "requirements": [], + "restrictions": [ + "user-country-not-supported" + ] + }, + { + "category": "features", + "enabled": false, + "key": "physical_card", + "name": "Physical Card", + "requirements": [], + "restrictions": [ + "user-country-not-supported" + ] + }, + { + "category": "features", + "enabled": true, + "key": "referrals", + "name": "Referrals", + "requirements": [], + "restrictions": [] + }, + { + "category": "features", + "enabled": true, + "key": "staking", + "name": "Staking", + "requirements": [], + "restrictions": [] + }, + { + "category": "features", + "enabled": true, + "key": "virtual_iban", + "name": "Virtual IBAN", + "requirements": [ + "user-must-accept-virtual-iban-terms-of-services" + ], + "restrictions": [] + }, + { + "category": "permissions", + "enabled": true, + "key": "deposits", + "name": "Deposits", + "requirements": [], + "restrictions": [] + }, + { + "category": "permissions", + "enabled": true, + "key": "invites", + "name": "Invites", + "requirements": [], + "restrictions": [] + }, + { + "category": "permissions", + "enabled": false, + "key": "receives", + "name": "Receives", + "requirements": [], + "restrictions": [] + }, + { + "category": "permissions", + "enabled": true, + "key": "sends", + "name": "Sends", + "requirements": [], + "restrictions": [] + }, + { + "category": "permissions", + "enabled": true, + "key": "trades", + "name": "Trades", + "requirements": [], + "restrictions": [] + }, + { + "category": "permissions", + "enabled": true, + "key": "withdrawals", + "name": "Withdrawals", + "requirements": [], + "restrictions": [] + } +] + )"; + callback(std::move(response)); + })); + + get_capabilities_->Request( + "193a77cf-02e8-4e10-8127-8a1b5a8bfece", + [](type::Result result, Capabilities capabilities) { + EXPECT_EQ(result, type::Result::LEDGER_OK); + EXPECT_EQ(capabilities.can_receive, false); + EXPECT_EQ(capabilities.can_send, true); + }); +} + +TEST_F(GetCapabilitiesTest, ServerReturns401Unauthorized) { + ON_CALL(*mock_ledger_client_, LoadURL(_, _)) + .WillByDefault( + Invoke([](type::UrlRequestPtr, client::LoadURLCallback callback) { + type::UrlResponse response; + response.status_code = net::HTTP_UNAUTHORIZED; + callback(std::move(response)); + })); + + get_capabilities_->Request( + "193a77cf-02e8-4e10-8127-8a1b5a8bfece", + [](type::Result result, Capabilities capabilities) { + EXPECT_EQ(result, type::Result::EXPIRED_TOKEN); + EXPECT_EQ(capabilities.can_receive, absl::nullopt); + EXPECT_EQ(capabilities.can_send, absl::nullopt); + }); +} + +TEST_F(GetCapabilitiesTest, ServerReturnsUnexpectedHTTPStatus) { + ON_CALL(*mock_ledger_client_, LoadURL(_, _)) + .WillByDefault( + Invoke([](type::UrlRequestPtr, client::LoadURLCallback callback) { + type::UrlResponse response; + response.status_code = net::HTTP_INTERNAL_SERVER_ERROR; + callback(std::move(response)); + })); + + get_capabilities_->Request( + "193a77cf-02e8-4e10-8127-8a1b5a8bfece", + [](type::Result result, Capabilities capabilities) { + EXPECT_EQ(result, type::Result::LEDGER_ERROR); + EXPECT_EQ(capabilities.can_receive, absl::nullopt); + EXPECT_EQ(capabilities.can_send, absl::nullopt); + }); +} + +} // namespace uphold +} // namespace endpoint +} // namespace ledger diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_me/get_me.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_me/get_me.cc index 5f529dc4f7f6..f3c7acfb6016 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_me/get_me.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_me/get_me.cc @@ -15,30 +15,6 @@ using std::placeholders::_1; -namespace { - -ledger::uphold::UserStatus GetUserStatus(const std::string& status) { - if (status == "pending") { - return ledger::uphold::UserStatus::PENDING; - } - - if (status == "restricted") { - return ledger::uphold::UserStatus::RESTRICTED; - } - - if (status == "blocked") { - return ledger::uphold::UserStatus::BLOCKED; - } - - if (status == "ok") { - return ledger::uphold::UserStatus::OK; - } - - return ledger::uphold::UserStatus::EMPTY; -} - -} // namespace - namespace ledger { namespace endpoint { namespace uphold { @@ -103,16 +79,6 @@ type::Result GetMe::ParseBody( user->bat_not_allowed = bat_in_list == currencies->GetList().end(); } - const auto* status = dictionary->FindStringKey("status"); - if (status) { - user->status = GetUserStatus(*status); - } - - if (const auto* cdd_status = dictionary->FindStringPath( - "verifications.customerDueDiligence.status")) { - user->customer_due_diligence_required = *cdd_status == "required"; - } - return type::Result::LEDGER_OK; } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_me/get_me_unittest.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_me/get_me_unittest.cc index 6967935c6e70..564a1b795905 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_me/get_me_unittest.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_me/get_me_unittest.cc @@ -151,7 +151,6 @@ TEST_F(GetMeTest, ServerOK) { EXPECT_EQ(user.name, "John"); EXPECT_EQ(user.member_id, "b34060c9-5ca3-4bdb-bc32-1f826ecea36e"); EXPECT_EQ(user.bat_not_allowed, false); - EXPECT_EQ(user.status, ::ledger::uphold::UserStatus::OK); }); } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/uphold_server.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/uphold_server.cc index 1dc7ee400762..5cff6c3c1d4a 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/uphold_server.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/uphold_server.cc @@ -10,17 +10,17 @@ namespace ledger { namespace endpoint { -UpholdServer::UpholdServer(LedgerImpl* ledger): - post_oauth_(std::make_unique(ledger)), - get_cards_(std::make_unique(ledger)), - get_card_(std::make_unique(ledger)), - get_me_(std::make_unique(ledger)), - post_cards_(std::make_unique(ledger)), - patch_card_(std::make_unique(ledger)), - post_transaction_(std::make_unique(ledger)), - post_transaction_commit_( - std::make_unique(ledger)) { -} +UpholdServer::UpholdServer(LedgerImpl* ledger) + : post_oauth_(std::make_unique(ledger)), + get_capabilities_(std::make_unique(ledger)), + get_cards_(std::make_unique(ledger)), + get_card_(std::make_unique(ledger)), + get_me_(std::make_unique(ledger)), + post_cards_(std::make_unique(ledger)), + patch_card_(std::make_unique(ledger)), + post_transaction_(std::make_unique(ledger)), + post_transaction_commit_( + std::make_unique(ledger)) {} UpholdServer::~UpholdServer() = default; @@ -28,6 +28,10 @@ uphold::PostOauth* UpholdServer::post_oauth() const { return post_oauth_.get(); } +uphold::GetCapabilities* UpholdServer::get_capabilities() const { + return get_capabilities_.get(); +} + uphold::GetCards* UpholdServer::get_cards() const { return get_cards_.get(); } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/uphold_server.h b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/uphold_server.h index fa0e23d3226d..d5ab617dc7dd 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/uphold_server.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/uphold_server.h @@ -3,11 +3,12 @@ * 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/. */ -#ifndef BRAVELEDGER_ENDPOINT_UPHOLD_UPHOLD_SERVER_H_ -#define BRAVELEDGER_ENDPOINT_UPHOLD_UPHOLD_SERVER_H_ +#ifndef BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_ENDPOINT_UPHOLD_UPHOLD_SERVER_H_ +#define BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_ENDPOINT_UPHOLD_UPHOLD_SERVER_H_ #include +#include "bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.h" #include "bat/ledger/internal/endpoint/uphold/get_card/get_card.h" #include "bat/ledger/internal/endpoint/uphold/get_cards/get_cards.h" #include "bat/ledger/internal/endpoint/uphold/get_me/get_me.h" @@ -30,6 +31,8 @@ class UpholdServer { uphold::PostOauth* post_oauth() const; + uphold::GetCapabilities* get_capabilities() const; + uphold::GetCards* get_cards() const; uphold::GetCard* get_card() const; @@ -46,6 +49,7 @@ class UpholdServer { private: std::unique_ptr post_oauth_; + std::unique_ptr get_capabilities_; std::unique_ptr get_cards_; std::unique_ptr get_card_; std::unique_ptr get_me_; @@ -58,4 +62,4 @@ class UpholdServer { } // namespace endpoint } // namespace ledger -#endif // BRAVELEDGER_ENDPOINT_UPHOLD_UPHOLD_SERVER_H_ +#endif // BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_ENDPOINT_UPHOLD_UPHOLD_SERVER_H_ diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc index 022888a8b373..1bb923c0b416 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc @@ -221,6 +221,25 @@ void Uphold::GetUser(GetUserCallback callback) { user_->Get(callback); } +void Uphold::GetCapabilities(GetCapabilitiesCallback callback) { + auto uphold_wallet = GetWallet(); + if (!uphold_wallet) { + BLOG(0, "Uphold wallet is null!"); + return callback(type::Result::LEDGER_ERROR, {}); + } + + if (uphold_wallet->status != type::WalletStatus::PENDING && + uphold_wallet->status != type::WalletStatus::VERIFIED) { + BLOG(0, "Uphold wallet is neither in PENDING, nor in VERIFIED state!"); + return callback(type::Result::LEDGER_ERROR, {}); + } + + CheckWalletState(uphold_wallet.get()); + + uphold_server_->get_capabilities()->Request(uphold_wallet->token, + std::move(callback)); +} + void Uphold::SaveTransferFee(const std::string& contribution_id, const double fee) { StartTransferFeeTimer(contribution_id, 1); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.h b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.h index aef9d66a5a8a..7d5a3758fd81 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.h @@ -14,6 +14,7 @@ #include "base/containers/flat_map.h" #include "base/timer/timer.h" +#include "bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities.h" #include "bat/ledger/internal/uphold/uphold_user.h" #include "bat/ledger/ledger.h" @@ -40,6 +41,7 @@ class UpholdWallet; using FetchBalanceCallback = std::function; using CreateCardCallback = std::function; +using endpoint::uphold::GetCapabilitiesCallback; class Uphold { public: @@ -72,6 +74,8 @@ class Uphold { void GetUser(GetUserCallback callback); + void GetCapabilities(GetCapabilitiesCallback callback); + type::ExternalWalletPtr GetWallet(); bool SetWallet(type::ExternalWalletPtr wallet); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_capabilities.h b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_capabilities.h new file mode 100644 index 000000000000..74e6a874e7c5 --- /dev/null +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_capabilities.h @@ -0,0 +1,22 @@ +/* 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/. */ + +#ifndef BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_UPHOLD_UPHOLD_CAPABILITIES_H_ +#define BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_UPHOLD_UPHOLD_CAPABILITIES_H_ + +#include "third_party/abseil-cpp/absl/types/optional.h" + +namespace ledger { +namespace uphold { + +struct Capabilities { + absl::optional can_receive; + absl::optional can_send; +}; + +} // namespace uphold +} // namespace ledger + +#endif // BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_UPHOLD_UPHOLD_CAPABILITIES_H_ diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_unittest.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_unittest.cc index d482d71f60e9..83dbd9ab8b7b 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_unittest.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_unittest.cc @@ -506,23 +506,48 @@ INSTANTIATE_TEST_SUITE_P( type::Result::CONTINUE, type::WalletStatus::PENDING }, - // NOLINTNEXTLINE - GetUserParamType{ // Customer due diligence is required for the user! (PENDING) - "02_PENDING_customer_due_diligence_is_required_for_the_user", + GetUserParamType{ // BAT is not allowed for the user! (PENDING) + "02_PENDING_bat_is_not_allowed_for_the_user", R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })", type::UrlResponse{ {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "verifications": { "customerDueDiligence": { "status": "required" } } })", + R"({ "currencies": [] })", {} }, - type::Result::UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED, + type::Result::UPHOLD_BAT_NOT_ALLOWED, type::WalletStatus::NOT_CONNECTED }, - GetUserParamType{ // BAT is not allowed for the user! (PENDING) - "03_PENDING_bat_is_not_allowed_for_the_user", - R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })", + GetUserParamType{ // Access token expired! (VERIFIED) + "03_VERIFIED_access_token_expired", + R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_UNAUTHORIZED, + {}, + {} + }, + type::Result::EXPIRED_TOKEN, + type::WalletStatus::DISCONNECTED_VERIFIED + }, + GetUserParamType{ // Couldn't get the user object from Uphold! (VERIFIED) + "04_VERIFIED_couldn_t_get_the_user_object_from_uphold", + R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_INTERNAL_SERVER_ERROR, + {}, + {} + }, + type::Result::CONTINUE, + type::WalletStatus::VERIFIED + }, + GetUserParamType{ // BAT is not allowed for the user! (VERIFIED) + "05_VERIFIED_bat_is_not_allowed_for_the_user", + R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", type::UrlResponse{ {}, {}, @@ -531,50 +556,201 @@ INSTANTIATE_TEST_SUITE_P( {} }, type::Result::UPHOLD_BAT_NOT_ALLOWED, + type::WalletStatus::DISCONNECTED_VERIFIED + }), + NameSuffixGenerator +); +// clang-format on + +TEST_P(GetUser, Paths) { + const auto& params = GetParam(); + std::string uphold_wallet = std::get<1>(params); + const auto& uphold_get_user_response = std::get<2>(params); + const auto expected_result = std::get<3>(params); + const auto expected_status = std::get<4>(params); + + ON_CALL(*mock_ledger_client_, GetStringState(state::kWalletUphold)) + .WillByDefault( + [&] { return FakeEncryption::Base64EncryptString(uphold_wallet); }); + + ON_CALL(*mock_ledger_client_, SetStringState(state::kWalletUphold, _)) + .WillByDefault([&](const std::string&, const std::string& value) { + uphold_wallet = *FakeEncryption::Base64DecryptString(value); + return true; + }); + + ON_CALL(*mock_ledger_client_, LoadURL(_, _)) + .WillByDefault( + [&](type::UrlRequestPtr, client::LoadURLCallback callback) { + callback(uphold_get_user_response); + }); + + ON_CALL(*mock_ledger_impl_, database()) + .WillByDefault(Return(mock_database_.get())); + + uphold_->GenerateWallet( + [&](type::Result result) { ASSERT_EQ(result, expected_result); }); + + const auto status = GetStatusFromJSON(uphold_wallet); + if (status && expected_status) { + ASSERT_EQ(*status, *expected_status); + } else { + ASSERT_TRUE(!status && !expected_status); + } +} + +// clang-format off +using GetCapabilitiesParamType = std::tuple< + std::string, // test name suffix + std::string, // input Uphold wallet + type::UrlResponse, // Uphold Get User response + type::UrlResponse, // Uphold Get Capabilities response + type::Result, // expected result + absl::optional // expected status +>; + +struct GetCapabilities : UpholdTest, + WithParamInterface {}; + +INSTANTIATE_TEST_SUITE_P( + UpholdTest, + GetCapabilities, + Values( + GetCapabilitiesParamType{ // Access token expired! (PENDING) + "00_PENDING_access_token_expired", + R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })", + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_UNAUTHORIZED, + {}, + {} + }, + type::Result::EXPIRED_TOKEN, type::WalletStatus::NOT_CONNECTED }, - GetUserParamType{ // Account is blocked at Uphold. (PENDING) - "04_PENDING_account_is_blocked_at_uphold", + // NOLINTNEXTLINE + GetCapabilitiesParamType{ // Couldn't get capabilities from Uphold! (PENDING) + "01_PENDING_couldn_t_get_capabilities_from_uphold", R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })", type::UrlResponse{ {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "blocked" })", + R"({ "currencies": [ "BAT" ] })", {} }, - type::Result::UPHOLD_BLOCKED_USER, - type::WalletStatus::NOT_CONNECTED + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_INTERNAL_SERVER_ERROR, + {}, + {} + }, + type::Result::CONTINUE, + type::WalletStatus::PENDING }, - GetUserParamType{ // Account is pending at Uphold. (PENDING) - "05_PENDING_account_is_pending_at_uphold", + // NOLINTNEXTLINE + GetCapabilitiesParamType{ // Couldn't get capabilities from Uphold! (PENDING) + "02_PENDING_couldn_t_get_capabilities_from_uphold", R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })", type::UrlResponse{ {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "pending" })", + R"({ "currencies": [ "BAT" ] })", {} }, - type::Result::UPHOLD_PENDING_USER, - type::WalletStatus::NOT_CONNECTED + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + {}, + {} + }, + type::Result::CONTINUE, + type::WalletStatus::PENDING + }, + // NOLINTNEXTLINE + GetCapabilitiesParamType{ // Couldn't get capabilities from Uphold! (PENDING) + "03_PENDING_couldn_t_get_capabilities_from_uphold", + R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })", + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "sends", "enabled": true } ])", + {} + }, + type::Result::CONTINUE, + type::WalletStatus::PENDING + }, + // NOLINTNEXTLINE + GetCapabilitiesParamType{ // Couldn't get capabilities from Uphold! (PENDING) + "04_PENDING_couldn_t_get_capabilities_from_uphold", + R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })", + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true } ])", + {} + }, + type::Result::CONTINUE, + type::WalletStatus::PENDING }, - GetUserParamType{ // Account is restricted at Uphold. (PENDING) - "06_PENDING_account_is_restricted_at_uphold", + // NOLINTNEXTLINE + GetCapabilitiesParamType{ // User doesn't have the required Uphold capabilities! (PENDING) + "05_PENDING_user_doesnt_have_the_required_uphold_capabilities", R"({ "status": 5, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150" })", type::UrlResponse{ {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "restricted" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": false } ])", {} }, - type::Result::UPHOLD_RESTRICTED_USER, + type::Result::UPHOLD_INSUFFICIENT_CAPABILITIES, type::WalletStatus::NOT_CONNECTED }, - GetUserParamType{ // Access token expired! (VERIFIED) - "07_VERIFIED_access_token_expired", + GetCapabilitiesParamType{ // Access token expired! (VERIFIED) + "06_VERIFIED_access_token_expired", R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"({ "currencies": [ "BAT" ] })", + {} + }, type::UrlResponse{ {}, {}, @@ -585,9 +761,17 @@ INSTANTIATE_TEST_SUITE_P( type::Result::EXPIRED_TOKEN, type::WalletStatus::DISCONNECTED_VERIFIED }, - GetUserParamType{ // Couldn't get the user object from Uphold! (VERIFIED) - "08_VERIFIED_couldn_t_get_the_user_object_from_uphold", + // NOLINTNEXTLINE + GetCapabilitiesParamType{ // Couldn't get capabilities from Uphold! (VERIFIED) + "07_VERIFIED_couldn_t_get_capabilities_from_uphold", R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"({ "currencies": [ "BAT" ] })", + {} + }, type::UrlResponse{ {}, {}, @@ -599,94 +783,120 @@ INSTANTIATE_TEST_SUITE_P( type::WalletStatus::VERIFIED }, // NOLINTNEXTLINE - GetUserParamType{ // Customer due diligence is required for the user! (VERIFIED) - "09_VERIFIED_customer_due_diligence_is_required_for_the_user", + GetCapabilitiesParamType{ // Couldn't get capabilities from Uphold! (VERIFIED) + "08_VERIFIED_couldn_t_get_capabilities_from_uphold", R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", type::UrlResponse{ {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "verifications": { "customerDueDiligence": { "status": "required" } } })", + R"({ "currencies": [ "BAT" ] })", {} }, - type::Result::UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED, - type::WalletStatus::DISCONNECTED_VERIFIED - }, - GetUserParamType{ // BAT is not allowed for the user! (VERIFIED) - "10_VERIFIED_bat_is_not_allowed_for_the_user", - R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", type::UrlResponse{ {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [] })", + {}, {} }, - type::Result::UPHOLD_BAT_NOT_ALLOWED, - type::WalletStatus::DISCONNECTED_VERIFIED + type::Result::CONTINUE, + type::WalletStatus::VERIFIED }, - GetUserParamType{ // Account is blocked at Uphold. (VERIFIED) - "11_VERIFIED_account_is_blocked_at_uphold", + // NOLINTNEXTLINE + GetCapabilitiesParamType{ // Couldn't get capabilities from Uphold! (VERIFIED) + "09_VERIFIED_couldn_t_get_capabilities_from_uphold", R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", type::UrlResponse{ {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "blocked" })", + R"({ "currencies": [ "BAT" ] })", {} }, - type::Result::UPHOLD_BLOCKED_USER, - type::WalletStatus::DISCONNECTED_VERIFIED + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "sends", "enabled": true } ])", + {} + }, + type::Result::CONTINUE, + type::WalletStatus::VERIFIED }, - GetUserParamType{ // Account is pending at Uphold. (VERIFIED) - "12_VERIFIED_account_is_pending_at_uphold", + // NOLINTNEXTLINE + GetCapabilitiesParamType{ // Couldn't get capabilities from Uphold! (VERIFIED) + "10_VERIFIED_couldn_t_get_capabilities_from_uphold", R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", type::UrlResponse{ {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "pending" })", + R"({ "currencies": [ "BAT" ] })", {} }, - type::Result::UPHOLD_PENDING_USER, - type::WalletStatus::DISCONNECTED_VERIFIED + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true } ])", + {} + }, + type::Result::CONTINUE, + type::WalletStatus::VERIFIED }, - GetUserParamType{ // Account is restricted at Uphold. (VERIFIED) - "13_VERIFIED_account_is_restricted_at_uphold", + // NOLINTNEXTLINE + GetCapabilitiesParamType{ // User doesn't have the required Uphold capabilities! (VERIFIED) + "11_VERIFIED_user_doesnt_have_the_required_uphold_capabilities", R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", type::UrlResponse{ {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "restricted" })", + R"({ "currencies": [ "BAT" ] })", {} }, - type::Result::UPHOLD_RESTRICTED_USER, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": false } ])", + {} + }, + type::Result::UPHOLD_INSUFFICIENT_CAPABILITIES, type::WalletStatus::DISCONNECTED_VERIFIED }, - GetUserParamType{ // Happy path. (VERIFIED) - "14_VERIFIED_happy_path", + GetCapabilitiesParamType{ // Happy path. (VERIFIED) + "12_VERIFIED_happy_path", R"({ "status": 2, "token": "0047c2fd8f023e067354dbdb5639ee67acf77150", "address": "962ef3b8-bc12-4619-a349-c8083931b795" })", type::UrlResponse{ {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::Result::LEDGER_OK, type::WalletStatus::VERIFIED }), - NameSuffixGenerator + NameSuffixGenerator ); // clang-format on -TEST_P(GetUser, Paths) { +TEST_P(GetCapabilities, Paths) { const auto& params = GetParam(); std::string uphold_wallet = std::get<1>(params); const auto& uphold_get_user_response = std::get<2>(params); - const auto expected_result = std::get<3>(params); - const auto expected_status = std::get<4>(params); + const auto& uphold_get_capabilities_response = std::get<3>(params); + const auto expected_result = std::get<4>(params); + const auto expected_status = std::get<5>(params); ON_CALL(*mock_ledger_client_, GetStringState(state::kWalletUphold)) .WillByDefault( @@ -698,15 +908,21 @@ TEST_P(GetUser, Paths) { return true; }); - ON_CALL(*mock_ledger_client_, LoadURL(_, _)) - .WillByDefault( - [&](type::UrlRequestPtr, client::LoadURLCallback callback) { - callback(uphold_get_user_response); - }); + EXPECT_CALL(*mock_ledger_client_, LoadURL(_, _)) + .Times(AtMost(2)) + .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { + callback(uphold_get_user_response); + }) + .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { + callback(uphold_get_capabilities_response); + }); ON_CALL(*mock_ledger_impl_, database()) .WillByDefault(Return(mock_database_.get())); + ON_CALL(*mock_ledger_impl_, promotion()) + .WillByDefault(Return(mock_promotion_.get())); + uphold_->GenerateWallet( [&](type::Result result) { ASSERT_EQ(result, expected_result); }); @@ -723,6 +939,7 @@ using GetCardIDParamType = std::tuple< std::string, // test name suffix std::string, // input Uphold wallet type::UrlResponse, // Uphold Get User response + type::UrlResponse, // Uphold Get Capabilities response type::UrlResponse, // Uphold List Cards response type::UrlResponse, // Uphold Create Card response type::UrlResponse, // Uphold Update Card response @@ -744,7 +961,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -767,7 +991,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -795,7 +1026,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -823,7 +1061,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -852,7 +1097,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -886,7 +1138,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -921,11 +1180,12 @@ TEST_P(GetCardID, Paths) { const auto& params = GetParam(); std::string uphold_wallet = std::get<1>(params); const auto& uphold_get_user_response = std::get<2>(params); - const auto& uphold_list_cards_response = std::get<3>(params); - const auto& uphold_create_card_response = std::get<4>(params); - const auto& uphold_update_card_response = std::get<5>(params); - const auto expected_result = std::get<6>(params); - const auto expected_status = std::get<7>(params); + const auto& uphold_get_capabilities_response = std::get<3>(params); + const auto& uphold_list_cards_response = std::get<4>(params); + const auto& uphold_create_card_response = std::get<5>(params); + const auto& uphold_update_card_response = std::get<6>(params); + const auto expected_result = std::get<7>(params); + const auto expected_status = std::get<8>(params); ON_CALL(*mock_ledger_client_, GetStringState(state::kWalletUphold)) .WillByDefault( @@ -938,10 +1198,13 @@ TEST_P(GetCardID, Paths) { }); EXPECT_CALL(*mock_ledger_client_, LoadURL(_, _)) - .Times(AtMost(4)) + .Times(AtMost(5)) .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { callback(uphold_get_user_response); }) + .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { + callback(uphold_get_capabilities_response); + }) .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { callback(uphold_list_cards_response); }) @@ -972,6 +1235,7 @@ using GetAnonFundsParamType = std::tuple< std::string, // test name suffix std::string, // input Uphold wallet type::UrlResponse, // Uphold Get User response + type::UrlResponse, // Uphold Get Capabilities response type::UrlResponse, // Uphold List Cards response bool, // fetch_old_balance std::string, // input Rewards wallet @@ -994,7 +1258,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -1017,7 +1288,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -1047,13 +1325,14 @@ TEST_P(GetAnonFunds, Paths) { const auto& params = GetParam(); std::string uphold_wallet = std::get<1>(params); const auto& uphold_get_user_response = std::get<2>(params); - const auto& uphold_list_cards_response = std::get<3>(params); - const auto fetch_old_balance = std::get<4>(params); - const auto& input_rewards_wallet = std::get<5>(params); + const auto& uphold_get_capabilities_response = std::get<3>(params); + const auto& uphold_list_cards_response = std::get<4>(params); + const auto fetch_old_balance = std::get<5>(params); + const auto& input_rewards_wallet = std::get<6>(params); const auto& rewards_services_get_wallet_balance_response = - std::get<6>(params); - const auto expected_result = std::get<7>(params); - const auto expected_status = std::get<8>(params); + std::get<7>(params); + const auto expected_result = std::get<8>(params); + const auto expected_status = std::get<9>(params); ON_CALL(*mock_ledger_client_, GetStringState(state::kWalletUphold)) .WillByDefault( @@ -1066,10 +1345,13 @@ TEST_P(GetAnonFunds, Paths) { }); EXPECT_CALL(*mock_ledger_client_, LoadURL(_, _)) - .Times(AtMost(3)) + .Times(AtMost(4)) .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { callback(uphold_get_user_response); }) + .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { + callback(uphold_get_capabilities_response); + }) .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { callback(uphold_list_cards_response); }) @@ -1103,6 +1385,7 @@ using LinkWalletParamType = std::tuple< std::string, // test name suffix std::string, // input Uphold wallet type::UrlResponse, // Uphold Get User response + type::UrlResponse, // Uphold Get Capabilities response type::UrlResponse, // Uphold List Cards response bool, // fetch_old_balance std::string, // input Rewards wallet @@ -1125,7 +1408,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -1154,7 +1444,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -1188,7 +1485,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -1222,7 +1526,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -1256,7 +1567,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -1290,7 +1608,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -1324,7 +1649,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -1353,7 +1685,14 @@ INSTANTIATE_TEST_SUITE_P( {}, {}, net::HttpStatusCode::HTTP_OK, - R"({ "currencies": [ "BAT" ], "status": "ok", "memberAt": "2021-05-26T16:42:23.134Z" })", + R"({ "currencies": [ "BAT" ] })", + {} + }, + type::UrlResponse{ + {}, + {}, + net::HttpStatusCode::HTTP_OK, + R"([ { "key": "receives", "enabled": true }, { "key": "sends", "enabled": true } ])", {} }, type::UrlResponse{ @@ -1383,12 +1722,13 @@ TEST_P(LinkWallet, Paths) { const auto& params = GetParam(); std::string uphold_wallet = std::get<1>(params); const auto& uphold_get_user_response = std::get<2>(params); - const auto& uphold_list_cards_response = std::get<3>(params); - const auto fetch_old_balance = std::get<4>(params); - const auto& input_rewards_wallet = std::get<5>(params); - const auto& rewards_link_wallet_response = std::get<6>(params); - const auto expected_result = std::get<7>(params); - const auto expected_status = std::get<8>(params); + const auto& uphold_get_capabilities_response = std::get<3>(params); + const auto& uphold_list_cards_response = std::get<4>(params); + const auto fetch_old_balance = std::get<5>(params); + const auto& input_rewards_wallet = std::get<6>(params); + const auto& rewards_link_wallet_response = std::get<7>(params); + const auto expected_result = std::get<8>(params); + const auto expected_status = std::get<9>(params); ON_CALL(*mock_ledger_client_, GetStringState(state::kWalletUphold)) .WillByDefault( @@ -1401,10 +1741,13 @@ TEST_P(LinkWallet, Paths) { }); EXPECT_CALL(*mock_ledger_client_, LoadURL(_, _)) - .Times(AtMost(3)) + .Times(AtMost(4)) .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { callback(uphold_get_user_response); }) + .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { + callback(uphold_get_capabilities_response); + }) .WillOnce([&](type::UrlRequestPtr, client::LoadURLCallback callback) { callback(uphold_list_cards_response); }) diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_user.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_user.cc index fe14a62c0b2d..a9d53f0a820d 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_user.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_user.cc @@ -21,12 +21,7 @@ using std::placeholders::_3; namespace ledger { namespace uphold { -User::User() - : name(""), - member_id(""), - status(UserStatus::EMPTY), - bat_not_allowed(true), - customer_due_diligence_required(false) {} +User::User() : name(""), member_id(""), bat_not_allowed(true) {} User::~User() = default; diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_user.h b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_user.h index 43c8f8350ce2..8b4aadd9f580 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_user.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_user.h @@ -20,20 +20,10 @@ class UpholdServer; namespace uphold { -enum UserStatus { - EMPTY = 0, - PENDING = 1, - RESTRICTED = 2, - BLOCKED = 3, - OK = 4, -}; - struct User { std::string name; std::string member_id; - UserStatus status; bool bat_not_allowed; - bool customer_due_diligence_required; User(); ~User(); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.cc index a50db93df9d2..df4b29d37c3b 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.cc @@ -16,30 +16,13 @@ #include "bat/ledger/internal/notifications/notification_keys.h" #include "bat/ledger/internal/uphold/uphold_util.h" +using ledger::uphold::Capabilities; using std::placeholders::_1; using std::placeholders::_2; namespace ledger { namespace uphold { -namespace { -type::Result GetReturnValueForUserStatus(UserStatus status) { - DCHECK(status != UserStatus::OK); - - switch (status) { - case UserStatus::BLOCKED: - return type::Result::UPHOLD_BLOCKED_USER; - case UserStatus::PENDING: - return type::Result::UPHOLD_PENDING_USER; - case UserStatus::RESTRICTED: - return type::Result::UPHOLD_RESTRICTED_USER; - default: - DCHECK(status == UserStatus::EMPTY); - return type::Result::LEDGER_ERROR; - } -} -} // namespace - UpholdWallet::UpholdWallet(LedgerImpl* ledger) : ledger_{ledger}, promotion_server_{std::make_unique(ledger)} {} @@ -112,16 +95,6 @@ void UpholdWallet::OnGetUser(const type::Result result, return callback(type::Result::CONTINUE); } - if (user.customer_due_diligence_required) { - BLOG(0, "Customer due diligence is required for the user!"); - // Entering NOT_CONNECTED or DISCONNECTED_VERIFIED. - ledger_->uphold()->DisconnectWallet( - uphold_wallet->status == type::WalletStatus::VERIFIED - ? ledger::notifications::kWalletDisconnected - : ""); - return callback(type::Result::UPHOLD_CUSTOMER_DUE_DILIGENCE_REQUIRED); - } - if (user.bat_not_allowed) { BLOG(0, "BAT is not allowed for the user!"); // Entering NOT_CONNECTED or DISCONNECTED_VERIFIED. @@ -136,11 +109,48 @@ void UpholdWallet::OnGetUser(const type::Result result, return callback(type::Result::LEDGER_ERROR); } - if (user.status != UserStatus::OK) { + ledger_->uphold()->GetCapabilities(std::bind( + &UpholdWallet::OnGetCapabilities, this, _1, _2, std::move(callback))); +} + +void UpholdWallet::OnGetCapabilities(type::Result result, + Capabilities capabilities, + ledger::ResultCallback callback) const { + auto uphold_wallet = ledger_->uphold()->GetWallet(); + if (!uphold_wallet) { + BLOG(0, "Uphold wallet is null!"); + return callback(type::Result::LEDGER_ERROR); + } + + if (uphold_wallet->status != type::WalletStatus::PENDING && + uphold_wallet->status != type::WalletStatus::VERIFIED) { + return callback(type::Result::LEDGER_OK); + } + + CheckWalletState(uphold_wallet.get()); + + if (result == type::Result::EXPIRED_TOKEN) { + BLOG(0, "Access token expired!"); // Entering NOT_CONNECTED or DISCONNECTED_VERIFIED. - ledger_->uphold()->DisconnectWallet(""); + ledger_->uphold()->DisconnectWallet( + ledger::notifications::kWalletDisconnected); + return callback(type::Result::EXPIRED_TOKEN); + } + + if (result != type::Result::LEDGER_OK || !capabilities.can_receive || + !capabilities.can_send) { + BLOG(0, "Couldn't get capabilities from Uphold!"); + return callback(type::Result::CONTINUE); + } - return callback(GetReturnValueForUserStatus(user.status)); + if (!*capabilities.can_receive || !*capabilities.can_send) { + BLOG(0, "User doesn't have the required Uphold capabilities!"); + // Entering NOT_CONNECTED or DISCONNECTED_VERIFIED. + ledger_->uphold()->DisconnectWallet( + uphold_wallet->status == type::WalletStatus::VERIFIED + ? ledger::notifications::kWalletDisconnected + : ""); + return callback(type::Result::UPHOLD_INSUFFICIENT_CAPABILITIES); } if (uphold_wallet->status == type::WalletStatus::VERIFIED) { @@ -148,8 +158,8 @@ void UpholdWallet::OnGetUser(const type::Result result, std::bind(&UpholdWallet::OnTransferTokens, this, _1, _2, callback)); } - ledger_->uphold()->CreateCard( - std::bind(&UpholdWallet::OnCreateCard, this, _1, _2, callback)); + ledger_->uphold()->CreateCard(std::bind(&UpholdWallet::OnCreateCard, this, _1, + _2, std::move(callback))); } void UpholdWallet::OnCreateCard(const type::Result result, diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.h b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.h index 51c8ee61fe42..51c43612f395 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_wallet.h @@ -6,10 +6,12 @@ #ifndef BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_UPHOLD_UPHOLD_WALLET_H_ #define BRAVE_VENDOR_BAT_NATIVE_LEDGER_SRC_BAT_LEDGER_INTERNAL_UPHOLD_UPHOLD_WALLET_H_ +#include #include #include #include "bat/ledger/internal/endpoint/promotion/promotion_server.h" +#include "bat/ledger/internal/uphold/uphold_capabilities.h" #include "bat/ledger/internal/uphold/uphold_user.h" #include "bat/ledger/ledger.h" @@ -31,6 +33,10 @@ class UpholdWallet { const User& user, ledger::ResultCallback callback) const; + void OnGetCapabilities(type::Result result, + ledger::uphold::Capabilities capabilities, + ledger::ResultCallback callback) const; + void OnCreateCard(const type::Result result, const std::string& id, ledger::ResultCallback callback) const; diff --git a/vendor/bat-native-ledger/test/BUILD.gn b/vendor/bat-native-ledger/test/BUILD.gn index 5e184cf8e0de..28a49c1ec9fe 100644 --- a/vendor/bat-native-ledger/test/BUILD.gn +++ b/vendor/bat-native-ledger/test/BUILD.gn @@ -86,6 +86,7 @@ source_set("bat_native_ledger_tests") { "//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/put_safetynet/put_safetynet_unittest.cc", "//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/rewards/get_prefix_list/get_prefix_list_unittest.cc", "//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/rewards/rewards_util_unittest.cc", + "//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_capabilities/get_capabilities_unittest.cc", "//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_card/get_card_unittest.cc", "//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_cards/get_cards_unittest.cc", "//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/uphold/get_me/get_me_unittest.cc",