Skip to content

Commit

Permalink
BAT Points round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanml committed Nov 8, 2019
1 parent 644bc42 commit bea5b16
Show file tree
Hide file tree
Showing 37 changed files with 253 additions and 54 deletions.
18 changes: 18 additions & 0 deletions browser/ui/webui/brave_tip_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class RewardsTipDOMHandler : public WebUIMessageHandler,
void OnGetRecurringTips(
std::unique_ptr<brave_rewards::ContentSiteList> list);
void TweetTip(const base::ListValue *args);
void OnlyAnonWallet(const base::ListValue* args);
void GetExternalWallet(const base::ListValue* args);
void OnExternalWallet(
const int32_t result,
Expand Down Expand Up @@ -145,6 +146,11 @@ void RewardsTipDOMHandler::RegisterMessages() {
base::BindRepeating(
&RewardsTipDOMHandler::GetExternalWallet,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"brave_rewards_tip.onlyAnonWallet",
base::BindRepeating(
&RewardsTipDOMHandler::OnlyAnonWallet,
base::Unretained(this)));
}

void RewardsTipDOMHandler::GetPublisherTipData(
Expand Down Expand Up @@ -469,3 +475,15 @@ void RewardsTipDOMHandler::OnExternalWallet(
web_ui()->CallJavascriptFunctionUnsafe(
"brave_rewards_tip.externalWallet", data);
}

void RewardsTipDOMHandler::OnlyAnonWallet(const base::ListValue* args) {
if (!rewards_service_ || !web_ui()->CanCallJavascript()) {
return;
}

const bool allow = rewards_service_->OnlyAnonWallet();

web_ui()->CallJavascriptFunctionUnsafe(
"brave_rewards_tip.onlyAnonWallet",
base::Value(allow));
}
13 changes: 12 additions & 1 deletion browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ void CustomizeWebUIHTMLSource(const std::string &name,

// Rewards widget
{ "rewardsWidgetAnd", IDS_BRAVE_UI_AND },
{ "rewardsWidgetBap", IDS_BRAVE_UI_BAP_REWARDS_TEXT },
{ "rewardsWidgetBat", IDS_BRAVE_UI_BAT_REWARDS_TEXT },
{ "rewardsWidgetBatPoints", IDS_BRAVE_UI_BAT_POINTS_TEXT },
{ "rewardsWidgetBraveRewards", IDS_BRAVE_UI_BRAVE_REWARDS },
{ "rewardsWidgetPrivacyPolicy", IDS_BRAVE_UI_PRIVACY_POLICY },
{ "rewardsWidgetTermsOfService", IDS_BRAVE_UI_TERMS_OF_SERVICE },
Expand Down Expand Up @@ -260,6 +260,7 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "adsTitle", IDS_BRAVE_REWARDS_LOCAL_ADS_TITLE },

{ "bat", IDS_BRAVE_UI_BAT_REWARDS_TEXT },
{ "bap", IDS_BRAVE_UI_BAP_REWARDS_TEXT },
{ "batPoints", IDS_BRAVE_UI_BAT_POINTS_TEXT },
{ "batPointsMessage", IDS_BRAVE_UI_POINTS_MESSAGE },
{ "contributionTitle", IDS_BRAVE_REWARDS_LOCAL_CONTR_TITLE },
Expand Down Expand Up @@ -401,6 +402,7 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "grantFinishTitleUGP", IDS_BRAVE_UI_GRANT_FINISH_TITLE_UGP },
{ "grantFinishTokenAds", IDS_BRAVE_UI_GRANT_FINISH_TOKEN_ADS },
{ "grantFinishTokenUGP", IDS_BRAVE_UI_GRANT_FINISH_TOKEN_UGP },
{ "grantFinishPointUGP", IDS_BRAVE_UI_GRANT_FINISH_POINT_UGP },
{ "grants", IDS_BRAVE_UI_GRANTS },
{ "import", IDS_BRAVE_UI_IMPORT },
{ "includeInAuto", IDS_BRAVE_UI_INCLUDE_IN_AUTO },
Expand Down Expand Up @@ -455,6 +457,9 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "pinnedSitesThree", IDS_BRAVE_UI_PAYMENT_PINNED_SITES_THREE },
{ "pinnedSitesFour", IDS_BRAVE_UI_PAYMENT_PINNED_SITES_FOUR },
{ "pleaseNote", IDS_BRAVE_UI_PLEASE_NOTE },
{ "point", IDS_BRAVE_UI_POINT },
{ "pointGrantClaimed", IDS_BRAVE_UI_POINT_GRANT_CLAIMED },
{ "points", IDS_BRAVE_UI_POINTS },
{ "print", IDS_BRAVE_UI_PRINT },
{ "processingRequest", IDS_BRAVE_UI_PROCESSING_REQUEST },
{ "processingRequestButton", IDS_BRAVE_UI_PROCESSING_REQUEST_BUTTON },
Expand Down Expand Up @@ -520,7 +525,10 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "titleETH", IDS_BRAVE_UI_TITLE_ETH},
{ "titleLTC", IDS_BRAVE_UI_TITLE_LTC},
{ "tokenGrantClaimed", IDS_BRAVE_UI_TOKEN_GRANT_CLAIMED },
{ "token", IDS_BRAVE_UI_TOKEN },
{ "tokens", IDS_BRAVE_UI_TOKENS },
{ "tokenGrants", IDS_BRAVE_UI_TOKEN_GRANTS },
{ "pointGrants", IDS_BRAVE_UI_POINT_GRANTS },
{ "total", IDS_BRAVE_UI_TOTAL },
{ "transactions", IDS_BRAVE_UI_TRANSACTIONS },
{ "turnOnAds", IDS_BRAVE_UI_TURN_ON_ADS },
Expand Down Expand Up @@ -559,6 +567,7 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "welcomeButtonTextTwo", IDS_BRAVE_UI_WELCOME_BUTTON_TEXT_TWO},
{ "welcomeDescOne", IDS_BRAVE_UI_WELCOME_DESC_ONE},
{ "welcomeDescTwo", IDS_BRAVE_UI_WELCOME_DESC_TWO},
{ "welcomeDescPoints", IDS_BRAVE_UI_WELCOME_DESC_POINTS },
{ "welcomeFooterTextOne", IDS_BRAVE_UI_WELCOME_FOOTER_TEXT_ONE},
{ "welcomeFooterTextTwo", IDS_BRAVE_UI_WELCOME_FOOTER_TEXT_TWO},
{ "welcomeHeaderOne", IDS_BRAVE_UI_WELCOME_HEADER_ONE},
Expand Down Expand Up @@ -672,6 +681,7 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "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 },
{ "donationAmount", IDS_BRAVE_UI_DONATION_AMOUNT },
{ "doMonthly", IDS_BRAVE_UI_DO_MONTHLY },
{ "firstTipDateText", IDS_BRAVE_UI_FIRST_TIP_TEXT },
Expand All @@ -683,6 +693,7 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "redditTipTitleEmpty", IDS_BRAVE_UI_REDDIT_TIP_TITLE_EMPTY },
{ "githubTipTitle", IDS_BRAVE_UI_GITHUB_TIP_TITLE },
{ "githubTipTitleEmpty", IDS_BRAVE_UI_GITHUB_TIP_TITLE_EMPTY },
{ "points", IDS_BRAVE_UI_POINTS },
{ "rewardsBannerText1", IDS_BRAVE_UI_REWARDS_BANNER_TEXT1 },
{ "rewardsBannerText2", IDS_BRAVE_UI_REWARDS_BANNER_TEXT2 },
{ "sendDonation", IDS_BRAVE_UI_SEND_DONATION },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Rewards extends React.PureComponent<RewardsProps, {}> {
? totalContribution
: adsEstimatedEarnings.toFixed(1)
const converted = convertBalance(amount, rates)
const batFormatString = onlyAnonWallet ? getLocale('rewardsWidgetBatPoints') : getLocale('rewardsWidgetBat')
const batFormatString = onlyAnonWallet ? getLocale('rewardsWidgetBap') : getLocale('rewardsWidgetBat')

return (
<AmountItem isLast={type === AmountItemType.TIPS}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"message": "You can now earn tokens for watching privacy-respecting ads.",
"description": "Entry text for welcome screen in the panel, new user"
},
"welcomeDescPoints": {
"message": "You can now earn points for watching privacy-respecting ads.",
"description": "Entry text for welcome screen in the panel, points"
},
"welcomeFooterTextOne": {
"message": "Check out what’s improved",
"description": "Link in the footer (takes you to rewards settings page) for welcome screen in the panel, existing user"
Expand Down Expand Up @@ -144,13 +148,23 @@
"description": "Month"
},
"tokenGrant": {
"message": "Token Grants",
"description": "Title for grant notification"
"message": "$currency$ Grants",
"description": "Title for grant notification",
"placeholders": {
"currency": {
"content": "$1",
"example": "Token"
}
}
},
"tokenGrantClaimed": {
"message": "Token Grants Claimed",
"description": "Title for grant section in wallet summary"
},
"pointGrantClaimed": {
"message": "Point Grants Claimed",
"description": "Title for point grant section in wallet summary"
},
"earningsAds": {
"message": "Earnings from Ads",
"description": "Title for ads section in wallet summary"
Expand Down Expand Up @@ -196,12 +210,16 @@
"description": "Notification title when we display info about auto contribution"
},
"contributeNotificationSuccess": {
"message": "You've contributed $amount$ BAT",
"message": "You've contributed $amount$ $currency$",
"description": "We show this string in the notification when contribution is successful",
"placeholders": {
"amount": {
"content": "$1",
"example": "10.0"
},
"currency": {
"content": "$2",
"example": "BAT"
}
}
},
Expand Down Expand Up @@ -413,6 +431,10 @@
"message": "BAT",
"description": "BAT text for displaying converted tip amount."
},
"bap": {
"message": "BAP",
"description": "BAT Points abbreviation text"
},
"turnOnAds": {
"message": "Turn on Ads",
"description": "Prompt to turn on Ads via notification"
Expand Down Expand Up @@ -468,13 +490,23 @@
"description": "Cosmetic text upon captcha success"
},
"grantFinishTextUGP": {
"message": "Your token grant is on its way.",
"description": "Cosmetic text indicating grant funds are on the way"
"message": "Your $currency$ grant is on its way.",
"description": "Cosmetic text indicating grant funds are on the way",
"placeholders": {
"currency": {
"content": "$1",
"example": "token"
}
}
},
"grantFinishTokenTitleUGP": {
"message": "Free Token Grant",
"description": "Token title on success screen"
},
"grantFinishPointTitleUGP": {
"message": "Free Point Grant",
"description": "Point title on success screen"
},
"grantFinishTitleAds": {
"message": "You've earned an Ads Reward!",
"description": "Cosmetic text upon captcha success for ads"
Expand Down Expand Up @@ -544,5 +576,29 @@
"walletGoToVerifyPage": {
"message": "Complete wallet verification",
"description": "CTA for completing wallet verification"
},
"tokens": {
"message": "tokens",
"description": "Standard tokens text"
},
"point": {
"message": "Point",
"description": "BAT Point text"
},
"token": {
"message": "Token",
"description": "BAT Token text"
},
"points": {
"message": "points",
"description": "BAT Points text"
},
"tokenGrants": {
"message": "Token Grants",
"description": "BAT Tokens Grant Text"
},
"pointGrants": {
"message": "Point Grants",
"description": "BAT Points Grant Text"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const getUIMessages = (): Record<string, string> => {
'backupWalletNotification',
'backupWalletTitle',
'bat',
'bap',
'batPoints',
'batPointsMessage',
'braveAdsLaunchTitle',
Expand Down Expand Up @@ -83,6 +84,9 @@ export const getUIMessages = (): Record<string, string> => {
'on',
'oneTimeDonation',
'pendingContributionTitle',
'point',
'pointGrantClaimed',
'points',
'privacyPolicy',
'recurringDonations',
'reservedAmountText',
Expand All @@ -96,6 +100,10 @@ export const getUIMessages = (): Record<string, string> => {
'tipsProcessedNotification',
'tokenGrant',
'tokenGrantClaimed',
'token',
'tokens',
'tokenGrants',
'pointGrants',
'unVerifiedCheck',
'turnOnAds',
'unVerifiedPublisher',
Expand All @@ -107,6 +115,7 @@ export const getUIMessages = (): Record<string, string> => {
'welcomeButtonTextTwo',
'welcomeDescOne',
'welcomeDescTwo',
'welcomeDescPoints',
'walletFailedButton',
'walletFailedTitle',
'welcomeBack',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export class RewardsPanel extends React.Component<Props, State> {
optInErrorAction={this.onCreate}
moreLink={this.openRewards}
onTOSClick={this.openTOS}
onlyAnonWallet={this.state.onlyAnonWallet}
onPrivacyClick={this.openPrivacyPolicy}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export class Panel extends React.Component<Props, State> {

getNotification = () => {
const { notifications, currentNotification } = this.props.rewardsPanelData
const { onlyAnonWallet } = this.props

if (
currentNotification === undefined ||
Expand Down Expand Up @@ -335,8 +336,9 @@ export class Panel extends React.Component<Props, State> {
// 16 - error while tipping

if (result === '0') {
const currency = onlyAnonWallet ? getMessage('bap') : getMessage('bat')
const fixed = utils.convertProbiToFixed(notification.args[3])
text = getMessage('contributeNotificationSuccess', [fixed])
text = getMessage('contributeNotificationSuccess', [fixed, currency])
} else if (result === '15') {
text = getMessage('contributeNotificationNotEnoughFunds')
isAlert = 'warning'
Expand Down Expand Up @@ -624,6 +626,7 @@ export class Panel extends React.Component<Props, State> {
const tipAmounts = defaultContribution !== '0.0'
? this.generateAmounts(publisher)
: undefined
const { onlyAnonWallet } = this.props

if (notification &&
notification.notification &&
Expand All @@ -642,7 +645,7 @@ export class Panel extends React.Component<Props, State> {
}
}

currentGrant = utils.getGrant(currentGrant)
currentGrant = utils.getGrant(currentGrant, this.props.onlyAnonWallet)

let walletStatus: WalletState | undefined = undefined
let onVerifyClick = undefined
Expand Down Expand Up @@ -703,6 +706,7 @@ export class Panel extends React.Component<Props, State> {
onRefreshPublisher={this.refreshPublisher}
refreshingPublisher={this.state.refreshingPublisher}
publisherRefreshed={this.state.publisherRefreshed}
onlyAnonWallet={onlyAnonWallet}
/>
: null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ export const getGrants = (grants?: RewardsExtension.Grant[]) => {
})
}

export const getGrant = (grant?: RewardsExtension.GrantInfo) => {
export const getGrant = (grant?: RewardsExtension.GrantInfo, onlyAnonWallet?: boolean) => {
if (!grant) {
return grant
}

const tokenString = onlyAnonWallet ? getMessage('point') : getMessage('token')
grant.finishTitle = getMessage('grantFinishTitleUGP')
grant.finishText = getMessage('grantFinishTextUGP')
grant.finishTokenTitle = getMessage('grantFinishTokenTitleUGP')
grant.finishText = getMessage('grantFinishTextUGP', [tokenString])
grant.finishTokenTitle = onlyAnonWallet
? getMessage('grantFinishPointTitleUGP')
: getMessage('grantFinishTokenTitleUGP')

if (grant.type === 'ads') {
grant.expiryTime = 0
Expand Down
8 changes: 6 additions & 2 deletions components/brave_rewards/resources/page/components/adsBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ class AdsBox extends React.Component<Props, State> {
adsHistory,
enabledMain,
firstLoad,
balance
balance,
ui
} = this.props.rewardsData
const { onlyAnonWallet } = ui

if (adsData) {
adsEnabled = adsData.adsEnabled
Expand All @@ -283,13 +285,14 @@ class AdsBox extends React.Component<Props, State> {
const historyEntries = adsHistory || []
const rows = this.getAdHistoryData(historyEntries, savedOnly)
const notEmpty = rows && rows.length !== 0
const tokenString = getLocale(onlyAnonWallet ? 'points' : 'tokens')

return (
<>
<Box
title={getLocale('adsTitle')}
type={'ads'}
description={getLocale('adsDesc')}
description={getLocale('adsDesc', { currency: tokenString })}
toggle={toggle}
checked={enabled}
settingsChild={this.adsSettings(enabled && enabledMain)}
Expand All @@ -302,6 +305,7 @@ class AdsBox extends React.Component<Props, State> {
>
<List title={getLocale('adsCurrentEarnings')}>
<Tokens
onlyAnonWallet={onlyAnonWallet}
value={estimatedPendingRewards}
converted={utils.convertBalance(estimatedPendingRewards, balance.rates)}
/>
Expand Down
Loading

0 comments on commit bea5b16

Please sign in to comment.