Skip to content

Commit 816a3e3

Browse files
committed
Fixes user funds claim
Resolves brave/brave-browser#11298
1 parent df1345f commit 816a3e3

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

components/brave_rewards/browser/rewards_p3a.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void RecordRewardsDisabledForSomeMetrics() {
154154

155155

156156
double CalcWalletBalanceForP3A(base::flat_map<std::string, double> wallets,
157-
std::string user_funds) {
157+
double user_funds) {
158158
double balance_minus_grant = 0.0;
159159
for (const auto& wallet : wallets) {
160160
// Skip anonymous wallet, since it can contain grants.
@@ -166,9 +166,7 @@ double CalcWalletBalanceForP3A(base::flat_map<std::string, double> wallets,
166166

167167
// `user_funds` is the amount of user-funded BAT
168168
// in the anonymous wallet (ex: not grants).
169-
double user_funds_value;
170-
balance_minus_grant +=
171-
base::StringToDouble(user_funds, &user_funds_value);
169+
balance_minus_grant += user_funds;
172170
return balance_minus_grant;
173171
}
174172

components/brave_rewards/browser/rewards_p3a.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void RecordNoWalletCreatedForAllMetrics();
6363
void RecordRewardsDisabledForSomeMetrics();
6464

6565
double CalcWalletBalanceForP3A(base::flat_map<std::string, double> wallets,
66-
std::string user_funds);
66+
double user_funds);
6767

6868
uint64_t RoundProbiToUint64(base::StringPiece probi);
6969

vendor/bat-native-ledger/include/bat/ledger/public/interfaces/ledger.mojom

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct RewardsParameters {
122122

123123
struct Balance {
124124
double total;
125-
string user_funds;
125+
double user_funds;
126126
map<string, double> wallets;
127127
};
128128

vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_balance.cc

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ void WalletBalance::Fetch(ledger::FetchBalanceCallback callback) {
3535
// we can skip balance server ping
3636
if (!braveledger_state::GetFetchOldBalanceEnabled(ledger_)) {
3737
auto balance = ledger::Balance::New();
38-
balance->user_funds = "0";
3938
GetUnblindedTokens(std::move(balance), callback);
4039
return;
4140
}

vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_claim.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "base/base64.h"
1313
#include "base/json/json_writer.h"
14+
#include "base/strings/string_number_conversions.h"
1415
#include "base/strings/stringprintf.h"
1516
#include "base/values.h"
1617
#include "bat/ledger/internal/common/security_helper.h"
@@ -28,14 +29,12 @@ using std::placeholders::_2;
2829
namespace {
2930

3031
std::string GeneratePayload(
31-
const std::string& user_funds,
32+
const double user_funds,
3233
const std::string& address,
3334
const std::string& anon_address,
3435
const std::vector<uint8_t>& seed) {
35-
const std::string amount = user_funds.empty() ? "0" : user_funds;
36-
3736
base::Value denomination(base::Value::Type::DICTIONARY);
38-
denomination.SetStringKey("amount", amount);
37+
denomination.SetStringKey("amount", base::NumberToString(user_funds));
3938
denomination.SetStringKey("currency", "BAT");
4039

4140
base::Value octets(base::Value::Type::DICTIONARY);
@@ -109,7 +108,7 @@ void WalletClaim::OnBalance(
109108
}
110109

111110
if (ledger_->GetBooleanState(ledger::kStateAnonTransferChecked) &&
112-
balance->user_funds == "0") {
111+
balance->user_funds == 0) {
113112
BLOG(1, "Second ping with zero balance");
114113
callback(ledger::Result::LEDGER_OK);
115114
return;
@@ -144,7 +143,7 @@ void WalletClaim::OnBalance(
144143

145144
void WalletClaim::TransferFunds(
146145
const ledger::Result result,
147-
const std::string user_funds,
146+
const double user_funds,
148147
ledger::ResultCallback callback) {
149148
auto wallets = ledger_->GetExternalWallets();
150149
auto wallet_ptr = braveledger_uphold::GetWallet(std::move(wallets));

vendor/bat-native-ledger/src/bat/ledger/internal/wallet/wallet_claim.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class WalletClaim {
3333

3434
void TransferFunds(
3535
const ledger::Result result,
36-
const std::string user_funds,
36+
const double user_funds,
3737
ledger::ResultCallback callback);
3838

3939
void OnTransferFunds(

0 commit comments

Comments
 (0)