Skip to content

Commit

Permalink
Importer now sets the values read from session-store-1
Browse files Browse the repository at this point in the history
  • Loading branch information
bsclifton committed Nov 9, 2018
1 parent ffd5f9c commit 11a722b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
10 changes: 8 additions & 2 deletions browser/importer/brave_profile_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ void BraveProfileWriter::UpdateLedger(const BraveLedger& ledger) {
return;
}

// TODO: set the values that were read in the importer
// ...
// Set the preferences read from session-store-1
auto* payments = &ledger.settings.payments;
rewards_service->SetPublisherAllowVideos(payments->allow_media_publishers);
rewards_service->SetPublisherAllowNonVerified(payments->allow_non_verified);
rewards_service->SetAutoContribute(payments->enabled);
rewards_service->SetContributionAmount(payments->contribution_amount);
rewards_service->SetPublisherMinVisitTime(payments->min_visit_time);
rewards_service->SetPublisherMinVisits(payments->min_visits);

// TODO: register observer which can handle the work
// that needs to happen AFTER RecoverWallet (StuffThatHappensAfterRecover)
Expand Down
4 changes: 2 additions & 2 deletions common/importer/brave_ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ struct BraveLedger {
bool allow_media_publishers;
bool allow_non_verified;
bool enabled;
uint64_t min_publisher_duration;
unsigned int contribution_amount;
double contribution_amount;
uint64_t min_visit_time;
unsigned int min_visits;
} payments;
} settings;
Expand Down
39 changes: 15 additions & 24 deletions utility/importer/brave_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@ bool ParsePaymentsPreferences(BraveLedger& ledger, const base::Value& session_st
TryFindBoolKey(settings, "payments.allow-non-verified-publishers", payments->allow_non_verified);
TryFindBoolKey(settings, "payments.allow-media-publishers", payments->allow_media_publishers);

std::string contribution_amount = "";
TryFindStringKey(settings, "payments.contribution-amount", contribution_amount);
if (!contribution_amount.empty()) {
if (!base::StringToDouble(contribution_amount, &payments->contribution_amount)) {
LOG(ERROR) << "StringToDouble failed when converting \"settings.payments.contribution-amount\"; unable to convert value \"" << contribution_amount << "\"; defaulting value.";
}
}

std::string minimum_visits = "";
TryFindStringKey(settings, "payments.minimum-visits", minimum_visits);
if (!minimum_visits.empty()) {
Expand All @@ -422,42 +430,25 @@ bool ParsePaymentsPreferences(BraveLedger& ledger, const base::Value& session_st
}

std::string minumum_visit_time = "";
TryFindStringKey(settings, "payments.minimum-visit-time",minumum_visit_time);
TryFindStringKey(settings, "payments.minimum-visit-time", minumum_visit_time);
if (!minumum_visit_time.empty()) {
if (!base::StringToUint64(minumum_visit_time, &payments->min_publisher_duration)) {
if (!base::StringToUint64(minumum_visit_time, &payments->min_visit_time)) {
LOG(ERROR) << "StringToUint64 failed when converting \"settings.payments.minimum-visit-time\"; unable to convert value \"" << minumum_visit_time << "\"; defaulting value.";
}
}
switch (payments->min_publisher_duration) {
switch (payments->min_visit_time) {
// allowed values
case 5000:
case 8000:
case 60000:
break;
case 5000: payments->min_visit_time = 5; break;
case 8000: payments->min_visit_time = 8; break;
case 60000: payments->min_visit_time = 60; break;

default:
payments->min_publisher_duration = braveledger_ledger::_default_min_publisher_duration;
}

std::string contribution_amount = "";
TryFindStringKey(settings, "payments.contribution-amount", contribution_amount);
if (!contribution_amount.empty()) {
if (!base::StringToUint(contribution_amount, &payments->contribution_amount)) {
LOG(ERROR) << "StringToUint failed when converting \"settings.payments.contribution-amount\"; unable to convert value \"" << contribution_amount << "\"; defaulting value.";
}
payments->min_visit_time = braveledger_ledger::_default_min_publisher_duration;
}

// TODO: read in excluded sites
// ...

LOG(ERROR) << "BSC]] "
<< "\npayments->allow_media_publishers=" << payments->allow_media_publishers
<< "\npayments->allow_non_verified=" << payments->allow_non_verified
<< "\npayments->enabled=" << payments->enabled
<< "\npayments->min_publisher_duration=" << payments->min_publisher_duration
<< "\npayments->contribution_amount=" << payments->contribution_amount
<< "\npayments->min_visits=" << payments->min_visits;

return true;
}

Expand Down

0 comments on commit 11a722b

Please sign in to comment.