From f62bdb64342c3dd62ded594b75bc3f2b8cbd1da1 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Mon, 8 Jun 2020 22:13:46 +0200 Subject: [PATCH] Fixes split one time tip Resolves https://github.com/brave/brave-browser/issues/10153 --- .../browser/test/rewards_browsertest.cc | 40 ++++++++++++++++++- .../ui/components/modalActivity/index.tsx | 7 +++- .../internal/contribution/contribution.cc | 19 +-------- .../contribution/contribution_util.cc | 38 ------------------ .../internal/contribution/contribution_util.h | 6 --- 5 files changed, 47 insertions(+), 63 deletions(-) diff --git a/components/brave_rewards/browser/test/rewards_browsertest.cc b/components/brave_rewards/browser/test/rewards_browsertest.cc index af1d0a94398d..853679fe7e64 100644 --- a/components/brave_rewards/browser/test/rewards_browsertest.cc +++ b/components/brave_rewards/browser/test/rewards_browsertest.cc @@ -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]}]" "]"; } @@ -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"); +} diff --git a/components/brave_rewards/resources/ui/components/modalActivity/index.tsx b/components/brave_rewards/resources/ui/components/modalActivity/index.tsx index 3091ac9c29fa..660ee4d77488 100644 --- a/components/brave_rewards/resources/ui/components/modalActivity/index.tsx +++ b/components/brave_rewards/resources/ui/components/modalActivity/index.tsx @@ -246,18 +246,22 @@ export default class ModalActivity extends React.PureComponent { 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 } @@ -277,6 +281,7 @@ export default class ModalActivity extends React.PureComponent { selected={selected} isFirst={isFirst} onClick={this.changeTab.bind(this, i)} + data-test-id={`tab-${tab.id}`} > {tab.title} @@ -284,7 +289,7 @@ export default class ModalActivity extends React.PureComponent { }) } - + {tabs[this.state.currentTab].content()} diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc index 807617c5621d..26cc3e0d494b 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.cc @@ -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; @@ -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); } } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_util.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_util.cc index 4f3bcaf70d4d..9e08f64f9db5 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_util.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_util.cc @@ -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); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_util.h b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_util.h index 6ad715e53896..97904fb4c199 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_util.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution_util.h @@ -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