Skip to content

Commit a5bdc84

Browse files
committed
Fixes user funds claim
Resolves brave/brave-browser#11298
1 parent f0f1ba2 commit a5bdc84

File tree

8 files changed

+18
-22
lines changed

8 files changed

+18
-22
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/endpoint/promotion/post_claim_uphold/post_claim_uphold.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "base/base64.h"
1212
#include "base/json/json_writer.h"
13+
#include "base/strings/string_number_conversions.h"
1314
#include "base/strings/stringprintf.h"
1415
#include "bat/ledger/internal/common/security_helper.h"
1516
#include "bat/ledger/internal/endpoint/promotion/promotions_util.h"
@@ -60,18 +61,16 @@ std::string PostClaimUphold::GetUrl() {
6061
return GetServerUrl(path);
6162
}
6263

63-
std::string PostClaimUphold::GeneratePayload(const std::string& user_funds) {
64+
std::string PostClaimUphold::GeneratePayload(const double user_funds) {
6465
auto wallets = ledger_->ledger_client()->GetExternalWallets();
6566
auto wallet_ptr = braveledger_uphold::GetWallet(std::move(wallets));
6667
if (!wallet_ptr) {
6768
BLOG(0, "Wallet is null");
6869
return "";
6970
}
7071

71-
const std::string amount = user_funds.empty() ? "0" : user_funds;
72-
7372
base::Value denomination(base::Value::Type::DICTIONARY);
74-
denomination.SetStringKey("amount", amount);
73+
denomination.SetStringKey("amount", base::NumberToString(user_funds));
7574
denomination.SetStringKey("currency", "BAT");
7675

7776
base::Value octets(base::Value::Type::DICTIONARY);
@@ -148,7 +147,7 @@ ledger::Result PostClaimUphold::CheckStatusCode(const int status_code) {
148147
}
149148

150149
void PostClaimUphold::Request(
151-
const std::string& user_funds,
150+
const double user_funds,
152151
PostClaimUpholdCallback callback) {
153152
auto url_callback = std::bind(&PostClaimUphold::OnRequest,
154153
this,

vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_claim_uphold/post_claim_uphold.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class PostClaimUphold {
2727
~PostClaimUphold();
2828

2929
void Request(
30-
const std::string& user_funds,
30+
const double user_funds,
3131
PostClaimUpholdCallback callback);
3232

3333
private:
3434
std::string GetUrl();
3535

36-
std::string GeneratePayload(const std::string& user_funds);
36+
std::string GeneratePayload(const double user_funds);
3737

3838
ledger::Result CheckStatusCode(const int status_code);
3939

vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/promotion/post_claim_uphold/post_claim_uphold_unittest.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ TEST_F(PostClaimUpholdTest, ServerOK) {
5959
}));
6060

6161
claim_->Request(
62-
"30.0",
62+
30.0,
6363
[](const ledger::Result result) {
6464
EXPECT_EQ(result, ledger::Result::LEDGER_OK);
6565
});
@@ -83,7 +83,7 @@ TEST_F(PostClaimUpholdTest, ServerError400) {
8383
}));
8484

8585
claim_->Request(
86-
"30.0",
86+
30.0,
8787
[](const ledger::Result result) {
8888
EXPECT_EQ(result, ledger::Result::LEDGER_ERROR);
8989
});
@@ -107,7 +107,7 @@ TEST_F(PostClaimUpholdTest, ServerError403) {
107107
}));
108108

109109
claim_->Request(
110-
"30.0",
110+
30.0,
111111
[](const ledger::Result result) {
112112
EXPECT_EQ(result, ledger::Result::LEDGER_ERROR);
113113
});
@@ -131,7 +131,7 @@ TEST_F(PostClaimUpholdTest, ServerError404) {
131131
}));
132132

133133
claim_->Request(
134-
"30.0",
134+
30.0,
135135
[](const ledger::Result result) {
136136
EXPECT_EQ(result, ledger::Result::NOT_FOUND);
137137
});
@@ -155,7 +155,7 @@ TEST_F(PostClaimUpholdTest, ServerError409) {
155155
}));
156156

157157
claim_->Request(
158-
"30.0",
158+
30.0,
159159
[](const ledger::Result result) {
160160
EXPECT_EQ(result, ledger::Result::ALREADY_EXISTS);
161161
});
@@ -179,7 +179,7 @@ TEST_F(PostClaimUpholdTest, ServerError500) {
179179
}));
180180

181181
claim_->Request(
182-
"30.0",
182+
30.0,
183183
[](const ledger::Result result) {
184184
EXPECT_EQ(result, ledger::Result::LEDGER_ERROR);
185185
});
@@ -203,7 +203,7 @@ TEST_F(PostClaimUpholdTest, ServerErrorRandom) {
203203
}));
204204

205205
claim_->Request(
206-
"30.0",
206+
30.0,
207207
[](const ledger::Result result) {
208208
EXPECT_EQ(result, ledger::Result::LEDGER_ERROR);
209209
});

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

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ void WalletBalance::Fetch(ledger::FetchBalanceCallback callback) {
3333
// we can skip balance server ping
3434
if (!ledger_->state()->GetFetchOldBalanceEnabled()) {
3535
auto balance = ledger::Balance::New();
36-
balance->user_funds = "0";
3736
GetUnblindedTokens(std::move(balance), callback);
3837
return;
3938
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void WalletClaim::OnBalance(
5353
}
5454

5555
if (ledger_->state()->GetAnonTransferChecked() &&
56-
balance->user_funds == "0") {
56+
balance->user_funds == 0) {
5757
BLOG(1, "Second ping with zero balance");
5858
callback(ledger::Result::LEDGER_OK);
5959
return;

0 commit comments

Comments
 (0)