From 816a3e3c383e02761e4da52bf193b499218573bf Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Tue, 18 Aug 2020 17:57:01 +0200 Subject: [PATCH] Fixes user funds claim Resolves https://github.com/brave/brave-browser/issues/11298 --- components/brave_rewards/browser/rewards_p3a.cc | 6 ++---- components/brave_rewards/browser/rewards_p3a.h | 2 +- .../include/bat/ledger/public/interfaces/ledger.mojom | 2 +- .../src/bat/ledger/internal/wallet/wallet_balance.cc | 1 - .../src/bat/ledger/internal/wallet/wallet_claim.cc | 11 +++++------ .../src/bat/ledger/internal/wallet/wallet_claim.h | 2 +- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/components/brave_rewards/browser/rewards_p3a.cc b/components/brave_rewards/browser/rewards_p3a.cc index 5b19a420f58b..191d048f33b0 100644 --- a/components/brave_rewards/browser/rewards_p3a.cc +++ b/components/brave_rewards/browser/rewards_p3a.cc @@ -154,7 +154,7 @@ void RecordRewardsDisabledForSomeMetrics() { double CalcWalletBalanceForP3A(base::flat_map wallets, - std::string user_funds) { + double user_funds) { double balance_minus_grant = 0.0; for (const auto& wallet : wallets) { // Skip anonymous wallet, since it can contain grants. @@ -166,9 +166,7 @@ double CalcWalletBalanceForP3A(base::flat_map wallets, // `user_funds` is the amount of user-funded BAT // in the anonymous wallet (ex: not grants). - double user_funds_value; - balance_minus_grant += - base::StringToDouble(user_funds, &user_funds_value); + balance_minus_grant += user_funds; return balance_minus_grant; } diff --git a/components/brave_rewards/browser/rewards_p3a.h b/components/brave_rewards/browser/rewards_p3a.h index 5ab8c075c5d3..f726404addf9 100644 --- a/components/brave_rewards/browser/rewards_p3a.h +++ b/components/brave_rewards/browser/rewards_p3a.h @@ -63,7 +63,7 @@ void RecordNoWalletCreatedForAllMetrics(); void RecordRewardsDisabledForSomeMetrics(); double CalcWalletBalanceForP3A(base::flat_map wallets, - std::string user_funds); + double user_funds); uint64_t RoundProbiToUint64(base::StringPiece probi); diff --git a/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom b/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom index 02057012dbff..c634b4ac83fa 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom +++ b/vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom @@ -122,7 +122,7 @@ struct RewardsParameters { struct Balance { double total; - string user_funds; + double user_funds; map wallets; }; diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_balance.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_balance.cc index be029b24cc86..7fec980761c1 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_balance.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_balance.cc @@ -35,7 +35,6 @@ void WalletBalance::Fetch(ledger::FetchBalanceCallback callback) { // we can skip balance server ping if (!braveledger_state::GetFetchOldBalanceEnabled(ledger_)) { auto balance = ledger::Balance::New(); - balance->user_funds = "0"; GetUnblindedTokens(std::move(balance), callback); return; } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_claim.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_claim.cc index a217744a52cf..488bef1344e4 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_claim.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_claim.cc @@ -11,6 +11,7 @@ #include "base/base64.h" #include "base/json/json_writer.h" +#include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/values.h" #include "bat/ledger/internal/common/security_helper.h" @@ -28,14 +29,12 @@ using std::placeholders::_2; namespace { std::string GeneratePayload( - const std::string& user_funds, + const double user_funds, const std::string& address, const std::string& anon_address, const std::vector& seed) { - const std::string amount = user_funds.empty() ? "0" : user_funds; - base::Value denomination(base::Value::Type::DICTIONARY); - denomination.SetStringKey("amount", amount); + denomination.SetStringKey("amount", base::NumberToString(user_funds)); denomination.SetStringKey("currency", "BAT"); base::Value octets(base::Value::Type::DICTIONARY); @@ -109,7 +108,7 @@ void WalletClaim::OnBalance( } if (ledger_->GetBooleanState(ledger::kStateAnonTransferChecked) && - balance->user_funds == "0") { + balance->user_funds == 0) { BLOG(1, "Second ping with zero balance"); callback(ledger::Result::LEDGER_OK); return; @@ -144,7 +143,7 @@ void WalletClaim::OnBalance( void WalletClaim::TransferFunds( const ledger::Result result, - const std::string user_funds, + const double user_funds, ledger::ResultCallback callback) { auto wallets = ledger_->GetExternalWallets(); auto wallet_ptr = braveledger_uphold::GetWallet(std::move(wallets)); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_claim.h b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_claim.h index abdddd9cd4a4..e46686c2b7d9 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_claim.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_claim.h @@ -33,7 +33,7 @@ class WalletClaim { void TransferFunds( const ledger::Result result, - const std::string user_funds, + const double user_funds, ledger::ResultCallback callback); void OnTransferFunds(