Skip to content

Add support for payout status #14063

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

Merged
merged 1 commit into from
Jul 11, 2022
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
11 changes: 8 additions & 3 deletions browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,11 @@ BraveRewardsGetRewardsParametersFunction::Run() {
}

rewards_service->GetRewardsParameters(base::BindOnce(
&BraveRewardsGetRewardsParametersFunction::OnGet,
this));
&BraveRewardsGetRewardsParametersFunction::OnGetRewardsParameters, this));
return RespondLater();
}

void BraveRewardsGetRewardsParametersFunction::OnGet(
void BraveRewardsGetRewardsParametersFunction::OnGetRewardsParameters(
ledger::type::RewardsParametersPtr parameters) {
base::DictionaryValue data;

Expand All @@ -604,6 +603,12 @@ void BraveRewardsGetRewardsParametersFunction::OnGet(
}
data.SetList("autoContributeChoices", std::move(ac_choices));

auto payout_status = std::make_unique<base::DictionaryValue>();
for (const auto& [key, value] : parameters->payout_status) {
payout_status->SetString(key, value);
}
data.Set("payoutStatus", std::move(payout_status));

Respond(OneArgument(std::move(data)));
}

Expand Down
2 changes: 1 addition & 1 deletion browser/extensions/api/brave_rewards_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class BraveRewardsGetRewardsParametersFunction : public ExtensionFunction {
ResponseAction Run() override;

private:
void OnGet(ledger::type::RewardsParametersPtr parameters);
void OnGetRewardsParameters(ledger::type::RewardsParametersPtr parameters);
};

class BraveRewardsGetBalanceReportFunction : public ExtensionFunction {
Expand Down
19 changes: 13 additions & 6 deletions browser/ui/webui/brave_rewards_page_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,21 @@ void RewardsDOMHandler::OnGetRewardsParameters(

base::DictionaryValue data;
if (parameters) {
auto choices = std::make_unique<base::ListValue>();
for (double const& choice : parameters->auto_contribute_choices) {
choices->Append(choice);
base::ListValue auto_contribute_choices;
for (double const& item : parameters->auto_contribute_choices) {
auto_contribute_choices.Append(item);
}

data.SetDouble("rate", parameters->rate);
data.SetDouble("autoContributeChoice", parameters->auto_contribute_choice);
data.SetList("autoContributeChoices", std::move(choices));
base::DictionaryValue payout_status;
for (const auto& [key, value] : parameters->payout_status) {
payout_status.SetStringKey(key, value);
}

data.SetDoubleKey("rate", parameters->rate);
data.SetDoubleKey("autoContributeChoice",
parameters->auto_contribute_choice);
data.SetKey("autoContributeChoices", std::move(auto_contribute_choices));
data.SetKey("payoutStatus", std::move(payout_status));
}
CallJavascriptFunction("brave_rewards.rewardsParameters", data);
}
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/webui/brave_tip_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,16 @@ void TipMessageHandler::GetRewardsParametersCallback(
ac_choices.Append(item);
}

base::Value payout_status(base::Value::Type::DICTIONARY);
for (const auto& item : parameters->payout_status) {
payout_status.SetStringKey(item.first, item.second);
}

data.SetDoubleKey("rate", parameters->rate);
data.SetKey("tipChoices", std::move(tip_choices));
data.SetKey("monthlyTipChoices", std::move(monthly_choices));
data.SetKey("autoContributeChoices", std::move(ac_choices));
data.SetKey("payoutStatus", std::move(payout_status));
}

FireWebUIListener("rewardsParametersUpdated", data);
Expand Down
8 changes: 7 additions & 1 deletion common/extensions/api/brave_rewards.json
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@
{
"name": "getRewardsParameters",
"type": "function",
"description": "Get default values that we get from the server",
"description": "Get default Rewards parameters",
"parameters": [
{
"type": "function",
Expand Down Expand Up @@ -734,6 +734,12 @@
"type": "number",
"minimum": 0
}
},
"payoutStatus": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions components/brave_new_tab_ui/components/default/rewards/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import * as React from 'react'

Expand All @@ -9,6 +9,7 @@ import createWidget from '../widget/index'
import { StyledTitleTab } from '../widgetTitleTab'

import { LocaleContext } from '../../../../brave_rewards/resources/shared/lib/locale_context'
import { getProviderPayoutStatus } from '../../../../brave_rewards/resources/shared/lib/provider_payout_status'
import { WithThemeVariables } from '../../../../brave_rewards/resources/shared/components/with_theme_variables'
import { GrantInfo } from '../../../../brave_rewards/resources/shared/lib/grant_info'
import { OnboardingCompletedStore } from '../../../../brave_rewards/resources/shared/lib/onboarding_completed_store'
Expand Down Expand Up @@ -92,6 +93,12 @@ export const RewardsWidget = createWidget((props: RewardsProps) => {
const adsInfo = props.adsAccountStatement || null
const grantInfo = getVisibleGrant(props.promotions || [])

const externalWallet = externalWalletFromExtensionData(props.externalWallet)
const walletProvider = externalWallet ? externalWallet.provider : null
const providerPayoutStatus = props.parameters.payoutStatus
? getProviderPayoutStatus(props.parameters.payoutStatus, walletProvider)
: 'off'

const onClaimGrant = () => {
if (grantInfo) {
chrome.braveRewards.showGrantCaptcha(grantInfo.id)
Expand All @@ -107,8 +114,9 @@ export const RewardsWidget = createWidget((props: RewardsProps) => {
rewardsBalance={props.balance.total}
exchangeCurrency='USD'
exchangeRate={props.parameters.rate}
providerPayoutStatus={providerPayoutStatus}
grantInfo={grantInfo}
externalWallet={externalWalletFromExtensionData(props.externalWallet)}
externalWallet={externalWallet}
nextPaymentDate={adsInfo ? adsInfo.nextPaymentDate : 0}
earningsThisMonth={adsInfo ? adsInfo.earningsThisMonth : 0}
earningsLastMonth={adsInfo ? adsInfo.earningsLastMonth : 0}
Expand Down
3 changes: 2 additions & 1 deletion components/brave_new_tab_ui/storage/new_tab_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export const defaultState: NewTab.State = {
totalContribution: 0.0,
parameters: {
rate: 0,
monthlyTipChoices: []
monthlyTipChoices: [],
payoutStatus: {}
}
},
currentStackWidget: '',
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/browser/rewards_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void RewardsService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
"");
registry->RegisterStringPref(prefs::kParametersTipChoices, "");
registry->RegisterStringPref(prefs::kParametersMonthlyTipChoices, "");
registry->RegisterStringPref(prefs::kParametersPayoutStatus, "");
registry->RegisterBooleanPref(prefs::kFetchOldBalance, true);
registry->RegisterBooleanPref(prefs::kEmptyBalanceChecked, false);
registry->RegisterStringPref(prefs::kWalletBrave, "");
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const char kParametersTipChoices[] =
"brave.rewards.parameters.tip.choices";
const char kParametersMonthlyTipChoices[] =
"brave.rewards.parameters.tip.monthly_choices";
const char kParametersPayoutStatus[] = "brave.rewards.parameters.payout_status";
const char kFetchOldBalance[] =
"brave.rewards.fetch_old_balance";
const char kEmptyBalanceChecked[] =
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern const char kParametersAutoContributeChoice[];
extern const char kParametersAutoContributeChoices[];
extern const char kParametersTipChoices[];
extern const char kParametersMonthlyTipChoices[];
extern const char kParametersPayoutStatus[];
extern const char kFetchOldBalance[];
extern const char kEmptyBalanceChecked[];
extern const char kWalletBrave[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
StyledNeedsBrowserUpdateContentBody
} from './style'

import { externalWalletProviderFromString } from '../../shared/lib/external_wallet'
import { getProviderPayoutStatus } from '../../shared/lib/provider_payout_status'
import { PaymentStatusView } from '../../shared/components/payment_status_view'

// Utils
Expand Down Expand Up @@ -221,6 +223,7 @@ class AdsBox extends React.Component<Props, {}> {
const {
adsData,
balanceReport,
externalWallet,
safetyNetFailed,
parameters
} = this.props.rewardsData
Expand Down Expand Up @@ -269,6 +272,13 @@ class AdsBox extends React.Component<Props, {}> {

const tokenString = getLocale('tokens')

const walletStatus = externalWallet ? externalWallet.status : null
const walletProvider = externalWallet
? externalWalletProviderFromString(externalWallet.type) : null
const providerPayoutStatus = getProviderPayoutStatus(
parameters.payoutStatus,
walletProvider && walletStatus ? walletProvider : null)

return (
<BoxMobile
title={getLocale('adsTitle')}
Expand All @@ -282,6 +292,7 @@ class AdsBox extends React.Component<Props, {}> {
earningsLastMonth={earningsLastMonth}
earningsReceived={adEarningsReceived}
nextPaymentDate={nextPaymentDate}
providerPayoutStatus={providerPayoutStatus}
/>
</StyledArrivingSoon>
<List title={<StyledListContent>{getLocale('adsCurrentEarnings')}</StyledListContent>}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../../ui/components'
import { PendingContributionsModal } from './pending_contributions_modal'
import { WalletCard, ExternalWalletAction } from '../../shared/components/wallet_card'
import { getProviderPayoutStatus } from '../../shared/lib/provider_payout_status'
import { ExternalWallet, ExternalWalletProvider, ExternalWalletStatus } from '../../shared/lib/external_wallet'
import { Provider } from '../../ui/components/profile'
import { DetailRow as PendingDetailRow, PendingType } from '../../ui/components/tablePending'
Expand Down Expand Up @@ -760,6 +761,10 @@ class PageWallet extends React.Component<Props, State> {
}
}

const providerPayoutStatus = getProviderPayoutStatus(
parameters.payoutStatus,
walletProvider && walletStatus ? walletProvider : null)

const summaryData = {
adEarnings: balanceReport && balanceReport.ads || 0,
autoContributions: balanceReport && balanceReport.contribute || 0,
Expand All @@ -773,6 +778,7 @@ class PageWallet extends React.Component<Props, State> {
<WalletCard
balance={total}
externalWallet={externalWalletInfo}
providerPayoutStatus={providerPayoutStatus}
earningsThisMonth={adsData.adsEarningsThisMonth || 0}
earningsLastMonth={adsData.adsEarningsLastMonth || 0}
nextPaymentDate={0}
Expand Down
5 changes: 3 additions & 2 deletions components/brave_rewards/resources/android_page/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { debounce } from '../../../common/debounce'
const keyName = 'rewards-data'

export const defaultState: Rewards.State = {
version: 1,
version: 2,
createdTimestamp: null,
enabledAds: true,
enabledAdsMigrated: false,
Expand Down Expand Up @@ -77,7 +77,8 @@ export const defaultState: Rewards.State = {
parameters: {
autoContributeChoice: 0,
autoContributeChoices: [],
rate: 0
rate: 0,
payoutStatus: {}
},
initializing: true,
paymentId: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const defaultState: RewardsExtension.State = {
parameters: {
monthlyTipChoices: [],
rate: 0,
autoContributeChoices: [5, 10, 15, 20]
autoContributeChoices: [5, 10, 15, 20],
payoutStatus: {}
},
balanceReport: {
ads: 0.0,
Expand Down
13 changes: 12 additions & 1 deletion components/brave_rewards/resources/page/components/adsBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
import { Grid, Column, Select, ControlWrapper } from 'brave-ui/components'
import { AlertCircleIcon } from 'brave-ui/components/icons'

import { externalWalletProviderFromString } from '../../shared/lib/external_wallet'
import { getProviderPayoutStatus } from '../../shared/lib/provider_payout_status'
import { PaymentStatusView } from '../../shared/components/payment_status_view'

import * as style from './style'
Expand Down Expand Up @@ -415,6 +417,7 @@ class AdsBox extends React.Component<Props, State> {
adsData,
adsHistory,
balanceReport,
externalWallet,
parameters
} = this.props.rewardsData

Expand Down Expand Up @@ -442,6 +445,13 @@ class AdsBox extends React.Component<Props, State> {
const rows = this.getGroupedAdsHistory(historyEntries, savedOnly)
const tokenString = getLocale('tokens')

const walletStatus = externalWallet ? externalWallet.status : null
const walletProvider = externalWallet
? externalWalletProviderFromString(externalWallet.type) : null
const providerPayoutStatus = getProviderPayoutStatus(
parameters.payoutStatus,
walletProvider && walletStatus ? walletProvider : null)

return (
<>
<Box
Expand All @@ -468,6 +478,7 @@ class AdsBox extends React.Component<Props, State> {
earningsLastMonth={earningsLastMonth}
earningsReceived={adEarningsReceived}
nextPaymentDate={nextPaymentDate}
providerPayoutStatus={providerPayoutStatus}
/>
</style.PaymentStatus>
<List title={getLocale('adsCurrentEarnings')}>
Expand Down Expand Up @@ -496,7 +507,7 @@ class AdsBox extends React.Component<Props, State> {
</List>
{
<ShowAdsHistory
onAdsHistoryOpen={this.onAdsHistoryToggle}
onAdsHistoryOpen={this.onAdsHistoryToggle}
/>
}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ModalQRCode
} from '../../ui/components'
import { WalletCard, ExternalWalletAction } from '../../shared/components/wallet_card'
import { getProviderPayoutStatus } from '../../shared/lib/provider_payout_status'
import { ExternalWallet, ExternalWalletProvider, ExternalWalletStatus } from '../../shared/lib/external_wallet'
import { Provider } from '../../ui/components/profile'
import { DetailRow as PendingDetailRow, PendingType } from '../../ui/components/tablePending'
Expand Down Expand Up @@ -760,6 +761,10 @@ class PageWallet extends React.Component<Props, State> {
}
}

const providerPayoutStatus = getProviderPayoutStatus(
parameters.payoutStatus,
walletProvider && walletStatus ? walletProvider : null)

const summaryData = {
adEarnings: balanceReport && balanceReport.ads || 0,
autoContributions: balanceReport && balanceReport.contribute || 0,
Expand All @@ -773,6 +778,7 @@ class PageWallet extends React.Component<Props, State> {
<WalletCard
balance={total}
externalWallet={externalWalletInfo}
providerPayoutStatus={providerPayoutStatus}
earningsThisMonth={adsData.adsEarningsThisMonth || 0}
earningsLastMonth={adsData.adsEarningsLastMonth || 0}
nextPaymentDate={0}
Expand Down
5 changes: 3 additions & 2 deletions components/brave_rewards/resources/page/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { debounce } from '../../../common/debounce'
const keyName = 'rewards-data'

export const defaultState: Rewards.State = {
version: 1,
version: 2,
createdTimestamp: null,
enabledAds: false,
enabledAdsMigrated: false,
Expand Down Expand Up @@ -76,7 +76,8 @@ export const defaultState: Rewards.State = {
parameters: {
autoContributeChoice: 0,
autoContributeChoices: [],
rate: 0
rate: 0,
payoutStatus: {}
},
initializing: true,
paymentId: '',
Expand Down
Loading