Skip to content

Commit

Permalink
Moves promotions to new endpoint structure
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Aug 17, 2020
1 parent 5775c0e commit aaab482
Show file tree
Hide file tree
Showing 121 changed files with 6,093 additions and 1,760 deletions.
19 changes: 0 additions & 19 deletions components/brave_rewards/browser/android_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,4 @@ ledger::ClientInfoPtr GetAndroidClientInfo() {
return info;
}

std::string ParseClaimPromotionResponse(const std::string& response) {
base::Optional<base::Value> value = base::JSONReader::Read(response);
if (!value || !value->is_dict()) {
return "";
}

base::DictionaryValue* dictionary = nullptr;
if (!value->GetAsDictionary(&dictionary)) {
return "";
}

auto* nonce = dictionary->FindKey("nonce");
if (!nonce || !nonce->is_string()) {
return "";
}

return nonce->GetString();
}

} // namespace android_util
2 changes: 0 additions & 2 deletions components/brave_rewards/browser/android_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace android_util {

ledger::ClientInfoPtr GetAndroidClientInfo();

std::string ParseClaimPromotionResponse(const std::string& response);

} // namespace android_util

#endif // BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_ANDROID_UTIL_H_
3 changes: 1 addition & 2 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1257,13 +1257,12 @@ void RewardsServiceImpl::AttestationAndroid(
const std::string& promotion_id,
AttestPromotionCallback callback,
const ledger::Result result,
const std::string& response) {
const std::string& nonce) {
if (result != ledger::Result::LEDGER_OK) {
std::move(callback).Run(static_cast<int32_t>(result), nullptr);
return;
}

const std::string nonce = android_util::ParseClaimPromotionResponse(response);
if (nonce.empty()) {
std::move(callback).Run(
static_cast<int32_t>(ledger::Result::LEDGER_ERROR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,7 @@ void RewardsBrowserTestResponse::Get(
return;
}

if (URLMatches(
url,
"/wallet/uphold",
PREFIX_V3,
ServerTypes::kPromotion)) {
if (url.find("/v3/wallet/uphold") != std::string::npos) {
if (user_funds_balance_) {
*response = user_funds_balance_resp_;
} else {
Expand All @@ -252,11 +248,7 @@ void RewardsBrowserTestResponse::Get(
return;
}

if (URLMatches(
url,
"/promotions?",
PREFIX_V1,
ServerTypes::kPromotion)) {
if (url.find("v1/promotions?") != std::string::npos) {
if (empty_promotion_key_) {
*response = promotion_empty_key_;
} else {
Expand All @@ -265,11 +257,7 @@ void RewardsBrowserTestResponse::Get(
return;
}

if (URLMatches(
url,
"/promotions/",
PREFIX_V1,
ServerTypes::kPromotion)) {
if (url.find("/v1/promotions") != std::string::npos) {
if (url.find("claims") != std::string::npos) {
*response = creds_tokens_;
} else {
Expand All @@ -278,11 +266,7 @@ void RewardsBrowserTestResponse::Get(
return;
}

if (URLMatches(
url,
"/captchas",
PREFIX_V1,
ServerTypes::kPromotion)) {
if (url.find("/v1/captchas") != std::string::npos) {
*response = captcha_;
}

Expand Down
19 changes: 19 additions & 0 deletions components/brave_rewards/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ source_set("brave_rewards_unit_tests") {
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/publisher/publisher_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/api/api_util_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/api/get_parameters/get_parameters_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_available/get_available_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_captcha/get_captcha_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_signed_creds/get_signed_creds_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/get_wallet_balance/get_wallet_balance_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_bat_loss/post_bat_loss_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_captcha/post_captcha_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_claim_uphold/post_claim_uphold_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_clobbered_claims/post_clobbered_claims_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_creds/post_creds_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_devicecheck/post_devicecheck_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_safetynet/post_safetynet_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_suggestions/post_suggestions_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_suggestions_claim/post_suggestions_claim_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_wallet_brave/post_wallet_brave_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/promotions_util_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/put_captcha/put_captcha_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/put_devicecheck/put_devicecheck_unittest.cc",
"//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/uphold/uphold_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold_util_unittest.cc",
"//brave/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_util_unittest.cc",
Expand Down
50 changes: 40 additions & 10 deletions vendor/bat-native-ledger/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -300,36 +300,66 @@ source_set("ledger") {
"src/bat/ledger/internal/recovery/recovery_empty_balance.h",
"src/bat/ledger/internal/report/report.cc",
"src/bat/ledger/internal/report/report.h",
"src/bat/ledger/internal/request/request_attestation.cc",
"src/bat/ledger/internal/request/request_attestation.h",
"src/bat/ledger/internal/request/request_promotion.cc",
"src/bat/ledger/internal/request/request_promotion.h",
"src/bat/ledger/internal/request/request_publisher.cc",
"src/bat/ledger/internal/request/request_publisher.h",
"src/bat/ledger/internal/request/request_sku.cc",
"src/bat/ledger/internal/request/request_sku.h",
"src/bat/ledger/internal/request/request_util.cc",
"src/bat/ledger/internal/request/request_util.h",
"src/bat/ledger/internal/response/response_attestation.cc",
"src/bat/ledger/internal/response/response_attestation.h",
"src/bat/ledger/internal/response/response_credentials.cc",
"src/bat/ledger/internal/response/response_credentials.h",
"src/bat/ledger/internal/response/response_promotion.cc",
"src/bat/ledger/internal/response/response_promotion.h",
"src/bat/ledger/internal/response/response_publisher.cc",
"src/bat/ledger/internal/response/response_publisher.h",
"src/bat/ledger/internal/response/response_sku.cc",
"src/bat/ledger/internal/response/response_sku.h",
"src/bat/ledger/internal/response/response_uphold.cc",
"src/bat/ledger/internal/response/response_uphold.h",
"src/bat/ledger/internal/response/response_wallet.cc",
"src/bat/ledger/internal/response/response_wallet.h",
"src/bat/ledger/internal/endpoint/api/api_server.cc",
"src/bat/ledger/internal/endpoint/api/api_server.h",
"src/bat/ledger/internal/endpoint/api/api_util.cc",
"src/bat/ledger/internal/endpoint/api/api_util.h",
"src/bat/ledger/internal/endpoint/api/get_parameters/get_parameters.cc",
"src/bat/ledger/internal/endpoint/api/get_parameters/get_parameters.h",
"src/bat/ledger/internal/endpoint/promotion/get_available/get_available.cc",
"src/bat/ledger/internal/endpoint/promotion/get_available/get_available.h",
"src/bat/ledger/internal/endpoint/promotion/get_captcha/get_captcha.cc",
"src/bat/ledger/internal/endpoint/promotion/get_captcha/get_captcha.h",
"src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet.cc",
"src/bat/ledger/internal/endpoint/promotion/get_recover_wallet/get_recover_wallet.h",
"src/bat/ledger/internal/endpoint/promotion/get_signed_creds/get_signed_creds.cc",
"src/bat/ledger/internal/endpoint/promotion/get_signed_creds/get_signed_creds.h",
"src/bat/ledger/internal/endpoint/promotion/get_wallet_balance/get_wallet_balance.cc",
"src/bat/ledger/internal/endpoint/promotion/get_wallet_balance/get_wallet_balance.h",
"src/bat/ledger/internal/endpoint/promotion/post_bat_loss/post_bat_loss.cc",
"src/bat/ledger/internal/endpoint/promotion/post_bat_loss/post_bat_loss.h",
"src/bat/ledger/internal/endpoint/promotion/post_captcha/post_captcha.cc",
"src/bat/ledger/internal/endpoint/promotion/post_captcha/post_captcha.h",
"src/bat/ledger/internal/endpoint/promotion/post_claim_uphold/post_claim_uphold.cc",
"src/bat/ledger/internal/endpoint/promotion/post_claim_uphold/post_claim_uphold.h",
"src/bat/ledger/internal/endpoint/promotion/post_clobbered_claims/post_clobbered_claims.cc",
"src/bat/ledger/internal/endpoint/promotion/post_clobbered_claims/post_clobbered_claims.h",
"src/bat/ledger/internal/endpoint/promotion/post_creds/post_creds.cc",
"src/bat/ledger/internal/endpoint/promotion/post_creds/post_creds.h",
"src/bat/ledger/internal/endpoint/promotion/post_devicecheck/post_devicecheck.cc",
"src/bat/ledger/internal/endpoint/promotion/post_devicecheck/post_devicecheck.h",
"src/bat/ledger/internal/endpoint/promotion/post_safetynet/post_safetynet.cc",
"src/bat/ledger/internal/endpoint/promotion/post_safetynet/post_safetynet.h",
"src/bat/ledger/internal/endpoint/promotion/post_suggestions/post_suggestions.cc",
"src/bat/ledger/internal/endpoint/promotion/post_suggestions/post_suggestions.h",
"src/bat/ledger/internal/endpoint/promotion/post_suggestions_claim/post_suggestions_claim.cc",
"src/bat/ledger/internal/endpoint/promotion/post_suggestions_claim/post_suggestions_claim.h",
"src/bat/ledger/internal/endpoint/promotion/post_wallet_brave/post_wallet_brave.cc",
"src/bat/ledger/internal/endpoint/promotion/post_wallet_brave/post_wallet_brave.h",
"src/bat/ledger/internal/endpoint/promotion/promotion_server.cc",
"src/bat/ledger/internal/endpoint/promotion/promotion_server.h",
"src/bat/ledger/internal/endpoint/promotion/promotions_util.cc",
"src/bat/ledger/internal/endpoint/promotion/promotions_util.h",
"src/bat/ledger/internal/endpoint/promotion/put_captcha/put_captcha.cc",
"src/bat/ledger/internal/endpoint/promotion/put_captcha/put_captcha.h",
"src/bat/ledger/internal/endpoint/promotion/put_devicecheck/put_devicecheck.cc",
"src/bat/ledger/internal/endpoint/promotion/put_devicecheck/put_devicecheck.h",
"src/bat/ledger/internal/endpoint/promotion/put_safetynet/put_safetynet.cc",
"src/bat/ledger/internal/endpoint/promotion/put_safetynet/put_safetynet.h",
"src/bat/ledger/internal/sku/sku.h",
"src/bat/ledger/internal/sku/sku_brave.cc",
"src/bat/ledger/internal/sku/sku_brave.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
#include "bat/ledger/internal/attestation/attestation.h"
#include "bat/ledger/internal/ledger_impl.h"

namespace braveledger_attestation {
namespace ledger {
namespace attestation {

Attestation::Attestation(bat_ledger::LedgerImpl* ledger) : ledger_(ledger) {
}

Attestation::~Attestation() = default;

} // namespace braveledger_attestation
} // namespace attestation
} // namespace ledger
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace bat_ledger {
class LedgerImpl;
}

namespace braveledger_attestation {
namespace ledger {
namespace attestation {

using StartCallback =
std::function<void(const ledger::Result, const std::string&)>;
Expand All @@ -38,5 +39,6 @@ class Attestation {
bat_ledger::LedgerImpl* ledger_; // NOT OWNED
};

} // namespace braveledger_attestation
} // namespace attestation
} // namespace ledger
#endif // BRAVELEDGER_ATTESTATION_ATTESTATION_H_
Loading

0 comments on commit aaab482

Please sign in to comment.