-
Notifications
You must be signed in to change notification settings - Fork 879
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
Refactor GetGrantCaptcha to use callback #2940
Conversation
8e1a775
to
307dc13
Compare
} | ||
|
||
- (void)onGrantCaptcha:(const std::string &)image hint:(const std::string &)hint | ||
{ | ||
if (self.grantCaptchaBlock) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can delete the grantCaptchaBlock
@Property definition now that its no longer used.
Also can you just add a comment here saying this is unused, better than fully empty I guess 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
ledger->GetGrantCaptcha(headers); | ||
ledger->GetGrantCaptcha(headers, | ||
^(const std::string &image, const std::string &hint) { | ||
completion([NSString stringWithUTF8String:image.c_str()], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is grant captcha doing an asynchronous network call? I can't recall, but if it is, can we wrap this completion block in a dispatch_async
to main thread as seen in other callbacks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
13be142
to
8584882
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few comments.
// static | ||
void BatLedgerImpl::OnGetGrantCaptcha( | ||
CallbackHolder<GetGrantCaptchaCallback>* holder, | ||
std::string image, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make image
and hint
const reference parameters, e.g., const std::string& image
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -63,7 +63,7 @@ interface BatLedger { | |||
int32 month, int32 year, uint32 data); | |||
|
|||
FetchGrants(string lang, string payment_id); | |||
GetGrantCaptcha(array<string> headers); | |||
GetGrantCaptcha(array<string> headers) =>(string image, string hint); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Should have a space after the arrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -50,6 +50,8 @@ using GetAddressesCallback = | |||
using HasSufficientBalanceToReconcileCallback = std::function<void(bool)>; | |||
using FetchBalanceCallback = std::function<void(ledger::Result, | |||
ledger::BalancePtr)>; | |||
using GetGrantCaptchaCallback = std::function<void(std::string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above: let's use const std::string&
for these parameters if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
bat_grants_->GetGrantCaptcha(headers); | ||
const std::vector<std::string>& headers, | ||
ledger::GetGrantCaptchaCallback callback) const { | ||
bat_grants_->GetGrantCaptcha(headers, std::move(callback)); | ||
} | ||
|
||
void LedgerImpl::OnGrantCaptcha(const std::string& image, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove it as it's not needed anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
8584882
to
3523a01
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
||
void LedgerImpl::OnGrantCaptcha(const std::string& image, | ||
const std::string& hint) { | ||
ledger_client_->OnGrantCaptcha(image, hint); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this removed from ledger_client.h
and then all other places. Do we use it somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OnGrantCaptcha is the callback I am passing down from rewards_service to ledger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ledger_client.h check
3523a01
to
d602fc4
Compare
@@ -1402,7 +1402,8 @@ void RewardsServiceImpl::GetGrantCaptcha( | |||
headers.push_back("brave-product:brave-core"); | |||
headers.push_back("promotion-id:" + promotion_id); | |||
headers.push_back("promotion-type:" + promotion_type); | |||
bat_ledger_->GetGrantCaptcha(headers); | |||
bat_ledger_->GetGrantCaptcha(headers, | |||
base::BindOnce(&RewardsServiceImpl::OnGrantCaptcha, AsWeakPtr())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OnGrantCaptcha used here
93b04ff
to
bf52714
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ios++
884d028
to
f251b28
Compare
f251b28
to
6393375
Compare
Resolves brave/brave-browser#5140
Submitter Checklist:
npm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
Reviewer Checklist:
After-merge Checklist:
changes has landed on.