Skip to content

Commit

Permalink
Adds 25 BAT limit for uphold
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jul 8, 2020
1 parent 99e9bb1 commit 92b0bbe
Show file tree
Hide file tree
Showing 30 changed files with 294 additions and 50 deletions.
1 change: 1 addition & 0 deletions browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ void BraveRewardsGetExternalWalletFunction::OnExternalWalet(
data->SetStringKey("withdrawUrl", wallet->withdraw_url);
data->SetStringKey("userName", wallet->user_name);
data->SetStringKey("accountUrl", wallet->account_url);
data->SetStringKey("loginUrl", wallet->login_url);
}

Respond(TwoArguments(
Expand Down
1 change: 1 addition & 0 deletions browser/ui/webui/brave_rewards_page_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,7 @@ void RewardsDOMHandler::OnGetExternalWallet(
wallet_dict.SetStringKey("withdrawUrl", wallet->withdraw_url);
wallet_dict.SetStringKey("userName", wallet->user_name);
wallet_dict.SetStringKey("accountUrl", wallet->account_url);
wallet_dict.SetStringKey("loginUrl", wallet->login_url);
}

data.SetKey("wallet", std::move(wallet_dict));
Expand Down
1 change: 1 addition & 0 deletions browser/ui/webui/brave_tip_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ void RewardsTipDOMHandler::OnExternalWallet(
data.SetString("withdrawUrl", wallet->withdraw_url);
data.SetString("userName", wallet->user_name);
data.SetString("accountUrl", wallet->account_url);
data.SetString("loginUrl", wallet->login_url);
data.SetInteger("status", static_cast<int>(wallet->status));
}

Expand Down
5 changes: 5 additions & 0 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "redirectModalError", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_ERROR },
{ "redirectModalClose", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_CLOSE },
{ "redirectModalErrorWallet", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_ERROR_WALLET }, // NOLINT
{ "redirectModalBatLimitTitle", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_BAT_LIMIT_TITLE }, // NOLINT
{ "redirectModalBatLimitText", IDS_BRAVE_REWARDS_LOCAL_REDIRECT_MODAL_BAT_LIMIT_TEXT }, // NOLINT

{ "click", IDS_BRAVE_REWARDS_LOCAL_ADS_CONFIRMATION_TYPE_CLICK },
{ "dismiss", IDS_BRAVE_REWARDS_LOCAL_ADS_CONFIRMATION_TYPE_DISMISS },
Expand Down Expand Up @@ -510,6 +512,9 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "import", IDS_BRAVE_UI_IMPORT },
{ "includeInAuto", IDS_BRAVE_UI_INCLUDE_IN_AUTO },
{ "learnMore", IDS_BRAVE_UI_LEARN_MORE },
{ "login", IDS_BRAVE_UI_LOGIN },
{ "loginMessageTitle", IDS_BRAVE_UI_LOGIN_MESSAGE_TITLE },
{ "loginMessageText", IDS_BRAVE_UI_LOGIN_MESSAGE_TEXT },
{ "makeMonthly", IDS_BRAVE_UI_MAKE_MONTHLY },
{ "manageWallet", IDS_BRAVE_UI_MANAGE_WALLET },
{ "markAsInappropriate", IDS_BRAVE_UI_ADS_MARK_AS_INAPPROPRIATE },
Expand Down
3 changes: 3 additions & 0 deletions common/extensions/api/brave_rewards.json
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,9 @@
},
"accountUrl": {
"type": "any"
},
"loginUrl": {
"type": "string"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions components/brave_rewards/browser/external_wallet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace brave_rewards {
withdraw_url = properties.withdraw_url;
user_name = properties.user_name;
account_url = properties.account_url;
login_url = properties.login_url;
}

std::string ExternalWallet::toJson() {
Expand All @@ -41,6 +42,7 @@ namespace brave_rewards {
dict.SetStringKey("withdraw_url", withdraw_url);
dict.SetStringKey("user_name", user_name);
dict.SetStringKey("account_url", account_url);
dict.SetStringKey("login_url", login_url);
base::JSONWriter::Write(dict, &json_wallet);
return json_wallet;
}
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/browser/external_wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct ExternalWallet {
std::string withdraw_url;
std::string user_name;
std::string account_url;
std::string login_url;
};

} // namespace brave_rewards
Expand Down
7 changes: 7 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3151,6 +3151,7 @@ void RewardsServiceImpl::SaveExternalWallet(const std::string& wallet_type,
new_wallet.SetStringKey("add_url", wallet->add_url);
new_wallet.SetStringKey("withdraw_url", wallet->withdraw_url);
new_wallet.SetStringKey("account_url", wallet->account_url);
new_wallet.SetStringKey("login_url", wallet->login_url);

new_wallets.SetKey(wallet_type, std::move(new_wallet));

Expand Down Expand Up @@ -3219,6 +3220,11 @@ RewardsServiceImpl::GetExternalWallets() {
wallet->account_url = *account_url;
}

auto* login_url = it.second.FindStringKey("login_url");
if (login_url) {
wallet->login_url = *login_url;
}

wallets.insert(std::make_pair(it.first, std::move(wallet)));
}

Expand All @@ -3243,6 +3249,7 @@ void RewardsServiceImpl::OnGetExternalWallet(
external->withdraw_url = wallet->withdraw_url;
external->user_name = wallet->user_name;
external->account_url = wallet->account_url;
external->login_url = wallet->login_url;
}

std::move(callback).Run(static_cast<int>(result), std::move(external));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ void RewardsBrowserTestPromotion::OnPromotionFinished(
}
}

void RewardsBrowserTestPromotion::WaitForUnblindedTokensReady() {
if (unblinded_tokens_) {
return;
}

wait_for_unblinded_tokens_loop_.reset(new base::RunLoop);
wait_for_unblinded_tokens_loop_->Run();
}

void RewardsBrowserTestPromotion::OnUnblindedTokensReady(
brave_rewards::RewardsService* rewards_service) {
unblinded_tokens_ = true;
if (wait_for_unblinded_tokens_loop_) {
wait_for_unblinded_tokens_loop_->Quit();
}
}

brave_rewards::Promotion RewardsBrowserTestPromotion::GetPromotion() {
return promotion_;
}
Expand All @@ -90,6 +107,7 @@ double RewardsBrowserTestPromotion::ClaimPromotionViaCode() {
solution,
base::DoNothing());
WaitForPromotionFinished();
WaitForUnblindedTokensReady();
return 30;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class RewardsBrowserTestPromotion

void WaitForPromotionFinished();

void WaitForUnblindedTokensReady();

brave_rewards::Promotion GetPromotion();

std::string GetPromotionId();
Expand All @@ -49,10 +51,15 @@ class RewardsBrowserTestPromotion
const uint32_t result,
brave_rewards::Promotion promotion) override;

void OnUnblindedTokensReady(
brave_rewards::RewardsService* rewards_service) override;

std::unique_ptr<base::RunLoop> wait_for_initialization_loop_;
bool initialized_ = false;
std::unique_ptr<base::RunLoop> wait_for_finished_loop_;
bool finished_ = false;
std::unique_ptr<base::RunLoop> wait_for_unblinded_tokens_loop_;
bool unblinded_tokens_ = false;

brave_rewards::Promotion promotion_;
Browser* browser_; // NOT OWNED
Expand Down
30 changes: 30 additions & 0 deletions components/brave_rewards/browser/test/rewards_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ IN_PROC_BROWSER_TEST_F(

IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, NotVerifiedWallet) {
rewards_browsertest_helper::EnableRewards(browser());
contribution_->AddBalance(promotion_->ClaimPromotionViaCode());
contribution_->IsBalanceCorrect();

// Click on verify button
rewards_browsertest_util::WaitForElementThenClick(
Expand Down Expand Up @@ -452,4 +454,32 @@ IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, ResetRewardsWithBAT) {
"Your 30 BATs and other Rewards");
}

IN_PROC_BROWSER_TEST_F(RewardsBrowserTest, UpholdLimitNoBAT) {
rewards_browsertest_helper::EnableRewards(browser());

rewards_browsertest_util::WaitForElementThenClick(
contents(),
"#verify-wallet-button");

rewards_browsertest_util::WaitForElementThenClick(
contents(),
"#cancel-login-button");

rewards_browsertest_util::WaitForElementThenClick(
contents(),
"#verify-wallet-button");

rewards_browsertest_util::WaitForElementThenClick(
contents(),
"#login-button");

// Check if we are redirected to uphold
{
const GURL current_url = contents()->GetURL();

auto found = current_url.spec().find("intention=login");
ASSERT_TRUE(found != std::string::npos);
}
}

} // namespace rewards_browsertest
Original file line number Diff line number Diff line change
Expand Up @@ -598,5 +598,21 @@
"example": "John"
}
}
},
"cancel": {
"message": "Cancel",
"description": "Text for cancel button"
},
"login": {
"message": "Login",
"description": "Text for login button"
},
"loginMessageTitle": {
"message": "Verifying wallet allows you to manage your funds more efficiently.",
"description": "Text for login button"
},
"loginMessageText": {
"message": "You need to have minimum 25 BAT to create an Uphold account. Please try again later. <br/> If you already have a verified Uphold account, continue to login.",
"description": "Text for login button"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ export const getUIMessages = (): Record<string, string> => {
'walletVerificationListHeader',
'walletVerificationTitle1',
'walletVerified',
'yourBalance'
'yourBalance',
'cancel',
'login',
'loginMessageTitle',
'loginMessageText'
]

let translations = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class RewardsPanel extends React.Component<Props, State> {
}

openRewardsAddFunds = () => {
const { externalWallet } = this.props.rewardsPanelData
const { externalWallet, balance } = this.props.rewardsPanelData

if (!externalWallet) {
return
Expand All @@ -254,10 +254,7 @@ export class RewardsPanel extends React.Component<Props, State> {
return
}

if (externalWallet.verifyUrl) {
utils.handleUpholdLink(externalWallet.verifyUrl, externalWallet)
return
}
utils.handleUpholdLink(balance, externalWallet)
}

openTOS () {
Expand Down Expand Up @@ -331,7 +328,7 @@ export class RewardsPanel extends React.Component<Props, State> {
let onVerifyClick = undefined
if (!this.state.onlyAnonWallet) {
walletStatus = utils.getWalletStatus(externalWallet)
onVerifyClick = utils.onVerifyClick.bind(this, this.actions)
onVerifyClick = utils.handleUpholdLink.bind(this, balance, externalWallet)
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class Panel extends React.Component<Props, State> {
}

onAddFunds = (notificationId?: string) => {
const { externalWallet } = this.props.rewardsPanelData
const { externalWallet, balance } = this.props.rewardsPanelData

if (notificationId) {
this.actions.deleteNotification(notificationId)
Expand All @@ -270,10 +270,7 @@ export class Panel extends React.Component<Props, State> {
return
}

if (externalWallet.verifyUrl) {
utils.handleUpholdLink(externalWallet.verifyUrl, externalWallet)
return
}
utils.handleUpholdLink(balance, externalWallet)
}

showTipSiteDetail = (monthly: boolean) => {
Expand Down Expand Up @@ -720,7 +717,7 @@ export class Panel extends React.Component<Props, State> {
let onVerifyClick = undefined
if (!this.props.onlyAnonWallet) {
walletStatus = utils.getWalletStatus(externalWallet)
onVerifyClick = utils.onVerifyClick.bind(this, this.actions)
onVerifyClick = utils.handleUpholdLink.bind(this, balance, externalWallet)
}

return (
Expand All @@ -745,6 +742,7 @@ export class Panel extends React.Component<Props, State> {
goToUphold={this.goToUphold}
greetings={utils.getGreetings(externalWallet)}
onlyAnonWallet={this.props.onlyAnonWallet}
showLoginMessage={balance.total < 25}
{...notification}
>
<WalletSummarySlider
Expand Down
29 changes: 13 additions & 16 deletions components/brave_rewards/resources/extension/brave_rewards/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,41 +147,38 @@ export const getGreetings = (externalWallet?: RewardsExtension.ExternalWallet) =
return getMessage('greetingsVerified', [externalWallet.userName])
}

export const handleUpholdLink = (link: string, externalWallet?: RewardsExtension.ExternalWallet) => {
export const handleUpholdLink = (balance: RewardsExtension.Balance, externalWallet?: RewardsExtension.ExternalWallet) => {
if (!externalWallet) {
return
}

let link = externalWallet.verifyUrl

if (!externalWallet || (externalWallet && externalWallet.status === 0)) {
link = 'brave://rewards/#verify'
}

if (balance.total < 25) {
link = externalWallet.loginUrl
}

chrome.tabs.create({
url: link
})
}

export const getExternalWallet = (actions: any, externalWallet?: RewardsExtension.ExternalWallet, open: boolean = false) => {
export const getExternalWallet = (actions: any, externalWallet?: RewardsExtension.ExternalWallet) => {
chrome.braveRewards.getExternalWallet('uphold', (result: number, wallet: RewardsExtension.ExternalWallet) => {
// EXPIRED TOKEN
if (result === 24) {
getExternalWallet(actions, externalWallet, open)
getExternalWallet(actions, externalWallet)
return
}

actions.onExternalWallet(wallet)

if (open && wallet.verifyUrl) {
handleUpholdLink(wallet.verifyUrl)
}
})
}

export const onVerifyClick = (actions: any, externalWallet?: RewardsExtension.ExternalWallet) => {
if (!externalWallet || externalWallet.verifyUrl) {
getExternalWallet(actions, externalWallet, true)
return
}

handleUpholdLink(externalWallet.verifyUrl)
}

export const getClaimedPromotions = (promotions: RewardsExtension.Promotion[]) => {
return promotions.filter((promotion: RewardsExtension.Promotion) => {
return promotion.status === 4 // PromotionStatus::FINISHED
Expand Down
Loading

0 comments on commit 92b0bbe

Please sign in to comment.