-
Notifications
You must be signed in to change notification settings - Fork 965
Japan installed Rewards now allows for BAT only in Add Funds dialog #2470
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
Conversation
@@ -1528,8 +1531,35 @@ void RewardsServiceImpl::GetAddresses(const GetAddressesCallback& callback) { | |||
return; | |||
} | |||
|
|||
bat_ledger_->GetAddresses(base::BindOnce(&RewardsServiceImpl::OnGetAddresses, | |||
AsWeakPtr(), callback)); | |||
bat_ledger_->GetAddressesLimitedCountries( |
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.
This logic needs to be moved to ledger code.
So what should happen is that we send country code to ledger and ledger return addresses. Rewards service doesn't need to know about limitations. We shouldn't have business logic in here.
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 agree but I wasn't sure if I should call country_codes::CountryCharsToCountryID in 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.
So instead, I'll move to ledger and make the call to country_codes::CountryCharsToCountryID
through LedgerClient
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.
what I would do is just pass country into GetAddresses
function so that ledger can know what is your current country and then ledger can take it from there
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.
this way ledger don't need to do another call out
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.
What's happening here is the call to country_codes::GetCountryIdFromPrefs
and country_codes::CountryCharsToCountryID
take the characters and packs them into an integer (US is something like 20154
JP is something like 19345
) and the current country ID (5 digit number) is what is stored in prefs. So to get the comparison, we have to do another call out to get the ID to 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.
we could send in country ID and instead of storing JP in ledger we store ID (which is ISO 3166-1 country code)
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.
No, the ISO 3166-1 code is a 3 digit code.
The code that Cr is storing in prefs is a code that is converted and packed based off of the alpha-2 code received. The result is a 5 digit code.
This is Cr specific and I wouldn't consider "standardized"
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.
Logic is moved to Ledger. There is a callout to LedgerClient to get the Cr specific country code from the alpha-2 chars.
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.
we need to move logic in ledger
browser/ui/webui/brave_rewards_ui.cc
Outdated
data.SetString("ETH", addresses.at("ETH")); | ||
data.SetString("LTC", addresses.at("LTC")); | ||
|
||
if (addresses.count("BTC") == 1) { |
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.
could we just iterate through addresses
map, so that we don't have if
's
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.
But we have hardcoded strings and wouldn't necessarily know which iteration gets set with which 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.
for (auto& address : addresses) {
data.SetString(address.first, address.second);
}
I was thinking something like this
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.
Ok. That works but FYI SetString
is deprecated.
using:
base::Value data(base::Value::Type::DICTIONARY);
for (auto& address : addresses) {
data.SetKey(address.first, base::Value(address.second))
}
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.
yeah I just copied what we have in the code now :) great
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.
Done.
1c2a9d4
to
7243084
Compare
7243084
to
f9ebe3f
Compare
4c7ec97
to
5aa4c60
Compare
@@ -1527,9 +1530,17 @@ void RewardsServiceImpl::GetAddresses(const GetAddressesCallback& callback) { | |||
if (!Connected()) { | |||
return; | |||
} | |||
int32_t current_country( |
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: could you please do int32_t current_country = country_codes::GetCountryIDFromPrefs(profile_->GetPrefs())
as it's a lot easier to read
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.
Done.
@@ -2624,6 +2635,13 @@ void RewardsServiceImpl::HandleFlags(const std::string& options) { | |||
|
|||
SetShortRetries(short_retries); | |||
} | |||
|
|||
if (name == "current-country") { |
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.
nice one 👍
@@ -222,6 +224,10 @@ class LEDGER_EXPORT LedgerClient { | |||
|
|||
virtual void GetExcludedPublishersNumberDB( | |||
ledger::GetExcludedPublishersNumberDBCallback callback) = 0; | |||
|
|||
virtual void GetCountryCodes( | |||
const std::vector<std::string>& limited_countries, |
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.
Maybe more general param? Like countries
, as this function could be used by other functions as well, where we wouldn't passing limited countries in
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.
Done.
04fe4a6
to
bf137f3
Compare
@@ -505,6 +506,9 @@ class RewardsServiceImpl : public RewardsService, | |||
void OnTwitterPublisherInfoSaved(SaveMediaInfoCallback callback, | |||
int32_t result, | |||
ledger::PublisherInfoPtr publisher); | |||
void GetCountryCodes( | |||
const std::vector<std::string>& limited_countries, |
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.
limited_countries
-> countries
@@ -96,6 +96,13 @@ void OnExcludedNumberDB( | |||
callback(result); | |||
} | |||
|
|||
void OnGetCountryCodes( | |||
const ledger::GetCountryCodesCallback& callback, | |||
const std::vector<int32_t>& limited_countries) { |
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.
limited_countries
-> countries
@@ -728,4 +735,15 @@ void BatLedgerClientMojoProxy::GetExcludedPublishersNumberDB( | |||
base::BindOnce(&OnExcludedNumberDB, std::move(callback))); | |||
} | |||
|
|||
void BatLedgerClientMojoProxy::GetCountryCodes( | |||
const std::vector<std::string>& limited_countries, |
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.
limited_countries
-> countries
@@ -140,6 +140,10 @@ class BatLedgerClientMojoProxy : public ledger::LedgerClient, | |||
void GetExcludedPublishersNumberDB( | |||
ledger::GetExcludedPublishersNumberDBCallback callback) override; | |||
|
|||
void GetCountryCodes( | |||
const std::vector<std::string>& limited_countries, |
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.
limited_countries
-> countries
} | ||
|
||
void LedgerClientMojoProxy::GetCountryCodes( | ||
const std::vector<std::string>& limited_countries, |
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.
limited_countries
-> countries
// static | ||
void LedgerClientMojoProxy::OnGetCountryCodes( | ||
CallbackHolder<GetCountryCodesCallback>* holder, | ||
const std::vector<int32_t>& limited_countries) { |
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.
limited_countries
-> countries
@@ -127,6 +127,10 @@ class LedgerClientMojoProxy : public mojom::BatLedgerClient, | |||
void GetExcludedPublishersNumberDB( | |||
GetExcludedPublishersNumberDBCallback callback) override; | |||
|
|||
void GetCountryCodes( | |||
const std::vector<std::string>& limited_countries, |
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.
limited_countries
-> countries
@@ -240,6 +244,10 @@ class LedgerClientMojoProxy : public mojom::BatLedgerClient, | |||
ledger::PublisherInfoList publisher_info_list, | |||
uint32_t next_record); | |||
|
|||
static void OnGetCountryCodes( | |||
CallbackHolder<GetCountryCodesCallback>* holder, | |||
const std::vector<int32_t>& limited_countries); |
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.
limited_countries
-> countries
@@ -212,4 +212,6 @@ interface BatLedgerClient { | |||
ConfirmationsTransactionHistoryDidChange(); | |||
|
|||
GetExcludedPublishersNumberDB() => (uint32 number); | |||
GetCountryCodes(array<string> limited_countries) => |
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.
limited_countries
-> countries
@@ -247,6 +247,10 @@ class MockConfirmationsClient : public ConfirmationsClient { | |||
|
|||
MOCK_METHOD1(GetExcludedPublishersNumberDB, void( | |||
ledger::GetExcludedPublishersNumberDBCallback callback)); | |||
|
|||
MOCK_METHOD2(GetCountryCodes, void( | |||
const std::vector<std::string>& limited_countries, |
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.
limited_countries
-> countries
79ea1dc
to
d2fcf32
Compare
Comments addressed |
d2fcf32
to
2b99ba8
Compare
2b99ba8
to
767deaf
Compare
Fixes brave/brave-browser#4476
Brave-UI: brave/brave-ui#470
Submitter Checklist:
npm test brave_unit_tests && npm test brave_browser_tests && npm run test-security
) onnpm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
Regression case:
Test case:
-- --rewards=current-country=JP
Test case 2:
-- --rewards=current-country=US
(or replace US with any value other than 'JP')Reviewer Checklist:
After-merge Checklist:
changes has landed on.