Skip to content

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

Merged
merged 1 commit into from
May 28, 2019

Conversation

jasonrsadler
Copy link
Contributor

@jasonrsadler jasonrsadler commented May 21, 2019

Fixes brave/brave-browser#4476

Brave-UI: brave/brave-ui#470

Submitter Checklist:

Test Plan:

Regression case:

  1. Start Brave with clean profile.
  2. Enable Rewards and navigate to Rewards page.
  3. Click Add Funds and ensure that all funding currencies are available

Test case:

  1. Start Brave with clean profile using -- --rewards=current-country=JP
  2. Enable Rewards and navigate to Rewards page.
  3. Click Add Funds and ensure that on BAT currency is available

Test case 2:

  1. Start Brave with clean profile using -- --rewards=current-country=US (or replace US with any value other than 'JP')
  2. Enable Rewards and navigate to Rewards page.
  3. Click Add Funds and ensure that all funding currencies are available

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@jasonrsadler jasonrsadler added this to the 0.67.x - Nightly milestone May 21, 2019
@jasonrsadler jasonrsadler self-assigned this May 21, 2019
@jasonrsadler jasonrsadler changed the title Japan installed Rewards not allows for BAT only in Add Funds dialog Japan installed Rewards now allows for BAT only in Add Funds dialog May 21, 2019
@@ -1528,8 +1531,35 @@ void RewardsServiceImpl::GetAddresses(const GetAddressesCallback& callback) {
return;
}

bat_ledger_->GetAddresses(base::BindOnce(&RewardsServiceImpl::OnGetAddresses,
AsWeakPtr(), callback));
bat_ledger_->GetAddressesLimitedCountries(
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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)

Copy link
Contributor Author

@jasonrsadler jasonrsadler May 22, 2019

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.

https://chromium.googlesource.com/chromium/src/+/refs/heads/master/components/country_codes/country_codes.h#35

This is Cr specific and I wouldn't consider "standardized"

Copy link
Contributor Author

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.

Copy link
Contributor

@NejcZdovc NejcZdovc left a 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

data.SetString("ETH", addresses.at("ETH"));
data.SetString("LTC", addresses.at("LTC"));

if (addresses.count("BTC") == 1) {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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))
}

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@brave brave deleted a comment from tmancey May 22, 2019
@brave brave deleted a comment from tmancey May 22, 2019
@brave brave deleted a comment from tmancey May 22, 2019
@brave brave deleted a comment from tmancey May 22, 2019
@brave brave deleted a comment from tmancey May 22, 2019
@brave brave deleted a comment from tmancey May 22, 2019
@brave brave deleted a comment from tmancey May 22, 2019
@brave brave deleted a comment from tmancey May 22, 2019
@brave brave deleted a comment from tmancey May 22, 2019
@brave brave deleted a comment from tmancey May 22, 2019
@jasonrsadler jasonrsadler force-pushed the add-funds-jp branch 2 times, most recently from 1c2a9d4 to 7243084 Compare May 22, 2019 20:07
@jasonrsadler jasonrsadler requested a review from NejcZdovc May 22, 2019 20:09
@jasonrsadler jasonrsadler dismissed NejcZdovc’s stale review May 22, 2019 20:10

Comments addressed

@@ -1527,9 +1530,17 @@ void RewardsServiceImpl::GetAddresses(const GetAddressesCallback& callback) {
if (!Connected()) {
return;
}
int32_t current_country(
Copy link
Contributor

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

Copy link
Contributor Author

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") {
Copy link
Contributor

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,
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jasonrsadler jasonrsadler force-pushed the add-funds-jp branch 2 times, most recently from 04fe4a6 to bf137f3 Compare May 28, 2019 03:12
@jasonrsadler jasonrsadler requested a review from NejcZdovc May 28, 2019 03:13
@@ -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,
Copy link
Contributor

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) {
Copy link
Contributor

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,
Copy link
Contributor

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,
Copy link
Contributor

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,
Copy link
Contributor

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) {
Copy link
Contributor

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,
Copy link
Contributor

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);
Copy link
Contributor

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) =>
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limited_countries -> countries

@jasonrsadler jasonrsadler force-pushed the add-funds-jp branch 2 times, most recently from 79ea1dc to d2fcf32 Compare May 28, 2019 10:32
@jasonrsadler
Copy link
Contributor Author

Comments addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Country specific Add Funds for BR
2 participants