diff --git a/include/bat/ledger/ledger_callback_handler.h b/include/bat/ledger/ledger_callback_handler.h index c10d981590e3..a693ba9d8c3a 100644 --- a/include/bat/ledger/ledger_callback_handler.h +++ b/include/bat/ledger/ledger_callback_handler.h @@ -18,6 +18,7 @@ LEDGER_EXPORT enum Result { NO_LEDGER_STATE = 3, INVALID_PUBLISHER_STATE = 4, INVALID_LEDGER_STATE = 5, + CAPTCHA_FAILED = 6, // some more useful result codes should go here }; diff --git a/include/bat/ledger/ledger_client.h b/include/bat/ledger/ledger_client.h index 5a8b36e8c0e6..11ad22783630 100644 --- a/include/bat/ledger/ledger_client.h +++ b/include/bat/ledger/ledger_client.h @@ -64,7 +64,7 @@ class LEDGER_EXPORT LedgerClient { virtual void GetGrantCaptcha() = 0; virtual void OnGrantCaptcha(const std::string& image) = 0; virtual void OnRecoverWallet(Result result, double balance, std::vector grants) = 0; - virtual void OnGrantFinish(ledger::Result result, unsigned int statusCode, uint64_t experationDate) = 0; + virtual void OnGrantFinish(ledger::Result result, ledger::Grant grant) = 0; virtual std::string URIEncode(const std::string& value) = 0; diff --git a/src/bat_client.cc b/src/bat_client.cc index 528d3fff85db..c37bd572269d 100644 --- a/src/bat_client.cc +++ b/src/bat_client.cc @@ -1003,7 +1003,8 @@ void BatClient::getGrantCallback(bool success, const std::string& response) { void BatClient::setGrant(const std::string& captchaResponse, const std::string& promotionId) { if (promotionId.empty() && state_->grant_.promotionId.empty()) { - ledger_->OnGrantFinish(ledger::Result::ERROR, 400, 0); + braveledger_bat_helper::GRANT properties; + ledger_->OnGrantFinish(ledger::Result::ERROR, properties); return; } @@ -1034,21 +1035,28 @@ void BatClient::setGrantCallback(bool success, const std::string& response) { std::string error; unsigned int statusCode; + braveledger_bat_helper::GRANT grant; braveledger_bat_helper::getJSONResponse(response, statusCode, error); if (!success) { - ledger_->OnGrantFinish(ledger::Result::ERROR, statusCode, 0); + if (statusCode == 422) { + ledger_->OnGrantFinish(ledger::Result::CAPTCHA_FAILED, grant); + } else { + ledger_->OnGrantFinish(ledger::Result::ERROR, grant); + } return; } - uint64_t expiryTime; - bool ok = braveledger_bat_helper::getJSONGrant(response, expiryTime); + bool ok = braveledger_bat_helper::loadFromJson(grant, response); if (!ok) { - ledger_->OnGrantFinish(ledger::Result::ERROR, 400, 0); + ledger_->OnGrantFinish(ledger::Result::ERROR, grant); return; } - ledger_->OnGrantFinish(ledger::Result::OK, statusCode, expiryTime); + grant.promotionId = state_->grant_.promotionId; + state_->grant_ = grant; + + ledger_->OnGrantFinish(ledger::Result::OK, grant); } void BatClient::getGrantCaptcha() { diff --git a/src/bat_helper.h b/src/bat_helper.h index e754f2f4e45c..85ec62a8c701 100644 --- a/src/bat_helper.h +++ b/src/bat_helper.h @@ -341,8 +341,6 @@ namespace braveledger_bat_helper { bool getJSONResponse(const std::string& json, unsigned int& statusCode, std::string& error); - bool getJSONGrant(const std::string& json, uint64_t& expiryTime); - std::vector generateSeed(); std::vector getHKDF(const std::vector& seed); diff --git a/src/ledger_impl.cc b/src/ledger_impl.cc index 6a9a575bb698..8cad3de2f3f3 100644 --- a/src/ledger_impl.cc +++ b/src/ledger_impl.cc @@ -441,8 +441,14 @@ void LedgerImpl::SolveGrantCaptcha(const std::string& solution) const { bat_client_->setGrant(solution, ""); } -void LedgerImpl::OnGrantFinish(ledger::Result result, unsigned int statusCode, uint64_t experationDate) { - ledger_client_->OnGrantFinish(result, statusCode, experationDate); +void LedgerImpl::OnGrantFinish(ledger::Result result, braveledger_bat_helper::GRANT grant) { + ledger::Grant newGrant; + + newGrant.altcurrency = grant.altcurrency; + newGrant.probi = grant.probi; + newGrant.expiryTime = grant.expiryTime; + + ledger_client_->OnGrantFinish(result, newGrant); } } // namespace bat_ledger diff --git a/src/ledger_impl.h b/src/ledger_impl.h index a4975a246858..0c084000357f 100644 --- a/src/ledger_impl.h +++ b/src/ledger_impl.h @@ -89,7 +89,7 @@ class LedgerImpl : public ledger::Ledger, void OnGrantCaptcha(const std::string& image); void SolveGrantCaptcha(const std::string& solution) const override; - void OnGrantFinish(ledger::Result result, unsigned int statusCode, uint64_t expiryTime); + void OnGrantFinish(ledger::Result result, braveledger_bat_helper::GRANT grant); std::string GetWalletPassphrase() const override; void RecoverWallet(const std::string& passPhrase) const override;