Skip to content

Commit

Permalink
Fixes user funds claim
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Aug 19, 2020
1 parent df1345f commit 816a3e3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
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

0 comments on commit 816a3e3

Please sign in to comment.