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

Fixes user funds claim (uplift to 1.13.x) #6453

Merged
merged 1 commit into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions components/brave_rewards/browser/rewards_p3a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void RecordRewardsDisabledForSomeMetrics() {


double CalcWalletBalanceForP3A(base::flat_map<std::string, double> 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.
Expand All @@ -166,9 +166,7 @@ double CalcWalletBalanceForP3A(base::flat_map<std::string, double> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion components/brave_rewards/browser/rewards_p3a.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void RecordNoWalletCreatedForAllMetrics();
void RecordRewardsDisabledForSomeMetrics();

double CalcWalletBalanceForP3A(base::flat_map<std::string, double> wallets,
std::string user_funds);
double user_funds);

uint64_t RoundProbiToUint64(base::StringPiece probi);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct RewardsParameters {

struct Balance {
double total;
string user_funds;
double user_funds;
map<string, double> wallets;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<uint8_t>& 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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down