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

Moves WalletProperties to mojo #2712

Merged
merged 2 commits into from Jun 16, 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

@@ -821,30 +821,30 @@ void RewardsServiceImpl::OnWalletInitialized(ledger::Result result) {

void RewardsServiceImpl::OnWalletProperties(
ledger::Result result,
std::unique_ptr<ledger::WalletProperties> properties) {
if (properties && properties->balance_ > 0) {
ledger::WalletPropertiesPtr properties) {
if (properties && properties->balance > 0) {
profile_->GetPrefs()->SetBoolean(prefs::kRewardsUserHasFunded, true);
}

std::unique_ptr<brave_rewards::WalletProperties> wallet_properties;
for (auto& observer : observers_) {
if (properties) {
wallet_properties.reset(new brave_rewards::WalletProperties);
wallet_properties->probi = properties->probi_;
wallet_properties->balance = properties->balance_;
wallet_properties->rates = properties->rates_;
wallet_properties->parameters_choices = properties->parameters_choices_;
wallet_properties->parameters_range = properties->parameters_range_;
wallet_properties->parameters_days = properties->parameters_days_;
wallet_properties->monthly_amount = properties->fee_amount_;

for (size_t i = 0; i < properties->grants_.size(); i ++) {
wallet_properties->probi = properties->probi;
wallet_properties->balance = properties->balance;
wallet_properties->rates = mojo::FlatMapToMap(properties->rates);
wallet_properties->parameters_choices = properties->parameters_choices;
wallet_properties->parameters_range = properties->parameters_range;
wallet_properties->parameters_days = properties->parameters_days;
wallet_properties->monthly_amount = properties->fee_amount;

for (size_t i = 0; i < properties->grants.size(); i ++) {
brave_rewards::Grant grant;

grant.altcurrency = properties->grants_[i].altcurrency;
grant.probi = properties->grants_[i].probi;
grant.expiryTime = properties->grants_[i].expiryTime;
grant.type = properties->grants_[i].type;
grant.altcurrency = properties->grants[i]->altcurrency;
grant.probi = properties->grants[i]->probi;
grant.expiryTime = properties->grants[i]->expiry_time;
grant.type = properties->grants[i]->type;

wallet_properties->grants.push_back(grant);
}
@@ -913,8 +913,8 @@ void RewardsServiceImpl::GetAutoContributeProps(
}

void RewardsServiceImpl::OnGrant(ledger::Result result,
const ledger::Grant& grant) {
TriggerOnGrant(result, grant);
ledger::GrantPtr grant) {
TriggerOnGrant(result, std::move(grant));
}

void RewardsServiceImpl::OnGrantCaptcha(const std::string& image,
@@ -924,29 +924,30 @@ void RewardsServiceImpl::OnGrantCaptcha(const std::string& image,

void RewardsServiceImpl::OnRecoverWallet(ledger::Result result,
double balance,
const std::vector<ledger::Grant>& grants) {
TriggerOnRecoverWallet(result, balance, grants);
std::vector<ledger::GrantPtr> grants) {
TriggerOnRecoverWallet(result, balance, std::move(grants));
}

void RewardsServiceImpl::OnGrantFinish(ledger::Result result,
const ledger::Grant& grant) {
ledger::GrantPtr grant) {
ledger::BalanceReportInfo report_info;
auto now = base::Time::Now();
if (result == ledger::Result::LEDGER_OK) {
if (!Connected())
if (grant && result == ledger::Result::LEDGER_OK) {
if (!Connected()) {
return;
}

int report_type = grant.type == "ads"
int report_type = grant->type == "ads"
? ledger::ReportType::ADS
: ledger::ReportType::GRANT;
bat_ledger_->SetBalanceReportItem(GetPublisherMonth(now),
GetPublisherYear(now),
report_type,
grant.probi);
grant->probi);
}

GetCurrentBalanceReport();
TriggerOnGrantFinish(result, grant);
TriggerOnGrantFinish(result, std::move(grant));
}

void RewardsServiceImpl::OnReconcileComplete(ledger::Result result,
@@ -1364,16 +1365,9 @@ void RewardsServiceImpl::TriggerOnWalletInitialized(ledger::Result result) {

void RewardsServiceImpl::OnFetchWalletProperties(
int result,
const std::string& json_wallet) {
std::unique_ptr<ledger::WalletProperties> wallet_properties;

if (!json_wallet.empty()) {
wallet_properties.reset(new ledger::WalletProperties());
wallet_properties->loadFromJson(json_wallet);
}

ledger::WalletPropertiesPtr properties) {
OnWalletProperties(static_cast<ledger::Result>(result),
std::move(wallet_properties));
std::move(properties));
}

void RewardsServiceImpl::FetchWalletProperties() {
@@ -1402,14 +1396,16 @@ void RewardsServiceImpl::FetchGrants(const std::string& lang,
}

void RewardsServiceImpl::TriggerOnGrant(ledger::Result result,
const ledger::Grant& grant) {
ledger::GrantPtr grant) {
brave_rewards::Grant properties;

properties.promotionId = grant.promotionId;
properties.altcurrency = grant.altcurrency;
properties.probi = grant.probi;
properties.expiryTime = grant.expiryTime;
properties.type = grant.type;
if (grant) {
properties.promotionId = grant->promotion_id;
properties.altcurrency = grant->altcurrency;
properties.probi = grant->probi;
properties.expiryTime = grant->expiry_time;
properties.type = grant->type;
}

for (auto& observer : observers_)
observer.OnGrant(this, result, properties);
@@ -1451,20 +1447,26 @@ void RewardsServiceImpl::RecoverWallet(const std::string& passPhrase) const {
bat_ledger_->RecoverWallet(passPhrase);
}

void RewardsServiceImpl::TriggerOnRecoverWallet(ledger::Result result,
double balance,
const std::vector<ledger::Grant>& grants) {
void RewardsServiceImpl::TriggerOnRecoverWallet(
ledger::Result result,
double balance,
std::vector<ledger::GrantPtr> grants) {
std::vector<brave_rewards::Grant> newGrants;
for (size_t i = 0; i < grants.size(); i ++) {
if (!grants[i]) {
continue;
}

brave_rewards::Grant grant;

grant.altcurrency = grants[i].altcurrency;
grant.probi = grants[i].probi;
grant.expiryTime = grants[i].expiryTime;
grant.type = grants[i].type;
grant.altcurrency = grants[i]->altcurrency;
grant.probi = grants[i]->probi;
grant.expiryTime = grants[i]->expiry_time;
grant.type = grants[i]->type;

newGrants.push_back(grant);
}

for (auto& observer : observers_)
observer.OnRecoverWallet(this, result, balance, newGrants);
}
@@ -1479,17 +1481,20 @@ void RewardsServiceImpl::SolveGrantCaptcha(const std::string& solution,
}

void RewardsServiceImpl::TriggerOnGrantFinish(ledger::Result result,
const ledger::Grant& grant) {
ledger::GrantPtr grant) {
brave_rewards::Grant properties;

properties.promotionId = grant.promotionId;
properties.altcurrency = grant.altcurrency;
properties.probi = grant.probi;
properties.expiryTime = grant.expiryTime;
properties.type = grant.type;
if (grant) {
properties.promotionId = grant->promotion_id;
properties.altcurrency = grant->altcurrency;
properties.probi = grant->probi;
properties.expiryTime = grant->expiry_time;
properties.type = grant->type;
}

for (auto& observer : observers_)
for (auto& observer : observers_) {
observer.OnGrantFinish(this, result, properties);
}
}

void RewardsServiceImpl::GetReconcileStamp(
@@ -271,13 +271,13 @@ class RewardsServiceImpl : public RewardsService,
const std::string& data);
void TriggerOnWalletInitialized(ledger::Result result);
void OnFetchWalletProperties(int result,
const std::string& json_wallet);
void TriggerOnGrant(ledger::Result result, const ledger::Grant& grant);
ledger::WalletPropertiesPtr properties);
void TriggerOnGrant(ledger::Result result, ledger::GrantPtr grant);
void TriggerOnGrantCaptcha(const std::string& image, const std::string& hint);
void TriggerOnRecoverWallet(ledger::Result result,
double balance,
const std::vector<ledger::Grant>& grants);
void TriggerOnGrantFinish(ledger::Result result, const ledger::Grant& grant);
std::vector<ledger::GrantPtr> grants);
void TriggerOnGrantFinish(ledger::Result result, ledger::GrantPtr grant);
void TriggerOnRewardsMainEnabled(bool rewards_main_enabled);
void OnPublisherInfoSaved(ledger::PublisherInfoCallback callback,
ledger::PublisherInfoPtr info,
@@ -333,7 +333,7 @@ class RewardsServiceImpl : public RewardsService,
bool success);
void OnWalletProperties(
ledger::Result result,
std::unique_ptr<ledger::WalletProperties> properties) override;
ledger::WalletPropertiesPtr properties) override;
void OnTip(const std::string& publisher_key, int amount, bool recurring,
std::unique_ptr<brave_rewards::ContentSite> site) override;

@@ -399,18 +399,18 @@ class RewardsServiceImpl : public RewardsService,
std::string GenerateGUID() const override;
void OnWalletInitialized(ledger::Result result) override;
void OnGrant(ledger::Result result,
const ledger::Grant& grant) override;
ledger::GrantPtr grant) override;
void OnGrantCaptcha(const std::string& image,
const std::string& hint) override;
void OnRecoverWallet(ledger::Result result,
double balance,
const std::vector<ledger::Grant>& grants) override;
std::vector<ledger::GrantPtr> grants) override;
void OnReconcileComplete(ledger::Result result,
const std::string& viewing_id,
ledger::REWARDS_CATEGORY category,
const std::string& probi) override;
void OnGrantFinish(ledger::Result result,
const ledger::Grant& grant) override;
ledger::GrantPtr grant) override;
void LoadLedgerState(ledger::LedgerCallbackHandler* handler) override;
void LoadPublisherState(ledger::LedgerCallbackHandler* handler) override;
void SaveLedgerState(const std::string& ledger_state,
@@ -143,21 +143,22 @@ void BatLedgerClientMojoProxy::OnWalletInitialized(ledger::Result result) {
bat_ledger_client_->OnWalletInitialized(ToMojomResult(result));
}

void BatLedgerClientMojoProxy::OnWalletProperties(ledger::Result result,
std::unique_ptr<ledger::WalletProperties> properties) {
void BatLedgerClientMojoProxy::OnWalletProperties(
ledger::Result result,
ledger::WalletPropertiesPtr properties) {
if (!Connected())
return;

std::string json = properties ? properties->ToJson() : "";
bat_ledger_client_->OnWalletProperties(ToMojomResult(result), json);
bat_ledger_client_->OnWalletProperties(ToMojomResult(result),
std::move(properties));
}

void BatLedgerClientMojoProxy::OnGrant(ledger::Result result,
const ledger::Grant& grant) {
ledger::GrantPtr grant) {
if (!Connected())
return;

bat_ledger_client_->OnGrant(ToMojomResult(result), grant.ToJson());
bat_ledger_client_->OnGrant(ToMojomResult(result), std::move(grant));
}

void BatLedgerClientMojoProxy::OnGrantCaptcha(const std::string& image,
@@ -168,18 +169,17 @@ void BatLedgerClientMojoProxy::OnGrantCaptcha(const std::string& image,
bat_ledger_client_->OnGrantCaptcha(image, hint);
}

void BatLedgerClientMojoProxy::OnRecoverWallet(ledger::Result result,
double balance, const std::vector<ledger::Grant>& grants) {
if (!Connected())
void BatLedgerClientMojoProxy::OnRecoverWallet(
ledger::Result result,
double balance,
std::vector<ledger::GrantPtr> grants) {
if (!Connected()) {
return;

std::vector<std::string> grant_jsons;
for (auto const& grant : grants) {
grant_jsons.push_back(grant.ToJson());
}

bat_ledger_client_->OnRecoverWallet(
ToMojomResult(result), balance, grant_jsons);
bat_ledger_client_->OnRecoverWallet(ToMojomResult(result),
balance,
std::move(grants));
}

void BatLedgerClientMojoProxy::OnReconcileComplete(ledger::Result result,
@@ -206,11 +206,11 @@ std::unique_ptr<ledger::LogStream> BatLedgerClientMojoProxy::VerboseLog(
}

void BatLedgerClientMojoProxy::OnGrantFinish(ledger::Result result,
const ledger::Grant& grant) {
ledger::GrantPtr grant) {
if (!Connected())
return;

bat_ledger_client_->OnGrantFinish(ToMojomResult(result), grant.ToJson());
bat_ledger_client_->OnGrantFinish(ToMojomResult(result), std::move(grant));
}

void BatLedgerClientMojoProxy::OnLoadLedgerState(
@@ -31,20 +31,20 @@ class BatLedgerClientMojoProxy : public ledger::LedgerClient,
void OnWalletInitialized(ledger::Result result) override;
void OnWalletProperties(
ledger::Result result,
std::unique_ptr<ledger::WalletProperties> properties) override;
ledger::WalletPropertiesPtr properties) override;
void OnGrant(ledger::Result result,
const ledger::Grant& grant) override;
ledger::GrantPtr grant) override;
void OnGrantCaptcha(const std::string& image,
const std::string& hint) override;
void OnRecoverWallet(ledger::Result result,
double balance,
const std::vector<ledger::Grant>& grants) override;
std::vector<ledger::GrantPtr> grants) override;
void OnReconcileComplete(ledger::Result result,
const std::string& viewing_id,
ledger::REWARDS_CATEGORY category,
const std::string& probi) override;
void OnGrantFinish(ledger::Result result,
const ledger::Grant& grant) override;
ledger::GrantPtr grant) override;
void LoadLedgerState(ledger::LedgerCallbackHandler* handler) override;
void LoadPublisherState(ledger::LedgerCallbackHandler* handler) override;
void SaveLedgerState(const std::string& ledger_state,
@@ -64,10 +64,9 @@ void BatLedgerImpl::CreateWallet() {
void BatLedgerImpl::OnFetchWalletProperties(
CallbackHolder<FetchWalletPropertiesCallback>* holder,
ledger::Result result,
std::unique_ptr<ledger::WalletProperties> properties) {
std::string json_wallet = properties.get() ? properties->ToJson() : "";
ledger::WalletPropertiesPtr properties) {
if (holder->is_valid())
std::move(holder->get()).Run(result, json_wallet);
std::move(holder->get()).Run(result, std::move(properties));
delete holder;
}

@@ -209,7 +209,7 @@ class BatLedgerImpl : public mojom::BatLedger,
static void OnFetchWalletProperties(
CallbackHolder<FetchWalletPropertiesCallback>* holder,
ledger::Result result,
std::unique_ptr<ledger::WalletProperties> properties);
ledger::WalletPropertiesPtr properties);

static void OnGetPublisherBanner(
CallbackHolder<GetPublisherBannerCallback>* holder,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.