Skip to content

Commit

Permalink
Uplift of #5776 (squashed) to beta
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-browser-releases authored and NejcZdovc committed Jun 9, 2020
1 parent 1d9d338 commit 93cf6ec
Show file tree
Hide file tree
Showing 5 changed files with 47 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.000BAT28.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.000BAT42.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 @@ -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 93cf6ec

Please sign in to comment.