Skip to content

Commit

Permalink
Fixed grant type for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
samartnik committed Aug 28, 2019
1 parent 398911a commit b690109
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,11 @@ void RewardsNotificationServiceImpl::OnGetAllNotifications(
}

bool RewardsNotificationServiceImpl::IsUGPGrant(const std::string& grant_type) {
return (grant_type == "ugp");
#if defined(OS_ANDROID)
return (grant_type == "android");
#else
return (grant_type == "ugp");
#endif
}

std::string RewardsNotificationServiceImpl::GetGrantIdPrefix(
Expand Down
2 changes: 1 addition & 1 deletion components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3691,7 +3691,7 @@ void RewardsServiceImpl::OnGrantViaSafetynetCheck(const std::string& promotion_i
void RewardsServiceImpl::GrantAttestationResult(const std::string& promotion_id, bool result,
const std::string& result_string) {
if (result) {
return bat_ledger_->ApplySafetynetToken(result_string);
return bat_ledger_->ApplySafetynetToken(promotion_id, result_string);
} else {
LOG(ERROR) << "GrantAttestationResult error: " << result_string;
TriggerOnGrantFinish(ledger::Result::SAFETYNET_ATTESTATION_FAILED, nullptr);
Expand Down
4 changes: 2 additions & 2 deletions components/services/bat_ledger/bat_ledger_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ void BatLedgerImpl::GetGrantViaSafetynetCheck(const std::string& promotion_id) {
ledger_->GetGrantViaSafetynetCheck(promotion_id);
}

void BatLedgerImpl::ApplySafetynetToken(const std::string& result_string) {
ledger_->ApplySafetynetToken(result_string);
void BatLedgerImpl::ApplySafetynetToken(const std::string& promotion_id, const std::string& result_string) {
ledger_->ApplySafetynetToken(promotion_id, result_string);
}


Expand Down
2 changes: 1 addition & 1 deletion components/services/bat_ledger/bat_ledger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class BatLedgerImpl : public mojom::BatLedger,
HasSufficientBalanceToReconcileCallback callback) override;

void GetGrantViaSafetynetCheck(const std::string& promotion_id) override;
void ApplySafetynetToken(const std::string& result_string) override;
void ApplySafetynetToken(const std::string& promotion_id, const std::string& result_string) override;

void GetTransactionHistory(
GetTransactionHistoryCallback callback) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface BatLedger {
SolveGrantCaptcha(string solution, string promotionId);

GetGrantViaSafetynetCheck(string promotion_id);
ApplySafetynetToken(string result_string);
ApplySafetynetToken(string promotion_id, string result_string);

SetRewardsMainEnabled(bool enabled);
SetPublisherMinVisitTime(uint64 duration_in_seconds);
Expand Down
3 changes: 2 additions & 1 deletion vendor/bat-native-ledger/include/bat/ledger/ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ class LEDGER_EXPORT Ledger {
const std::vector<std::string>& headers,
GetGrantCaptchaCallback callback) const = 0;

virtual void ApplySafetynetToken(const std::string& token) const = 0;
virtual void ApplySafetynetToken(const std::string& promotion_id,
const std::string& token) const = 0;

virtual void GetGrantViaSafetynetCheck(const std::string& promotion_id) const = 0;

Expand Down
21 changes: 12 additions & 9 deletions vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1017,15 +1017,11 @@ GRANT::GRANT(const GRANT &properties) {
type = properties.type;
}

bool GRANT::loadFromJsonSafetyNet(const std::string& json) {
return loadFromJsonInternal(json, true);
}

bool GRANT::loadFromJson(const std::string & json) {
return loadFromJsonInternal(json, false);
return loadFromJsonInternal(json);
}

bool GRANT::loadFromJsonInternal(const std::string& json, bool is_safetynet_check) {
bool GRANT::loadFromJsonInternal(const std::string& json) {
rapidjson::Document d;
d.Parse(json.c_str());

Expand All @@ -1041,24 +1037,31 @@ bool GRANT::loadFromJsonInternal(const std::string& json, bool is_safetynet_chec

if (!error) {
promotionId = d["promotionId"].GetString();

if (d.HasMember("type") && d["type"].IsString()){
type = d["type"].GetString();
}
return !error;
}

// On successful grant
error = !(
d.HasMember("altcurrency") && d["altcurrency"].IsString() &&
d.HasMember("expiryTime") && d["expiryTime"].IsNumber() &&
d.HasMember("probi") && d["probi"].IsString() &&
(is_safetynet_check || (d.HasMember("type") && d["type"].IsString())));
d.HasMember("probi") && d["probi"].IsString());

if (!error) {
altcurrency = d["altcurrency"].GetString();
expiryTime = d["expiryTime"].GetUint64();
probi = d["probi"].GetString();
if (!is_safetynet_check) {
if (d.HasMember("type") && d["type"].IsString()) {
type = d["type"].GetString();
} else {
#if defined(OS_ANDROID)
type = "android";
#else
type = "ugp";
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,13 @@ struct GRANT {

// load from json string
bool loadFromJson(const std::string & json);
bool loadFromJsonSafetyNet(const std::string& json);
std::string altcurrency;
std::string probi;
uint64_t expiryTime;
std::string promotionId;
std::string type;
private:
bool loadFromJsonInternal(const std::string& json, bool is_safetynet_check);
bool loadFromJsonInternal(const std::string& json);
};

struct GRANT_RESPONSE {
Expand Down
2 changes: 1 addition & 1 deletion vendor/bat-native-ledger/src/bat/ledger/internal/grants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void Grants::FetchGrants(const std::string& lang,
ledger_->OnWalletProperties(ledger::Result::CORRUPTED_WALLET, properties);
return;
}

std::string paymentId = forPaymentId;
if (paymentId.empty()) {
paymentId = ledger_->GetPaymentId();
Expand Down Expand Up @@ -139,7 +140,6 @@ void Grants::GetGrantsCallback(
braveledger_bat_helper::GRANT grant_;
grant_.promotionId = grant.promotionId;
grant_.type = grant.type;

grants.push_back(grant_);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1784,8 +1784,8 @@ void LedgerImpl::OnGrantViaSafetynetCheck(const std::string& promotion_id, const
ledger_client_->OnGrantViaSafetynetCheck(promotion_id, nonce);
}

void LedgerImpl::ApplySafetynetToken(const std::string& token) const {
bat_grants_->SetGrant("", "", token);
void LedgerImpl::ApplySafetynetToken(const std::string& promotion_id, const std::string& token) const {
bat_grants_->SetGrant("", promotion_id, token);
}

} // namespace bat_ledger
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class LedgerImpl : public ledger::Ledger,
void SolveGrantCaptcha(const std::string& solution,
const std::string& promotionId) const override;

void ApplySafetynetToken(const std::string& token) const override;
void ApplySafetynetToken(const std::string& promotion_id, const std::string& token) const override;

void OnGrantFinish(ledger::Result result,
const braveledger_bat_helper::GRANT& grant);
Expand Down

0 comments on commit b690109

Please # to comment.