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 split one time tip #5776

Merged
merged 1 commit into from
Jun 9, 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
40 changes: 39 additions & 1 deletion components/brave_rewards/browser/test/rewards_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ class RewardsBrowserTest
"[\"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 @@ -2923,3 +2925,39 @@ IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, CheckIfReconcileWasResetACOff) {
}));
run_loop_second.Run();
}

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

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

ActivateTabAtIndex(0);

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

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

rewards_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_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