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

Handles anon wallet connected publisher case #3399

Merged
merged 1 commit into from
Sep 16, 2019
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
125 changes: 96 additions & 29 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,29 @@ export class Panel extends React.Component<Props, State> {
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 } = this.props.rewardsPanelData
const { total, rates } = this.props.rewardsPanelData.balance
Expand All @@ -577,8 +600,6 @@ export class Panel extends React.Component<Props, State> {
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
Expand Down Expand Up @@ -657,7 +678,7 @@ export class Panel extends React.Component<Props, State> {
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'}
Expand Down
2 changes: 1 addition & 1 deletion components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@
<message name="IDS_BRAVE_UI_REWARDS_CREATING_TEXT" desc="">Creating wallet</message>
<message name="IDS_BRAVE_UI_SITE_BANNER_NOTICE_NOTE" desc="">NOTE:</message>
<message name="IDS_BRAVE_UI_SITE_BANNER_NOTICE_TEXT" desc="">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.</message>
<message name="IDS_BRAVE_UI_SITE_BANNER_CONNECTED_TEXT" desc="Text shown for connected publishers that are not fully verified on site banner">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>
<message name="IDS_BRAVE_UI_SITE_BANNER_CONNECTED_TEXT" desc="Text shown for connected publishers that are not fully verified on site banner">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.</message>
<message name="IDS_BRAVE_UI_SITE_UNVERIFIED_TEXT_MORE" desc="">Learn more.</message>
<message name="IDS_BRAVE_UI_ADS_EARNINGS" desc="Description text for ad grants in grant details">earned from ads</message>
<message name="IDS_BRAVE_UI_PENDING_CONTRIBUTIONS" desc="Title of pending contribution modal">Pending contributions</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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<double>(amount),
ledger::REWARDS_CATEGORY::ONE_TIME_TIP,
callback);
return;
}
Expand Down Expand Up @@ -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<double>(amount),
static_cast<ledger::REWARDS_CATEGORY>(reconcile.category_),
[](const ledger::Result _){});
return;
}

uphold_->StartContribution(
viewing_id,
info->address,
static_cast<double>(amount),
ledger::ExternalWallet::New(wallet));
}

void Contribution::OnUpholdAC(ledger::Result result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -285,6 +291,12 @@ class Contribution {
base::flat_map<std::string, double> wallet_balances,
std::map<std::string, ledger::ExternalWalletPtr> 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);
Expand Down
Loading