Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID and Type are now sent with request headers on grant fetch #1911

Merged
merged 1 commit into from Mar 15, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -151,11 +151,14 @@ BraveRewardsGetGrantCaptchaFunction::~BraveRewardsGetGrantCaptchaFunction() {
}

ExtensionFunction::ResponseAction BraveRewardsGetGrantCaptchaFunction::Run() {
std::unique_ptr<brave_rewards::GetGrantCaptcha::Params> params(
brave_rewards::GetGrantCaptcha::Params::Create(*args_));
Profile* profile = Profile::FromBrowserContext(browser_context());
RewardsService* rewards_service =
RewardsServiceFactory::GetForProfile(profile);
if (rewards_service) {
rewards_service->GetGrantCaptcha();
rewards_service->GetGrantCaptcha(params->promotion_id,
params->type);
}
return RespondNow(NoArguments());
}
@@ -483,7 +483,11 @@ void RewardsDOMHandler::OnGrantCaptcha(

void RewardsDOMHandler::GetGrantCaptcha(const base::ListValue* args) {
if (rewards_service_) {
rewards_service_->GetGrantCaptcha();
std::string promotion_id;
std::string promotion_type;
args->GetString(0, &promotion_id);
args->GetString(1, &promotion_type);
rewards_service_->GetGrantCaptcha(promotion_id, promotion_type);
}
}

@@ -371,7 +371,16 @@
"name": "getGrantCaptcha",
"type": "function",
"description": "Retrieves grant captcha data",
"parameters": []
"parameters": [
{
"name": "promotionId",
"type": "string"
},
{
"name": "type",
"type": "string"
}
]
},
{
"name": "solveGrantCaptcha",
@@ -89,7 +89,9 @@ class RewardsService : public KeyedService {
const GetContentSiteListCallback& callback) = 0;
virtual void FetchGrants(const std::string& lang,
const std::string& paymentId) = 0;
virtual void GetGrantCaptcha() = 0;
virtual void GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) = 0;
virtual void SolveGrantCaptcha(const std::string& solution,
const std::string& promotionId) const = 0;
virtual void GetWalletPassphrase(
@@ -1315,12 +1315,14 @@ void RewardsServiceImpl::TriggerOnGrant(ledger::Result result,
observer.OnGrant(this, result, properties);
}

void RewardsServiceImpl::GetGrantCaptcha() {
void RewardsServiceImpl::GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) {
if (!Connected()) {
return;
}

bat_ledger_->GetGrantCaptcha();
bat_ledger_->GetGrantCaptcha(promotion_id, promotion_type);
}

void RewardsServiceImpl::TriggerOnGrantCaptcha(const std::string& image,
@@ -86,7 +86,9 @@ class RewardsServiceImpl : public RewardsService,
void FetchWalletProperties() override;
void FetchGrants(const std::string& lang,
const std::string& paymentId) override;
void GetGrantCaptcha() override;
void GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) override;
void SolveGrantCaptcha(const std::string& solution,
const std::string& promotionId) const override;
void GetWalletPassphrase(
@@ -72,7 +72,9 @@ export const grantPanelReducer = (state: RewardsExtension.State | undefined, act
}

state.currentGrant = currentGrant
chrome.braveRewards.getGrantCaptcha()
if (currentGrant.promotionId && currentGrant.type) {
chrome.braveRewards.getGrantCaptcha(currentGrant.promotionId, currentGrant.type)
}
break
case types.ON_GRANT_CAPTCHA: {
if (state.currentGrant && state.grants) {
@@ -186,7 +188,9 @@ export const grantPanelReducer = (state: RewardsExtension.State | undefined, act
break
case 6:
currentGrant.status = 'wrongPosition'
chrome.braveRewards.getGrantCaptcha()
if (currentGrant.promotionId && currentGrant.type) {
chrome.braveRewards.getGrantCaptcha(currentGrant.promotionId, currentGrant.type)
}
break
case 13:
currentGrant.status = 'grantGone'
@@ -71,7 +71,9 @@ const grantReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
}

state.currentGrant = currentGrant
chrome.send('brave_rewards.getGrantCaptcha', [])
if (currentGrant.promotionId && currentGrant.type) {
chrome.send('brave_rewards.getGrantCaptcha', [currentGrant.promotionId, currentGrant.type])
}
break
case types.ON_GRANT_CAPTCHA: {
if (state.currentGrant && state.grants) {
@@ -187,7 +189,9 @@ const grantReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
break
case 6:
newGrant.status = 'wrongPosition'
chrome.send('brave_rewards.getGrantCaptcha', [])
if (state.currentGrant.promotionId && state.currentGrant.type) {
chrome.send('brave_rewards.getGrantCaptcha', [state.currentGrant.promotionId, state.currentGrant.type])
}
break
case 13:
newGrant.status = 'grantGone'
@@ -41,7 +41,7 @@ declare namespace chrome.braveRewards {
}
const includeInAutoContribution: (publisherKey: string, excluded: boolean) => {}
const getGrants: () => {}
const getGrantCaptcha: () => {}
const getGrantCaptcha: (promotionId: string, type: string) => {}
const solveGrantCaptcha: (solution: string, promotionId: string) => {}
const getPendingContributionsTotal: (callback: (amount: number) => void) => {}
const getNonVerifiedSettings: (callback: (nonVerified: boolean) => void) => {}
@@ -567,11 +567,13 @@ void BatLedgerClientMojoProxy::FetchGrants(const std::string& lang,
bat_ledger_client_->FetchGrants(lang, paymentId);
}

void BatLedgerClientMojoProxy::GetGrantCaptcha() {
void BatLedgerClientMojoProxy::GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) {
if (!Connected())
return;

bat_ledger_client_->GetGrantCaptcha();
bat_ledger_client_->GetGrantCaptcha(promotion_id, promotion_type);
}

std::string BatLedgerClientMojoProxy::URIEncode(const std::string& value) {
@@ -101,7 +101,9 @@ class BatLedgerClientMojoProxy : public ledger::LedgerClient,
void FetchWalletProperties() override;
void FetchGrants(const std::string& lang,
const std::string& payment_id) override;
void GetGrantCaptcha() override;
void GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) override;

std::string URIEncode(const std::string& value) override;

@@ -178,8 +178,10 @@ void BatLedgerImpl::FetchGrants(const std::string& lang,
ledger_->FetchGrants(lang, payment_id);
}

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

void BatLedgerImpl::GetWalletPassphrase(GetWalletPassphraseCallback callback) {
@@ -73,7 +73,9 @@ class BatLedgerImpl : public mojom::BatLedger,

void FetchGrants(
const std::string& lang, const std::string& payment_id) override;
void GetGrantCaptcha() override;
void GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) override;
void GetWalletPassphrase(GetWalletPassphraseCallback callback) override;
void GetExcludedPublishersNumber(GetExcludedPublishersNumberCallback callback) override;
void RecoverWallet(const std::string& passPhrase) override;
@@ -453,8 +453,10 @@ void LedgerClientMojoProxy::FetchGrants(const std::string& lang,
ledger_client_->FetchGrants(lang, payment_id);
}

void LedgerClientMojoProxy::GetGrantCaptcha() {
ledger_client_->GetGrantCaptcha();
void LedgerClientMojoProxy::GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) {
ledger_client_->GetGrantCaptcha(promotion_id, promotion_type);
}

void LedgerClientMojoProxy::URIEncode(const std::string& value,
@@ -78,7 +78,9 @@ class LedgerClientMojoProxy : public mojom::BatLedgerClient,
void FetchWalletProperties() override;
void FetchGrants(const std::string& lang,
const std::string& payment_id) override;
void GetGrantCaptcha() override;
void GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) override;

void URIEncode(const std::string& value,
URIEncodeCallback callback) override;
@@ -53,7 +53,7 @@ interface BatLedger {
int32 month, int32 year, uint32 data);

FetchGrants(string lang, string payment_id);
GetGrantCaptcha();
GetGrantCaptcha(string promotion_id, string promotion_type);
GetWalletPassphrase() => (string wallet_passphrase);
GetExcludedPublishersNumber() => (uint32 num_excluded_sites);
RecoverWallet(string passPhrase);
@@ -152,7 +152,7 @@ interface BatLedgerClient {
SaveMediaPublisherInfo(string media_key, string publisher_id);
FetchWalletProperties();
FetchGrants(string lang, string payment_id);
GetGrantCaptcha();
GetGrantCaptcha(string promotion_id, string promotion_type);

[Sync]
URIEncode(string value) => (string encoded_value);
@@ -205,7 +205,9 @@ class LEDGER_EXPORT Ledger {
virtual void SolveGrantCaptcha(const std::string& solution,
const std::string& promotionId) const = 0;

virtual void GetGrantCaptcha() const = 0;
virtual void GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) const = 0;

virtual std::string GetWalletPassphrase() const = 0;

@@ -136,7 +136,9 @@ class LEDGER_EXPORT LedgerClient {
const std::string& paymentId) = 0;
virtual void OnGrant(ledger::Result result, const ledger::Grant& grant) = 0;

virtual void GetGrantCaptcha() = 0;
virtual void GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) = 0;

virtual void OnGrantCaptcha(const std::string& image,
const std::string& hint) = 0;
@@ -586,9 +586,13 @@ void BatClient::setGrantCallback(
ledger_->SetGrants(updated_grants);
}

void BatClient::getGrantCaptcha() {
void BatClient::getGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) {
std::vector<std::string> headers;
headers.push_back("brave-product:brave-core");
headers.push_back("promotion-id:" + promotion_id);
headers.push_back("promotion-type:" + promotion_type);
auto callback = std::bind(&BatClient::getGrantCaptchaCallback,
this,
_1,
@@ -52,7 +52,9 @@ class BatClient {
void setGrant(const std::string& captchaResponse,
const std::string& promotionId);

void getGrantCaptcha();
void getGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type);

void getWalletProperties();

@@ -624,8 +624,10 @@ void LedgerImpl::OnGrant(ledger::Result result,
ledger_client_->OnGrant(result, grant);
}

void LedgerImpl::GetGrantCaptcha() const {
bat_client_->getGrantCaptcha();
void LedgerImpl::GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) const {
bat_client_->getGrantCaptcha(promotion_id, promotion_type);
}

void LedgerImpl::OnGrantCaptcha(const std::string& image,
@@ -192,7 +192,9 @@ class LedgerImpl : public ledger::Ledger,
void OnGrant(ledger::Result result,
const braveledger_bat_helper::GRANT& grant);

void GetGrantCaptcha() const override;
void GetGrantCaptcha(
const std::string& promotion_id,
const std::string& promotion_type) const override;

void OnGrantCaptcha(const std::string& image, const std::string& hint);

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.