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 balance being an empty string #5883

Merged
merged 1 commit into from
Jun 18, 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
45 changes: 42 additions & 3 deletions components/brave_rewards/browser/test/rewards_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ bool URLMatches(const std::string& url,

enum class ContributionType { OneTimeTip, MonthlyTip };

class MadeRequest {
public:
MadeRequest(const std::string& url, int32_t method)
: url(url), method(method) {}
std::string url;
int32_t method;
};

} // namespace

namespace brave_test_resp {
Expand Down Expand Up @@ -354,7 +362,7 @@ class RewardsBrowserTest
int* response_status_code,
std::string* response,
std::map<std::string, std::string>* headers) {
request_made_ = true;
requests_made_.emplace_back(url, method);
std::vector<std::string> tmp = base::SplitString(url,
"/",
base::TRIM_WHITESPACE,
Expand Down Expand Up @@ -1442,7 +1450,7 @@ class RewardsBrowserTest
bool last_publisher_added_ = false;
bool alter_publisher_list_ = false;
bool show_defaults_in_properties_ = false;
bool request_made_ = false;
std::vector<MadeRequest> requests_made_;
double balance_ = 0;
double reconciled_tip_total_ = 0;
double pending_balance_ = 0;
Expand Down Expand Up @@ -2764,7 +2772,7 @@ IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, PanelDontDoRequests) {
ASSERT_TRUE(popup_contents);

// Make sure that no request was made
ASSERT_FALSE(request_made_);
ASSERT_TRUE(requests_made_.empty());
}

IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, ShowMonthlyIfACOff) {
Expand Down Expand Up @@ -2973,3 +2981,34 @@ IN_PROC_BROWSER_TEST_F(
"td:nth-of-type(3)",
"30.000BAT42.90 USD");
}

IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, ZeroBalanceWalletClaimNotCalled) {
SetUpUpholdWallet(50.0);
EnableRewardsViaCode();

requests_made_.clear(); // only consider requests made after initialization

base::RunLoop run_loop;
auto test_callback =
[&](int32_t result,
std::unique_ptr<brave_rewards::ExternalWallet> wallet) {
EXPECT_EQ(result, static_cast<int>(ledger::Result::LEDGER_OK));
EXPECT_FALSE(requests_made_.empty());

// Should not attempt to call /v2/wallet/UUID/claim endpoint
// since by default the wallet should contain 0 `user_funds`
auto wallet_claim_call = std::find_if(
requests_made_.begin(), requests_made_.end(),
[](const MadeRequest& req) {
return req.url.find("/v2/wallet") != std::string::npos &&
req.url.find("/claim") != std::string::npos;
});

EXPECT_TRUE(wallet_claim_call == requests_made_.end());
run_loop.Quit();
};

rewards_service_->GetExternalWallet(
"uphold", base::BindLambdaForTesting(test_callback));
run_loop.Run();
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void Balance::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 @@ -265,6 +265,9 @@ std::string Wallet::GetClaimPayload(
const std::string anon_address) {
ledger::UnsignedTxProperties unsigned_tx;
unsigned_tx.amount = user_funds;
if (unsigned_tx.amount.empty()) {
unsigned_tx.amount = "0";
}
unsigned_tx.currency = "BAT";
unsigned_tx.destination = new_address;
const ledger::UnsignedTxState unsigned_tx_state;
Expand Down Expand Up @@ -303,8 +306,8 @@ std::string Wallet::GetClaimPayload(
signed_tx.SetStringKey("octets", octets);

base::Value denomination(base::Value::Type::DICTIONARY);
denomination.SetStringKey("amount", user_funds);
denomination.SetStringKey("currency", "BAT");
denomination.SetStringKey("amount", unsigned_tx.amount);
denomination.SetStringKey("currency", unsigned_tx.currency);

base::Value body(base::Value::Type::DICTIONARY);
body.SetStringKey("destination", new_address);
Expand Down