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

Add new tip dialog user interface #6626

Merged
merged 2 commits into from
Oct 16, 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
680 changes: 362 additions & 318 deletions browser/ui/webui/brave_tip_ui.cc

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions browser/ui/webui/brave_tip_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@

#include <string>

#include "base/macros.h"
#include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"

class BraveTipUI : public ConstrainedWebDialogUI {
public:
BraveTipUI(content::WebUI* web_ui, const std::string& host);
~BraveTipUI() override;

private:
DISALLOW_COPY_AND_ASSIGN(BraveTipUI);
BraveTipUI(const BraveTipUI&) = delete;
BraveTipUI& operator=(const BraveTipUI&) = delete;
};

#endif // BRAVE_BROWSER_UI_WEBUI_BRAVE_TIP_UI_H_
65 changes: 30 additions & 35 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "1bb9aa85741c6d1c077f043324aae835.svg", IDR_BRAVE_REWARDS_IMG_WELCOME_BG }, // NOLINT
{ "dcaf489409ca7908aef96547c9aad274.svg", IDR_BRAVE_REWARDS_IMG_TAP }, // NOLINT
}
}, {
std::string("tip"), {
{ "2e7994eaf768ee4a99272ea96cb39849.svg", IDR_BRAVE_REWARDS_TIP_BG_1 },
{ "4364e454dba7ea966b117f643832e871.svg", IDR_BRAVE_REWARDS_TIP_BG_2 },
}
#endif
}, {
std::string("welcome"), {
Expand Down Expand Up @@ -823,48 +818,48 @@ void CustomizeWebUIHTMLSource(const std::string &name,
}, {
#endif
std::string("tip"), {
{ "about", IDS_BRAVE_UI_ABOUT },
{ "addFunds", IDS_BRAVE_UI_ADD_FUNDS },
{ "autoTipText", IDS_BRAVE_UI_AUTO_TIP_TEXT },
{ "bat", IDS_BRAVE_UI_BAT_TEXT },
{ "bap", IDS_BRAVE_UI_BAP_REWARDS_TEXT },
{ "contributionAmount", IDS_BRAVE_UI_CONTRIBUTION_AMOUNT },
{ "contributionNextDate", IDS_BRAVE_REWARDS_LOCAL_CONTR_NEXT_DATE },
{ "donationAmount", IDS_BRAVE_UI_DONATION_AMOUNT },
{ "bapFunds", IDS_BRAVE_REWARDS_TIP_BAP_FUNDS },
{ "bat", IDS_BRAVE_UI_BAT_TEXT },
{ "batFunds", IDS_BRAVE_REWARDS_TIP_BAT_FUNDS },
{ "cancel", IDS_BRAVE_REWARDS_TIP_CANCEL },
{ "cancelConfirmationText", IDS_BRAVE_REWARDS_TIP_CANCEL_CONFIRMATION_TEXT }, // NOLINT
{ "cancelMonthlyContribution", IDS_BRAVE_REWARDS_TIP_CANCEL_MONTHLY_CONTRIBUTION }, // NOLINT
{ "changeAmount", IDS_BRAVE_REWARDS_TIP_CHANGE_AMOUNT },
{ "confirmCancel", IDS_BRAVE_REWARDS_TIP_CONFIRM_CANCEL },
{ "contributionAmount", IDS_BRAVE_REWARDS_TIP_CONTRIBUTION_AMOUNT }, // NOLINT
{ "contributionCanceled", IDS_BRAVE_REWARDS_TIP_CONTRIBUTION_CANCELED }, // NOLINT
{ "currentlySupporting", IDS_BRAVE_REWARDS_TIP_CURRENTLY_SUPPORTING },
{ "currentMonthlyContribution", IDS_BRAVE_REWARDS_TIP_CURRENT_MONTHLY_CONTRIBUTION }, // NOLINT
{ "doMonthly", IDS_BRAVE_UI_DO_MONTHLY },
{ "firstTipDateText", IDS_BRAVE_UI_FIRST_TIP_TEXT },
{ "makeMonthly", IDS_BRAVE_UI_MAKE_MONTHLY },
{ "errorHasOccurred", IDS_BRAVE_REWARDS_TIP_ERROR_HAS_OCCURRED },
{ "monthlyContribution", IDS_BRAVE_UI_MONTHLY_CONTRIBUTION },
{ "monthlyContributionSet", IDS_BRAVE_REWARDS_TIP_MONTHLY_CONTRIBUTION_SET }, // NOLINT
{ "monthlyText", IDS_BRAVE_UI_MONTHLY_TEXT },
{ "nextContributionDate", IDS_BRAVE_REWARDS_TIP_NEXT_CONTRIBUTION_DATE }, // NOLINT
{ "notEnoughTokens", IDS_BRAVE_UI_NOT_ENOUGH_TOKENS },
{ "notEnoughTokensLink", IDS_BRAVE_UI_NOT_ENOUGH_TOKENS_LINK },
{ "on", IDS_BRAVE_UI_ON },
{ "monthlyText", IDS_BRAVE_UI_MONTHLY_TEXT },
{ "monthlySet", IDS_BRAVE_UI_CONTRIBUTION_SET },
{ "redditTipTitle", IDS_BRAVE_UI_REDDIT_TIP_TITLE },
{ "redditTipTitleEmpty", IDS_BRAVE_UI_REDDIT_TIP_TITLE_EMPTY },
{ "githubTipTitle", IDS_BRAVE_UI_GITHUB_TIP_TITLE },
{ "githubTipTitleEmpty", IDS_BRAVE_UI_GITHUB_TIP_TITLE_EMPTY },
{ "monthlyContribution", IDS_BRAVE_UI_MONTHLY_CONTRIBUTION },
{ "nextContribution", IDS_BRAVE_UI_NEXT_CONTRIBUTION },
{ "oneTimeTip", IDS_BRAVE_REWARDS_TIP_ONE_TIME_TIP },
{ "oneTimeTipAmount", IDS_BRAVE_REWARDS_TIP_ONE_TIME_TIP_AMOUNT },
{ "points", IDS_BRAVE_UI_POINTS },
{ "postHeader", IDS_BRAVE_REWARDS_TIP_POST_HEADER },
{ "postHeaderTwitter", IDS_BRAVE_REWARDS_TIP_POST_HEADER_TWITTER },
{ "rewardsBannerText1", IDS_BRAVE_UI_REWARDS_BANNER_TEXT1 },
{ "rewardsBannerText2", IDS_BRAVE_UI_REWARDS_BANNER_TEXT2 },
{ "rewardsBannerMonthlyText1", IDS_BRAVE_UI_REWARDS_BANNER_MONTHLY_TEXT1 }, // NOLINT
{ "sendDonation", IDS_BRAVE_UI_SEND_DONATION },
{ "setContribution", IDS_BRAVE_UI_SET_CONTRIBUTION },
{ "shareText", IDS_BRAVE_UI_SHARE_TEXT },
{ "siteBannerConnectedText", IDS_BRAVE_UI_SITE_BANNER_CONNECTED_TEXT },
{ "siteBannerNoticeNote", IDS_BRAVE_UI_SITE_BANNER_NOTICE_NOTE },
{ "siteBannerNoticeText", IDS_BRAVE_UI_SITE_BANNER_NOTICE_TEXT },
{ "siteBannerConnectedText", IDS_BRAVE_UI_SITE_BANNER_CONNECTED_TEXT },
{ "tellOthers", IDS_BRAVE_UI_TELL_OTHERS },
{ "thankYou", IDS_BRAVE_UI_THANK_YOU },
{ "tipSent", IDS_BRAVE_UI_TIP_SENT },
{ "tipText", IDS_BRAVE_UI_TIP_TEXT },
{ "sorryToSeeYouGo", IDS_BRAVE_REWARDS_TIP_SORRY_TO_SEE_YOU_GO },
{ "supportThisCreator", IDS_BRAVE_REWARDS_TIP_SUPPORT_THIS_CREATOR },
{ "termsOfService", IDS_BRAVE_REWARDS_TIP_TERMS_OF_SERVICE },
{ "thanksForTheSupport", IDS_BRAVE_REWARDS_TIP_THANKS_FOR_THE_SUPPORT }, // NOLINT
{ "tipHasBeenSent", IDS_BRAVE_REWARDS_TIP_TIP_HAS_BEEN_SET },
{ "tipPostSubtitle", IDS_BRAVE_REWARDS_TIP_TIP_POST_SUBTITLE },
{ "tokens", IDS_BRAVE_UI_TOKENS },
{ "tweetNow", IDS_BRAVE_UI_TWEET_NOW },
{ "tweetTipTitle", IDS_BRAVE_UI_TWEET_TIP_TITLE },
{ "tweetTipTitleEmpty", IDS_BRAVE_UI_TWEET_TIP_TITLE_EMPTY },
{ "unVerifiedTextMore", IDS_BRAVE_UI_SITE_UNVERIFIED_TEXT_MORE },
{ "walletBalance", IDS_BRAVE_UI_WALLET_BALANCE },
{ "tweetAboutSupport", IDS_BRAVE_REWARDS_TIP_TWEET_ABOUT_SUPPORT },
{ "unverifiedTextMore", IDS_BRAVE_UI_SITE_UNVERIFIED_TEXT_MORE },
{ "welcome", IDS_BRAVE_UI_WELCOME },
}
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,16 @@ void IsMediaTipsInjected(content::WebContents* context, bool should_appear) {

std::vector<double> GetSiteBannerTipOptions(content::WebContents* context) {
DCHECK(context);
WaitForElementToAppear(context, "[data-test-id=amount-wrapper] div span");
WaitForElementToAppear(context, "[data-test-id=tip-amount-options]");
auto options = content::EvalJs(
context,
R"(
const delay = t => new Promise(resolve => setTimeout(resolve, t));
delay(500).then(() => Array.prototype.map.call(
document.querySelectorAll(
"[data-test-id=amount-wrapper] div span"),
node => parseFloat(node.innerText)))
delay(500).then(() => Array.from(
document.querySelectorAll(
"[data-test-id=tip-amount-options] [data-option-value]"
)
).map(node => parseFloat(node.dataset.optionValue)))
)",
content::EXECUTE_SCRIPT_DEFAULT_OPTIONS,
content::ISOLATED_WORLD_ID_CONTENT_END).ExtractList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@ void RewardsBrowserTestContribution::TipPublisher(
auto tip_options = rewards_browsertest_util::GetSiteBannerTipOptions(
site_banner_contents);
const double amount = tip_options.at(selection);
const std::string amount_str = base::StringPrintf("%.3f", amount);

// Select the tip amount (default is 1.000 BAT)
std::string amount_selector = base::StringPrintf(
"div:nth-of-type(%u)>[data-test-id=amount-wrapper]",
selection + 1);
"[data-test-id=tip-amount-options] [data-option-index='%u'] button",
selection);

rewards_browsertest_util::WaitForElementThenClick(
site_banner_contents,
amount_selector);

// Send the tip
rewards_browsertest_util::WaitForElementThenClick(
site_banner_contents,
"[data-test-id='send-tip-button']");
"[data-test-id=form-submit-button]");

// Signal that direct tip was made and update wallet with new
// balance
Expand All @@ -123,11 +123,6 @@ void RewardsBrowserTestContribution::TipPublisher(
// Wait for thank you banner to load
ASSERT_TRUE(WaitForLoadStop(site_banner_contents));

const std::string confirmationText =
type == rewards_browsertest_util::ContributionType::MonthlyTip
? "Monthly contribution has been set!"
: "Tip sent!";

if (type == rewards_browsertest_util::ContributionType::MonthlyTip) {
WaitForRecurringTipToBeSaved();
// Trigger contribution process
Expand Down Expand Up @@ -160,24 +155,15 @@ void RewardsBrowserTestContribution::TipPublisher(
}

// Make sure that thank you banner shows correct publisher data
// (domain and amount)
{
rewards_browsertest_util::WaitForElementToContain(
site_banner_contents,
"body",
confirmationText);
rewards_browsertest_util::WaitForElementToContain(
site_banner_contents,
"body",
amount_str + " BAT");
rewards_browsertest_util::WaitForElementToContain(
site_banner_contents,
"body",
"Share the good news:");
"Thanks for the support!");
rewards_browsertest_util::WaitForElementToContain(
site_banner_contents,
"body",
GetStringBalance());
base::StringPrintf("%.3f BAT", amount));
}

const bool is_monthly =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
<include name="IDR_BRAVE_REWARDS_INTERNALS_HTML" file="internals/brave_rewards_internals.html" type="BINDATA" />

<!-- WebUI Brave Rewards Tip resources -->
<include name="IDR_BRAVE_REWARDS_TIP_BG_1" file="tip/img/tip_bg_1.svg" type="BINDATA" />
<include name="IDR_BRAVE_REWARDS_TIP_BG_2" file="tip/img/tip_bg_2.svg" type="BINDATA" />
<include name="IDR_BRAVE_REWARDS_TIP_HTML" file="tip/brave_rewards_tip.html" type="BINDATA" />
<include name="IDR_BRAVE_REWARDS_TIP_HTML" file="tip/index.html" type="BINDATA" />
</includes>
</release>
</grit>
2 changes: 1 addition & 1 deletion components/brave_rewards/resources/tip/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import("//brave/components/common/typescript.gni")

transpile_web_ui("tip") {
entry_points = [
["brave_rewards_tip", rebase_path("brave_rewards_tip.tsx")]
["brave_rewards_tip", rebase_path("main.tsx")]
]

resource_name = "brave_rewards_tip"
Expand Down
71 changes: 0 additions & 71 deletions components/brave_rewards/resources/tip/actions/tip_actions.ts

This file was deleted.

Loading