Skip to content

Commit

Permalink
Merge pull request #5778 from brave/pr5776_split-scenario_1.11.x
Browse files Browse the repository at this point in the history
Fixes split one time tip (uplift to 1.11.x)
  • Loading branch information
LaurenWags authored Jun 10, 2020
2 parents 958e4ed + 60da95f commit 86cc97b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 63 deletions.
40 changes: 39 additions & 1 deletion components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ class BraveRewardsBrowserTest
"[\"site2.com\",\"wallet_connected\",false,\"address5\",{}],"
"[\"site3.com\",\"wallet_connected\",false,\"address6\",{}],"
"[\"laurenwags.github.io\",\"wallet_connected\",false,\"address2\","
"{\"donationAmounts\": [5,10,20]}]"
"{\"donationAmounts\": [5,10,20]}],"
"[\"kjozwiakstaging.github.io\",\"wallet_connected\",false,\"aa\","
"{\"donationAmounts\": [5,50,100]}]"
"]";
}

Expand Down Expand Up @@ -2928,3 +2930,39 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, CheckIfReconcileWasResetACOff) {
}));
run_loop_second.Run();
}

IN_PROC_BROWSER_TEST_F(
BraveRewardsBrowserTest,
SplitProcessOneTimeTip) {
SetUpUpholdWallet(50.0);
EnableRewards();
ClaimPromotionViaCode();

TipPublisher(
"kjozwiakstaging.github.io",
ContributionType::OneTimeTip,
true,
1);

ActivateTabAtIndex(0);

rewards_service_browsertest_utils::WaitForElementThenClick(
contents(),
"[data-test-id='showMonthlyReport']");

rewards_service_browsertest_utils::WaitForElementThenClick(
contents(),
"[data-test-id='tab-oneTimeDonation']");

rewards_service_browsertest_utils::WaitForElementToEqual(
contents(),
"[data-test-id='activity-table-body'] tr:nth-of-type(1) "
"td:nth-of-type(3)",
"20.0BAT28.60 USD");

rewards_service_browsertest_utils::WaitForElementToEqual(
contents(),
"[data-test-id='activity-table-body'] tr:nth-of-type(2) "
"td:nth-of-type(3)",
"30.0BAT42.90 USD");
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,22 @@ export default class ModalActivity extends React.PureComponent<Props, State> {
generateTabs = () => {
const tabs = [
{
id: 'transactions',
title: getLocale('transactions'),
content: this.getTransactionTable
},
{
id: 'monthlyContributions',
title: getLocale('monthlyContributions'),
content: this.getMonthlyContributionTable
},
{
id: 'autoContribute',
title: getLocale('autoContribute'),
content: this.getAutoContributeTable
},
{
id: 'oneTimeDonation',
title: getLocale('oneTimeDonation'),
content: this.getOneTimeTips
}
Expand All @@ -277,14 +281,15 @@ export default class ModalActivity extends React.PureComponent<Props, State> {
selected={selected}
isFirst={isFirst}
onClick={this.changeTab.bind(this, i)}
data-test-id={`tab-${tab.id}`}
>
{tab.title}
</Tab>
)
})
}
</Tabs>
<TabContent>
<TabContent data-test-id={`activity-table-body`}>
{tabs[this.state.currentTab].content()}
</TabContent>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,30 +374,15 @@ void Contribution::CreateNewEntry(
queue_publishers.push_back(item->Clone());
}

ledger::ContributionQueuePublisherList publishers_new;
ledger::ContributionQueuePublisherList publishers_left;
if (wallet_balance < queue->amount) {
contribution->amount = wallet_balance;
queue->amount = queue->amount - wallet_balance;

if (queue->type == ledger::RewardsType::RECURRING_TIP ||
queue->type == ledger::RewardsType::ONE_TIME_TIP) {
AdjustPublisherListAmounts(
std::move(queue_publishers),
&publishers_new,
&publishers_left,
wallet_balance);
queue->publishers = std::move(publishers_left);
} else {
publishers_new = std::move(queue_publishers);
}
} else {
publishers_new = std::move(queue_publishers);
queue->amount = 0;
}

ledger::ContributionPublisherList publisher_list;
for (const auto& item : publishers_new) {
for (const auto& item : queue_publishers) {
auto publisher = ledger::ContributionPublisher::New();
publisher->contribution_id = contribution_id;
publisher->publisher_key = item->publisher_key;
Expand Down Expand Up @@ -479,7 +464,7 @@ void Contribution::OnEntrySaved(
braveledger_bind_util::FromContributionQueueToString(queue->Clone()));

ledger_->SaveContributionQueue(queue->Clone(), save_callback);
} else if (queue->type != ledger::RewardsType::ONE_TIME_TIP) {
} else {
MarkContributionQueueAsComplete(queue->id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <utility>

#include "base/guid.h"
#include "bat/ledger/internal/contribution/contribution_tip.h"
#include "bat/ledger/internal/ledger_impl.h"

Expand Down Expand Up @@ -74,6 +75,7 @@ void ContributionTip::ServerPublisher(
queue_list.push_back(std::move(publisher));

auto queue = ledger::ContributionQueue::New();
queue->id = base::GenerateGUID();
queue->type = ledger::RewardsType::ONE_TIME_TIP;
queue->amount = amount;
queue->partial = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,44 +88,6 @@ bool HaveEnoughFundsToContribute(
return true;
}

void AdjustPublisherListAmounts(
ledger::ContributionQueuePublisherList publishers,
ledger::ContributionQueuePublisherList* publishers_new,
ledger::ContributionQueuePublisherList* publishers_left,
double reduce_fee_for) {
DCHECK(publishers_new && publishers_left);

for (auto& item : publishers) {
if (!item) {
continue;
}

if (reduce_fee_for == 0) {
publishers_left->push_back(std::move(item));
continue;
}

if (item->amount_percent <= reduce_fee_for) {
publishers_new->push_back(item->Clone());
reduce_fee_for -= item->amount_percent;
continue;
}

if (item->amount_percent > reduce_fee_for) {
// current list
const auto original_weight = item->amount_percent;
item->amount_percent = reduce_fee_for;
publishers_new->push_back(item->Clone());

// next list
item->amount_percent = original_weight - reduce_fee_for;
publishers_left->push_back(item->Clone());

reduce_fee_for = 0;
}
}
}

int32_t GetVotesFromAmount(const double amount) {
DCHECK_GT(braveledger_ledger::_vote_price, 0);
return std::floor(amount / braveledger_ledger::_vote_price);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ bool HaveEnoughFundsToContribute(
const bool partial,
const double balance);

void AdjustPublisherListAmounts(
ledger::ContributionQueuePublisherList publishers,
ledger::ContributionQueuePublisherList* publishers_new,
ledger::ContributionQueuePublisherList* publishers_left,
double reduce_fee_for);

int32_t GetVotesFromAmount(const double amount);

} // namespace braveledger_contribution
Expand Down

0 comments on commit 86cc97b

Please sign in to comment.