Skip to content

Commit a4da516

Browse files
committed
Adding support for payout status
1 parent 9091bad commit a4da516

File tree

42 files changed

+285
-50
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+285
-50
lines changed

browser/extensions/api/brave_rewards_api.cc

+8-3
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,11 @@ BraveRewardsGetRewardsParametersFunction::Run() {
491491
}
492492

493493
rewards_service->GetRewardsParameters(base::BindOnce(
494-
&BraveRewardsGetRewardsParametersFunction::OnGet,
495-
this));
494+
&BraveRewardsGetRewardsParametersFunction::OnGetRewardsParameters, this));
496495
return RespondLater();
497496
}
498497

499-
void BraveRewardsGetRewardsParametersFunction::OnGet(
498+
void BraveRewardsGetRewardsParametersFunction::OnGetRewardsParameters(
500499
ledger::type::RewardsParametersPtr parameters) {
501500
base::DictionaryValue data;
502501

@@ -517,6 +516,12 @@ void BraveRewardsGetRewardsParametersFunction::OnGet(
517516
}
518517
data.SetList("autoContributeChoices", std::move(ac_choices));
519518

519+
auto payout_status = std::make_unique<base::DictionaryValue>();
520+
for (const auto& item : parameters->payout_status) {
521+
payout_status->SetString(item.first, item.second);
522+
}
523+
data.Set("payoutStatus", std::move(payout_status));
524+
520525
Respond(OneArgument(std::move(data)));
521526
}
522527

browser/extensions/api/brave_rewards_api.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class BraveRewardsGetRewardsParametersFunction : public ExtensionFunction {
138138
ResponseAction Run() override;
139139

140140
private:
141-
void OnGet(ledger::type::RewardsParametersPtr parameters);
141+
void OnGetRewardsParameters(ledger::type::RewardsParametersPtr parameters);
142142
};
143143

144144
class BraveRewardsGetBalanceReportFunction : public ExtensionFunction {

browser/ui/webui/brave_rewards_page_ui.cc

+13-6
Original file line numberDiff line numberDiff line change
@@ -667,14 +667,21 @@ void RewardsDOMHandler::OnGetRewardsParameters(
667667

668668
base::DictionaryValue data;
669669
if (parameters) {
670-
auto choices = std::make_unique<base::ListValue>();
671-
for (double const& choice : parameters->auto_contribute_choices) {
672-
choices->Append(choice);
670+
base::ListValue auto_contribute_choices;
671+
for (double const& item : parameters->auto_contribute_choices) {
672+
auto_contribute_choices.Append(item);
673673
}
674674

675-
data.SetDouble("rate", parameters->rate);
676-
data.SetDouble("autoContributeChoice", parameters->auto_contribute_choice);
677-
data.SetList("autoContributeChoices", std::move(choices));
675+
base::DictionaryValue payout_status;
676+
for (const auto& item : parameters->payout_status) {
677+
payout_status.SetStringKey(item.first, item.second);
678+
}
679+
680+
data.SetDoubleKey("rate", parameters->rate);
681+
data.SetDoubleKey("autoContributeChoice",
682+
parameters->auto_contribute_choice);
683+
data.SetKey("autoContributeChoices", std::move(auto_contribute_choices));
684+
data.SetKey("payoutStatus", std::move(payout_status));
678685
}
679686
CallJavascriptFunction("brave_rewards.rewardsParameters", data);
680687
}

browser/ui/webui/brave_tip_ui.cc

+6
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,16 @@ void TipMessageHandler::GetRewardsParametersCallback(
459459
ac_choices.Append(item);
460460
}
461461

462+
base::Value payout_status(base::Value::Type::DICTIONARY);
463+
for (const auto& item : parameters->payout_status) {
464+
payout_status.SetStringKey(item.first, item.second);
465+
}
466+
462467
data.SetDoubleKey("rate", parameters->rate);
463468
data.SetKey("tipChoices", std::move(tip_choices));
464469
data.SetKey("monthlyTipChoices", std::move(monthly_choices));
465470
data.SetKey("autoContributeChoices", std::move(ac_choices));
471+
data.SetKey("payoutStatus", std::move(payout_status));
466472
}
467473

468474
FireWebUIListener("rewardsParametersUpdated", data);

common/extensions/api/brave_rewards.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@
629629
{
630630
"name": "getRewardsParameters",
631631
"type": "function",
632-
"description": "Get default values that we get from the server",
632+
"description": "Get default Rewards parameters",
633633
"parameters": [
634634
{
635635
"type": "function",
@@ -658,6 +658,10 @@
658658
"type": "number",
659659
"minimum": 0
660660
}
661+
},
662+
"payoutStatus": {
663+
"type": "any",
664+
"description": "Payout status"
661665
}
662666
}
663667
}

components/brave_new_tab_ui/components/default/rewards/index.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
2-
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3-
* You can obtain one at http://mozilla.org/MPL/2.0/. */
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import * as React from 'react'
66

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

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

96+
const externalWallet = externalWalletFromExtensionData(props.externalWallet)
97+
const walletProvider = externalWallet ? externalWallet.provider : ''
98+
const providerPayoutStatus = getProviderPayoutStatus(
99+
props.parameters.payoutStatus, walletProvider)
100+
95101
const onClaimGrant = () => {
96102
if (grantInfo) {
97103
chrome.braveRewards.openBrowserActionUI(
@@ -108,8 +114,9 @@ export const RewardsWidget = createWidget((props: RewardsProps) => {
108114
rewardsBalance={props.balance.total}
109115
exchangeCurrency='USD'
110116
exchangeRate={props.parameters.rate}
117+
providerPayoutStatus={providerPayoutStatus}
111118
grantInfo={grantInfo}
112-
externalWallet={externalWalletFromExtensionData(props.externalWallet)}
119+
externalWallet={externalWallet}
113120
nextPaymentDate={adsInfo ? adsInfo.nextPaymentDate : 0}
114121
earningsThisMonth={adsInfo ? adsInfo.earningsThisMonth : 0}
115122
earningsLastMonth={adsInfo ? adsInfo.earningsLastMonth : 0}

components/brave_new_tab_ui/storage/new_tab_storage.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export const defaultState: NewTab.State = {
8080
totalContribution: 0.0,
8181
parameters: {
8282
rate: 0,
83-
monthlyTipChoices: []
83+
monthlyTipChoices: [],
84+
payoutStatus: {}
8485
}
8586
},
8687
currentStackWidget: '',

components/brave_rewards/browser/rewards_service.cc

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ void RewardsService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
8383
"");
8484
registry->RegisterStringPref(prefs::kParametersTipChoices, "");
8585
registry->RegisterStringPref(prefs::kParametersMonthlyTipChoices, "");
86+
registry->RegisterStringPref(prefs::kParametersPayoutStatus, "");
8687
registry->RegisterBooleanPref(prefs::kFetchOldBalance, true);
8788
registry->RegisterBooleanPref(prefs::kEmptyBalanceChecked, false);
8889
registry->RegisterStringPref(prefs::kWalletBrave, "");

components/brave_rewards/common/pref_names.cc

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const char kParametersTipChoices[] =
6464
"brave.rewards.parameters.tip.choices";
6565
const char kParametersMonthlyTipChoices[] =
6666
"brave.rewards.parameters.tip.monthly_choices";
67+
const char kParametersPayoutStatus[] = "brave.rewards.parameters.payout_status";
6768
const char kFetchOldBalance[] =
6869
"brave.rewards.fetch_old_balance";
6970
const char kEmptyBalanceChecked[] =

components/brave_rewards/common/pref_names.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extern const char kParametersAutoContributeChoice[];
5454
extern const char kParametersAutoContributeChoices[];
5555
extern const char kParametersTipChoices[];
5656
extern const char kParametersMonthlyTipChoices[];
57+
extern const char kParametersPayoutStatus[];
5758
extern const char kFetchOldBalance[];
5859
extern const char kEmptyBalanceChecked[];
5960
extern const char kWalletBrave[];

components/brave_rewards/resources/android_page/components/adsBox.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
StyledNeedsBrowserUpdateContentBody
2424
} from './style'
2525

26+
import { getProviderPayoutStatus } from '../../shared/lib/provider_payout_status'
2627
import { PaymentStatusView } from '../../shared/components/payment_status_view'
2728

2829
// Utils
@@ -221,6 +222,7 @@ class AdsBox extends React.Component<Props, {}> {
221222
const {
222223
adsData,
223224
balanceReport,
225+
externalWallet,
224226
safetyNetFailed,
225227
parameters
226228
} = this.props.rewardsData
@@ -269,6 +271,12 @@ class AdsBox extends React.Component<Props, {}> {
269271

270272
const tokenString = getLocale('tokens')
271273

274+
const walletStatus = externalWallet ? externalWallet.status : null
275+
const walletProvider = externalWallet ? externalWallet.type : ''
276+
const providerPayoutStatus = getProviderPayoutStatus(
277+
parameters.payoutStatus,
278+
walletProvider && walletStatus ? walletProvider : '')
279+
272280
return (
273281
<BoxMobile
274282
title={getLocale('adsTitle')}
@@ -282,6 +290,7 @@ class AdsBox extends React.Component<Props, {}> {
282290
earningsLastMonth={earningsLastMonth}
283291
earningsReceived={adEarningsReceived}
284292
nextPaymentDate={nextPaymentDate}
293+
providerPayoutStatus={providerPayoutStatus}
285294
/>
286295
</StyledArrivingSoon>
287296
<List title={<StyledListContent>{getLocale('adsCurrentEarnings')}</StyledListContent>}>

components/brave_rewards/resources/android_page/components/pageWallet.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../../ui/components'
1414
import { PendingContributionsModal } from './pending_contributions_modal'
1515
import { WalletCard, ExternalWalletAction } from '../../shared/components/wallet_card'
16+
import { getProviderPayoutStatus } from '../../shared/lib/provider_payout_status'
1617
import { ExternalWallet, ExternalWalletProvider, ExternalWalletStatus } from '../../shared/lib/external_wallet'
1718
import { Provider } from '../../ui/components/profile'
1819
import { DetailRow as PendingDetailRow, PendingType } from '../../ui/components/tablePending'
@@ -760,6 +761,10 @@ class PageWallet extends React.Component<Props, State> {
760761
}
761762
}
762763

764+
const providerPayoutStatus = getProviderPayoutStatus(
765+
parameters.payoutStatus,
766+
walletProvider && walletStatus ? walletProvider : '')
767+
763768
const summaryData = {
764769
adEarnings: balanceReport && balanceReport.ads || 0,
765770
autoContributions: balanceReport && balanceReport.contribute || 0,
@@ -773,6 +778,7 @@ class PageWallet extends React.Component<Props, State> {
773778
<WalletCard
774779
balance={total}
775780
externalWallet={externalWalletInfo}
781+
providerPayoutStatus={providerPayoutStatus}
776782
earningsThisMonth={adsData.adsEarningsThisMonth || 0}
777783
earningsLastMonth={adsData.adsEarningsLastMonth || 0}
778784
nextPaymentDate={0}

components/brave_rewards/resources/android_page/storage.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export const defaultState: Rewards.State = {
7777
parameters: {
7878
autoContributeChoice: 0,
7979
autoContributeChoices: [],
80-
rate: 0
80+
rate: 0,
81+
payoutStatus: {}
8182
},
8283
initializing: true,
8384
paymentId: '',

components/brave_rewards/resources/extension/brave_rewards/background/storage.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export const defaultState: RewardsExtension.State = {
77
parameters: {
88
monthlyTipChoices: [],
99
rate: 0,
10-
autoContributeChoices: [5, 10, 15, 20]
10+
autoContributeChoices: [5, 10, 15, 20],
11+
payoutStatus: {}
1112
},
1213
balanceReport: {
1314
ads: 0.0,

components/brave_rewards/resources/page/components/adsBox.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import { Grid, Column, Select, ControlWrapper } from 'brave-ui/components'
2121
import { AlertCircleIcon } from 'brave-ui/components/icons'
2222

23+
import { getProviderPayoutStatus } from '../../shared/lib/provider_payout_status'
2324
import { PaymentStatusView } from '../../shared/components/payment_status_view'
2425

2526
import * as style from './style'
@@ -415,6 +416,7 @@ class AdsBox extends React.Component<Props, State> {
415416
adsData,
416417
adsHistory,
417418
balanceReport,
419+
externalWallet,
418420
parameters
419421
} = this.props.rewardsData
420422

@@ -442,6 +444,12 @@ class AdsBox extends React.Component<Props, State> {
442444
const rows = this.getGroupedAdsHistory(historyEntries, savedOnly)
443445
const tokenString = getLocale('tokens')
444446

447+
const walletStatus = externalWallet ? externalWallet.status : null
448+
const walletProvider = externalWallet ? externalWallet.type : ''
449+
const providerPayoutStatus = getProviderPayoutStatus(
450+
parameters.payoutStatus,
451+
walletProvider && walletStatus ? walletProvider : '')
452+
445453
return (
446454
<>
447455
<Box
@@ -468,6 +476,7 @@ class AdsBox extends React.Component<Props, State> {
468476
earningsLastMonth={earningsLastMonth}
469477
earningsReceived={adEarningsReceived}
470478
nextPaymentDate={nextPaymentDate}
479+
providerPayoutStatus={providerPayoutStatus}
471480
/>
472481
</style.PaymentStatus>
473482
<List title={getLocale('adsCurrentEarnings')}>
@@ -496,7 +505,7 @@ class AdsBox extends React.Component<Props, State> {
496505
</List>
497506
{
498507
<ShowAdsHistory
499-
onAdsHistoryOpen={this.onAdsHistoryToggle}
508+
onAdsHistoryOpen={this.onAdsHistoryToggle}
500509
/>
501510
}
502511
</Box>

components/brave_rewards/resources/page/components/pageWallet.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ModalQRCode
1414
} from '../../ui/components'
1515
import { WalletCard, ExternalWalletAction } from '../../shared/components/wallet_card'
16+
import { getProviderPayoutStatus } from '../../shared/lib/provider_payout_status'
1617
import { ExternalWallet, ExternalWalletProvider, ExternalWalletStatus } from '../../shared/lib/external_wallet'
1718
import { Provider } from '../../ui/components/profile'
1819
import { DetailRow as PendingDetailRow, PendingType } from '../../ui/components/tablePending'
@@ -760,6 +761,10 @@ class PageWallet extends React.Component<Props, State> {
760761
}
761762
}
762763

764+
const providerPayoutStatus = getProviderPayoutStatus(
765+
parameters.payoutStatus,
766+
walletProvider && walletStatus ? walletProvider : '')
767+
763768
const summaryData = {
764769
adEarnings: balanceReport && balanceReport.ads || 0,
765770
autoContributions: balanceReport && balanceReport.contribute || 0,
@@ -773,6 +778,7 @@ class PageWallet extends React.Component<Props, State> {
773778
<WalletCard
774779
balance={total}
775780
externalWallet={externalWalletInfo}
781+
providerPayoutStatus={providerPayoutStatus}
776782
earningsThisMonth={adsData.adsEarningsThisMonth || 0}
777783
earningsLastMonth={adsData.adsEarningsLastMonth || 0}
778784
nextPaymentDate={0}

components/brave_rewards/resources/page/storage.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export const defaultState: Rewards.State = {
7676
parameters: {
7777
autoContributeChoice: 0,
7878
autoContributeChoices: [],
79-
rate: 0
79+
rate: 0,
80+
payoutStatus: {}
8081
},
8182
initializing: true,
8283
paymentId: '',

components/brave_rewards/resources/rewards_panel/components/panel.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as React from 'react'
66

77
import { HostContext, useHostListener } from '../lib/host_context'
8+
import { getProviderPayoutStatus } from '../../shared/lib/provider_payout_status'
89
import { WalletCard } from '../../shared/components/wallet_card'
910
import { NavBar } from './navbar'
1011
import { PanelOverlays } from './panel_overlays'
@@ -25,6 +26,8 @@ export function Panel () {
2526
React.useState(host.state.exchangeInfo)
2627
const [earningsInfo, setEarningsInfo] =
2728
React.useState(host.state.earningsInfo)
29+
const [payoutStatus, setPayoutStatus] =
30+
React.useState(host.state.payoutStatus)
2831
const [summaryData, setSummaryData] = React.useState(host.state.summaryData)
2932
const [publisherInfo, setPublisherInfo] =
3033
React.useState(host.state.publisherInfo)
@@ -38,15 +41,21 @@ export function Panel () {
3841
setExternalWallet(state.externalWallet)
3942
setExchangeInfo(state.exchangeInfo)
4043
setEarningsInfo(state.earningsInfo)
44+
setPayoutStatus(state.payoutStatus)
4145
setSummaryData(state.summaryData)
4246
setPublisherInfo(state.publisherInfo)
4347
})
4448

49+
const walletProvider = externalWallet ? externalWallet.provider : ''
50+
const providerPayoutStatus = getProviderPayoutStatus(
51+
payoutStatus, walletProvider)
52+
4553
return (
4654
<style.root data-test-id='rewards-panel'>
4755
<WalletCard
4856
balance={balance}
4957
externalWallet={externalWallet}
58+
providerPayoutStatus={providerPayoutStatus}
5059
earningsThisMonth={earningsInfo.earningsThisMonth}
5160
earningsLastMonth={earningsInfo.earningsLastMonth}
5261
nextPaymentDate={earningsInfo.nextPaymentDate}

components/brave_rewards/resources/rewards_panel/lib/extension_api_adapter.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export function getEarningsInfo () {
6565
export function getRewardsParameters () {
6666
interface Result {
6767
exchangeInfo: ExchangeInfo
68+
payoutStatus: any
6869
options: Options
6970
}
7071

@@ -77,7 +78,8 @@ export function getRewardsParameters () {
7778
exchangeInfo: {
7879
currency: 'USD',
7980
rate: parameters.rate
80-
}
81+
},
82+
payoutStatus: parameters.payoutStatus
8183
})
8284
})
8385
})

0 commit comments

Comments
 (0)