diff --git a/components/brave_rewards/browser/rewards_service_browsertest.cc b/components/brave_rewards/browser/rewards_service_browsertest.cc index 098ab52d6907..70cb0fb691e2 100644 --- a/components/brave_rewards/browser/rewards_service_browsertest.cc +++ b/components/brave_rewards/browser/rewards_service_browsertest.cc @@ -780,15 +780,13 @@ class BraveRewardsBrowserTest : void TipPublisher( const std::string& publisher, - ledger::PublisherStatus status = ledger::PublisherStatus::NOT_VERIFIED, + bool should_contribute = false, bool monthly = false, int32_t selection = 0) { // we shouldn't be adding publisher to AC list, // so that we can focus only on tipping part rewards_service_->SetPublisherMinVisitTime(8); - const bool should_contribute = status == ledger::PublisherStatus::VERIFIED; - // Navigate to a site in a new tab GURL url = https_server()->GetURL(publisher, "/index.html"); ui_test_utils::NavigateToURLWithDisposition( @@ -1719,7 +1717,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, TipVerifiedPublisher) { ClaimGrant(use_panel); // Tip verified publisher - TipPublisher("duckduckgo.com", ledger::PublisherStatus::VERIFIED); + TipPublisher("duckduckgo.com", true); // Stop observing the Rewards service rewards_service_->RemoveObserver(this); @@ -1759,7 +1757,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, // Tip verified publisher const bool monthly = true; - TipPublisher("duckduckgo.com", ledger::PublisherStatus::VERIFIED, monthly); + TipPublisher("duckduckgo.com", true, monthly); // Stop observing the Rewards service rewards_service_->RemoveObserver(this); @@ -1780,7 +1778,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, // Tip verified publisher const bool monthly = true; - TipPublisher("brave.com", ledger::PublisherStatus::NOT_VERIFIED, monthly); + TipPublisher("brave.com", false, monthly); // Stop observing the Rewards service rewards_service_->RemoveObserver(this); @@ -2225,26 +2223,10 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, TipPublisher("brave.com"); rewards_service_->OnTip("brave.com", 5.0, false); UpdateContributionBalance(5.0, false); // update pending balance - TipPublisher( - "3zsistemi.si", - ledger::PublisherStatus::NOT_VERIFIED, - false, - 2); - TipPublisher( - "3zsistemi.si", - ledger::PublisherStatus::NOT_VERIFIED, - false, - 1); - TipPublisher( - "3zsistemi.si", - ledger::PublisherStatus::NOT_VERIFIED, - false, - 2); - TipPublisher( - "3zsistemi.si", - ledger::PublisherStatus::NOT_VERIFIED, - false, - 2); + TipPublisher("3zsistemi.si", false, false, 2); + TipPublisher("3zsistemi.si", false, false, 1); + TipPublisher("3zsistemi.si", false, false, 2); + TipPublisher("3zsistemi.si", false, false, 2); // Make sure that pending contribution box shows the correct // amount @@ -2454,13 +2436,13 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, EnableRewards(); // Tip verified publisher - TipPublisher("duckduckgo.com", ledger::PublisherStatus::VERIFIED); + TipPublisher("duckduckgo.com", true); // Stop observing the Rewards service rewards_service()->RemoveObserver(this); } -IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, TipConnectedPublisher) { +IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, TipConnectedPublisherAnon) { // Observe the Rewards service rewards_service_->AddObserver(this); @@ -2472,7 +2454,92 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, TipConnectedPublisher) { ClaimGrant(use_panel); // Tip verified publisher - TipPublisher("bumpsmack.com", ledger::PublisherStatus::CONNECTED); + TipPublisher("bumpsmack.com", true); + + // Stop observing the Rewards service + rewards_service_->RemoveObserver(this); +} + +IN_PROC_BROWSER_TEST_F( + BraveRewardsBrowserTest, + TipConnectedPublisherAnonAndConnected) { + // Observe the Rewards service + rewards_service()->AddObserver(this); + verified_wallet_ = true; + external_balance_ = 50.0; + + auto wallet = ledger::ExternalWallet::New(); + wallet->token = "token"; + wallet->address = external_wallet_address_; + wallet->status = 1; + wallet->one_time_string = ""; + wallet->user_name = "Brave Test"; + wallet->transferred = true; + rewards_service()->SaveExternalWallet("uphold", std::move(wallet)); + + // Enable Rewards + EnableRewards(); + + // Claim grant using settings page + const bool use_panel = true; + ClaimGrant(use_panel); + + // Tip verified publisher + TipPublisher("bumpsmack.com", true); + + // Stop observing the Rewards service + rewards_service_->RemoveObserver(this); +} + +IN_PROC_BROWSER_TEST_F( + BraveRewardsBrowserTest, + TipConnectedPublisherConnected) { + // Observe the Rewards service + rewards_service()->AddObserver(this); + verified_wallet_ = true; + external_balance_ = 50.0; + + auto wallet = ledger::ExternalWallet::New(); + wallet->token = "token"; + wallet->address = external_wallet_address_; + wallet->status = 1; + wallet->one_time_string = ""; + wallet->user_name = "Brave Test"; + wallet->transferred = true; + rewards_service()->SaveExternalWallet("uphold", std::move(wallet)); + + // Enable Rewards + EnableRewards(); + + // Tip verified publisher + TipPublisher("bumpsmack.com", false); + + // Stop observing the Rewards service + rewards_service_->RemoveObserver(this); +} + +IN_PROC_BROWSER_TEST_F( + BraveRewardsBrowserTest, + TipConnectedPublisherVerified) { + // Observe the Rewards service + rewards_service()->AddObserver(this); + verified_wallet_ = true; + external_balance_ = 50.0; + + auto wallet = ledger::ExternalWallet::New(); + wallet->token = "token"; + wallet->address = external_wallet_address_; + wallet->status = 2; + wallet->one_time_string = ""; + wallet->user_name = "Brave Test"; + wallet->transferred = true; + rewards_service()->SaveExternalWallet("uphold", std::move(wallet)); + + // Enable Rewards + EnableRewards(); + + // Tip verified publisher + TipPublisher("bumpsmack.com", false); // Stop observing the Rewards service rewards_service_->RemoveObserver(this); diff --git a/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json b/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json index 2290fb4e2bf6..1920159b131a 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json +++ b/components/brave_rewards/resources/extension/brave_rewards/_locales/en_US/messages.json @@ -522,7 +522,7 @@ "description": "Title for notification when wallet is disconnected" }, "connectedText": { - "message": "This verified creator has yet to verify (KYC) their account to receive tips from your verified wallet. Tips will remain in your wallet until they complete verification.", + "message": "This Brave Verified Creator has not yet configured their account to receive contributions from Brave Users. Any tips you send will remain in your wallet until they complete this process.", "description": "Text shown for connected publishers that are not fully verified in the panel" }, "walletGoToVerifyPage": { diff --git a/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx b/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx index 819bced18f62..a90c12181d1b 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx +++ b/components/brave_rewards/resources/extension/brave_rewards/components/panel.tsx @@ -564,6 +564,29 @@ export class Panel extends React.Component { chrome.braveRewards.disconnectWallet('uphold') } + shouldShowConnectedMessage = () => { + const { externalWallet, balance } = this.props.rewardsPanelData + const { wallets } = balance + const publisher: RewardsExtension.Publisher | undefined = this.getPublisher() + const notVerified = publisher && utils.isPublisherNotVerified(publisher.status) + const connected = publisher && utils.isPublisherConnected(publisher.status) + const status = utils.getWalletStatus(externalWallet) + + if (notVerified) { + return true + } + + if (connected && (status === 'unverified' || + status === 'disconnected_unverified' || + status === 'disconnected_verified')) { + return false + } + + const hasAnonBalance = wallets['anonymous'] && wallets['anonymous'] > 0 + + return connected && !hasAnonBalance + } + render () { const { pendingContributionTotal, enabledAC, externalWallet, balance } = this.props.rewardsPanelData const { rates } = this.props.rewardsPanelData.balance @@ -578,8 +601,6 @@ export class Panel extends React.Component { let { currentGrant } = this.props.rewardsPanelData const defaultContribution = this.getContribution(publisher) const checkmark = publisher && utils.isPublisherConnectedOrVerified(publisher.status) - const connected = publisher && utils.isPublisherConnected(publisher.status) - const notVerified = publisher && utils.isPublisherNotVerified(publisher.status) const tipAmounts = defaultContribution !== '0.0' ? this.generateAmounts(publisher) : undefined @@ -658,7 +679,7 @@ export class Panel extends React.Component { donationAction={this.showTipSiteDetail} onAmountChange={this.onContributionAmountChange} onIncludeInAuto={this.switchAutoContribute} - showUnVerified={connected || notVerified} + showUnVerified={this.shouldShowConnectedMessage()} acEnabled={enabledAC} donationAmounts={tipAmounts} moreLink={'https://brave.com/faq/#unclaimed-funds'} diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index 8402a15f0701..cbaa84b88d63 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -544,7 +544,7 @@ Creating wallet NOTE: This creator has not yet signed up to receive contributions from Brave users. Your browser will keep trying to contribute until they verify, or until 90 days have passed. - This verified creator has yet to verify (KYC) their account to receive tips from your verified wallet. Tips will remain in your wallet until they complete verification. + This Brave Verified Creator has not yet configured their account to receive contributions from Brave users. Your browser will keep trying to contribute until they verify, or until 90 days have passed. Learn more. earned from ads Pending contributions 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 518c63f2fa28..7d4c0706e3c7 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 @@ -227,7 +227,7 @@ ledger::PublisherInfoList Contribution::GetVerifiedListRecurring( continue; } - if (publisher->status == ledger::PublisherStatus::VERIFIED) { + if (publisher->status != ledger::PublisherStatus::NOT_VERIFIED) { verified.push_back(publisher->Clone()); *budget += publisher->weight; } else { @@ -692,6 +692,24 @@ void Contribution::DoDirectTip( ledger_->GetServerPublisherInfo(publisher_key, server_callback); } +void Contribution::SavePendingContribution( + const std::string& publisher_key, + double amount, + ledger::REWARDS_CATEGORY category, + ledger::SavePendingContributionCallback callback) { + auto contribution = ledger::PendingContribution::New(); + contribution->publisher_key = publisher_key; + contribution->amount = amount; + contribution->category = category; + + ledger::PendingContributionList list; + list.push_back(std::move(contribution)); + + ledger_->SaveUnverifiedContribution( + std::move(list), + callback); +} + void Contribution::OnDoDirectTipServerPublisher( ledger::ServerPublisherInfoPtr server_info, const std::string& publisher_key, @@ -704,17 +722,11 @@ void Contribution::OnDoDirectTipServerPublisher( } // Save to the pending list if not verified - if (status != ledger::PublisherStatus::VERIFIED) { - auto contribution = ledger::PendingContribution::New(); - contribution->publisher_key = publisher_key; - contribution->amount = amount; - contribution->category = ledger::REWARDS_CATEGORY::ONE_TIME_TIP; - - ledger::PendingContributionList list; - list.push_back(std::move(contribution)); - - ledger_->SaveUnverifiedContribution( - std::move(list), + if (status == ledger::PublisherStatus::NOT_VERIFIED) { + SavePendingContribution( + publisher_key, + static_cast(amount), + ledger::REWARDS_CATEGORY::ONE_TIME_TIP, callback); return; } @@ -1001,7 +1013,54 @@ void Contribution::OnExternalWallets( return; } - uphold_->StartContribution(viewing_id, std::move(wallet)); + for (const auto& item : reconcile.directions_) { + auto callback = + std::bind(&Contribution::OnExternalWalletServerPublisherInfo, + this, + _1, + viewing_id, + item.amount_, + *wallet); + + ledger_->GetServerPublisherInfo(item.publisher_key_, callback); + } +} + +void Contribution::OnExternalWalletServerPublisherInfo( + ledger::ServerPublisherInfoPtr info, + const std::string& viewing_id, + int amount, + const ledger::ExternalWallet& wallet) { + const auto reconcile = ledger_->GetReconcileById(viewing_id); + if (!info) { + const auto probi = + braveledger_uphold::ConvertToProbi(std::to_string(amount)); + ledger_->OnReconcileComplete( + ledger::Result::LEDGER_ERROR, + viewing_id, + probi, + reconcile.category_); + + if (!viewing_id.empty()) { + ledger_->RemoveReconcileById(viewing_id); + } + return; + } + + if (info->status != ledger::PublisherStatus::VERIFIED) { + SavePendingContribution( + info->publisher_key, + static_cast(amount), + static_cast(reconcile.category_), + [](const ledger::Result _){}); + return; + } + + uphold_->StartContribution( + viewing_id, + info->address, + static_cast(amount), + ledger::ExternalWallet::New(wallet)); } void Contribution::OnUpholdAC(ledger::Result result, diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.h b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.h index 5b163a90833e..d72c83f882cf 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/contribution/contribution.h @@ -247,6 +247,12 @@ class Contribution { ledger::BalancePtr properties, ledger::HasSufficientBalanceToReconcileCallback callback); + void SavePendingContribution( + const std::string& publisher_key, + double amount, + ledger::REWARDS_CATEGORY category, + ledger::SavePendingContributionCallback callback); + void OnDoDirectTipServerPublisher( ledger::ServerPublisherInfoPtr server_info, const std::string& publisher_key, @@ -285,6 +291,12 @@ class Contribution { base::flat_map wallet_balances, std::map wallets); + void OnExternalWalletServerPublisherInfo( + ledger::ServerPublisherInfoPtr info, + const std::string& viewing_id, + int amount, + const ledger::ExternalWallet& wallet); + void OnUpholdAC(ledger::Result result, bool created, const std::string& viewing_id); diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc index 58ce05566d8e..6649f1dd9866 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.cc @@ -34,48 +34,30 @@ Uphold::Uphold(bat_ledger::LedgerImpl* ledger) : Uphold::~Uphold() { } -void Uphold::StartContribution(const std::string& viewing_id, - ledger::ExternalWalletPtr wallet) { - const auto reconcile = ledger_->GetReconcileById(viewing_id); - - for (const auto& item : reconcile.directions_) { - auto callback = std::bind(&Uphold::OnServerPublisherInfo, - this, - _1, - viewing_id, - item.amount_, - *wallet); - - ledger_->GetServerPublisherInfo(item.publisher_key_, callback); - } -} - -void Uphold::OnServerPublisherInfo( - ledger::ServerPublisherInfoPtr info, +void Uphold::StartContribution( const std::string& viewing_id, - int amount, - const ledger::ExternalWallet& wallet) { - if (!info || info->address.empty()) { + const std::string& address, + double amount, + ledger::ExternalWalletPtr wallet) { + if (address.empty()) { ContributionCompleted(ledger::Result::LEDGER_ERROR, false, viewing_id); return; } - const double amount_double = static_cast(amount); - const double fee = (amount_double * 1.05) - amount_double; - const double reconcile_amount = amount_double - fee; + const double fee = (amount * 1.05) - amount; + const double reconcile_amount = amount - fee; - // rest of the reconcile auto contribution_callback = std::bind(&Uphold::ContributionCompleted, this, _1, _2, viewing_id, fee, - wallet); + *wallet); transfer_->Start(reconcile_amount, - info->address, - ledger::ExternalWallet::New(wallet), + address, + std::move(wallet), contribution_callback); } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.h b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.h index 4659b7ba6c47..ae1ebf4964a3 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.h +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/uphold/uphold.h @@ -37,8 +37,11 @@ class Uphold { ~Uphold(); - void StartContribution(const std::string &viewing_id, - ledger::ExternalWalletPtr wallet); + void StartContribution( + const std::string& viewing_id, + const std::string& address, + double amount, + ledger::ExternalWalletPtr wallet); void FetchBalance(std::map wallets, FetchBalanceCallback callback); @@ -77,12 +80,6 @@ class Uphold { CreateAnonAddressCallback callback); private: - void OnServerPublisherInfo( - ledger::ServerPublisherInfoPtr info, - const std::string& viewing_id, - int amount, - const ledger::ExternalWallet& wallet); - void ContributionCompleted( const ledger::Result result, const bool created,