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

Use probi for reports #409

Merged
merged 6 commits into from
Oct 10, 2018
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
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deps = {
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
"vendor/sparkle": "https://github.com/brave/Sparkle.git@c0759cce415d7c0feae45005c8a013b1898711f0",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@fa06a4b1153b5a1a87f1af8becfa0803e82bc6f3",
"vendor/bat-native-ledger": "https://github.com/brave-intl/bat-native-ledger@fe65bbb07d8e3ef237ada14b54dd9390f12fc2ee",
"vendor/bat-native-rapidjson": "https://github.com/brave-intl/bat-native-rapidjson.git@86aafe2ef89835ae71c9ed7c2527e3bb3000930e",
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@9b119931c702d55be994117eb505d56310720b1d",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@0559543f458a949b83b58035273ef7f8f1a1b111",
Expand Down
17 changes: 10 additions & 7 deletions browser/ui/webui/brave_rewards_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,15 @@ void RewardsDOMHandler::GetAllBalanceReports() {
for (auto const& report : reports) {
const brave_rewards::BalanceReport oldReport = report.second;
auto newReport = std::make_unique<base::DictionaryValue>();
newReport->SetDouble("opening", oldReport.opening_balance);
newReport->SetDouble("closing", oldReport.closing_balance);
newReport->SetDouble("grants", oldReport.grants);
newReport->SetDouble("ads", oldReport.earning_from_ads);
newReport->SetDouble("contribute", oldReport.auto_contribute);
newReport->SetDouble("donations", oldReport.recurring_donation);
newReport->SetDouble("oneTime", oldReport.one_time_donation);
newReport->SetString("opening", oldReport.opening_balance);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newReport->SetString("closing", oldReport.closing_balance);
newReport->SetString("grant", oldReport.grants);
newReport->SetString("deposit", oldReport.deposits);
newReport->SetString("ads", oldReport.earning_from_ads);
newReport->SetString("contribute", oldReport.auto_contribute);
newReport->SetString("donation", oldReport.recurring_donation);
newReport->SetString("tips", oldReport.one_time_donation);
newReport->SetString("total", oldReport.total);
newReports.SetDictionary(report.first, std::move(newReport));
}

Expand Down Expand Up @@ -395,6 +397,7 @@ void RewardsDOMHandler::SaveSetting(const base::ListValue* args) {
if (key == "contributionMonthly") {
rewards_service_->SetUserChangedContribution();
rewards_service_->SetContributionAmount(std::stod(value));
GetAllBalanceReports();
}

if (key == "contributionMinTime") {
Expand Down
50 changes: 29 additions & 21 deletions common/extensions/api/brave_rewards.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,33 +138,41 @@
"name": "properties",
"type": "object",
"properties": {
"openingBalance": {
"type": "double",
"description": "balance defined in BAT"
"ads": {
"type": "string",
"description": "balance defined in probi"
},
"closingBalance": {
"type": "double",
"description": "balance defined in BAT"
"closing": {
"type": "string",
"description": "balance defined in probi"
},
"grants": {
"type": "double",
"description": "balance defined in BAT"
"contribute": {
"type": "string",
"description": "balance defined in probi"
},
"earningFromAds": {
"type": "double",
"description": "balance defined in BAT"
"deposit": {
"type": "string",
"description": "balance defined in probi"
},
"autoContribute": {
"type": "double",
"description": "balance defined in BAT"
"grant": {
"type": "string",
"description": "balance defined in probi"
},
"recurringDonation": {
"type": "double",
"description": "balance defined in BAT"
"opening": {
"type": "string",
"description": "balance defined in probi"
},
"oneTimeDonation": {
"type": "double",
"description": "balance defined in BAT"
"recurring": {
"type": "string",
"description": "balance defined in probi"
},
"tips": {
"type": "string",
"description": "balance defined in probi"
},
"total": {
"type": "string",
"description": "balance defined in probi"
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions components/brave_rewards/browser/balance_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
namespace brave_rewards {

BalanceReport::BalanceReport() :
opening_balance(.0),
closing_balance(.0),
grants(.0),
earning_from_ads(.0),
auto_contribute(.0),
recurring_donation(.0),
one_time_donation(.0) {
opening_balance("0"),
closing_balance("0"),
deposits("0"),
grants("0"),
earning_from_ads("0"),
auto_contribute("0"),
recurring_donation("0"),
one_time_donation("0"),
total("0") {
}

BalanceReport::~BalanceReport() { }
Expand All @@ -21,10 +23,12 @@ namespace brave_rewards {
opening_balance = properties.opening_balance;
closing_balance = properties.closing_balance;
grants = properties.grants;
deposits = properties.deposits;
earning_from_ads = properties.earning_from_ads;
auto_contribute = properties.auto_contribute;
recurring_donation = properties.recurring_donation;
one_time_donation = properties.one_time_donation;
total = properties.total;
}

} // namespace brave_rewards
16 changes: 9 additions & 7 deletions components/brave_rewards/browser/balance_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ namespace brave_rewards {
~BalanceReport();
BalanceReport(const BalanceReport& properties);

double opening_balance = .0;
double closing_balance = .0;
double grants = .0;
double earning_from_ads = .0;
double auto_contribute = .0;
double recurring_donation = .0;
double one_time_donation = .0;
std::string opening_balance = "0";
std::string closing_balance = "0";
std::string deposits = "0";
std::string grants = "0";
std::string earning_from_ads = "0";
std::string auto_contribute = "0";
std::string recurring_donation = "0";
std::string one_time_donation = "0";
std::string total = "0";
};

} // namespace brave_rewards
Expand Down
22 changes: 11 additions & 11 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,7 @@ void RewardsServiceImpl::OnGrantFinish(ledger::Result result,
const ledger::Grant& grant) {
ledger::BalanceReportInfo report_info;
auto now = base::Time::Now();
ledger_->GetBalanceReport(GetPublisherMonth(now), GetPublisherYear(now), &report_info);
report_info.grants_ += 10.0; // TODO NZ convert probi to
ledger_->SetBalanceReport(GetPublisherMonth(now), GetPublisherYear(now), report_info);
ledger_->SetBalanceReportCaptcha(GetPublisherMonth(now), GetPublisherYear(now), grant.probi);
TriggerOnGrantFinish(result, grant);
}

Expand Down Expand Up @@ -971,7 +969,7 @@ void RewardsServiceImpl::SetPublisherAllowVideos(bool allow) const {
}

void RewardsServiceImpl::SetContributionAmount(double amount) const {
return ledger_->SetContributionAmount(amount);
ledger_->SetContributionAmount(amount);
}

void RewardsServiceImpl::SetUserChangedContribution() const {
Expand Down Expand Up @@ -1083,13 +1081,15 @@ void RewardsServiceImpl::GetCurrentBalanceReport() {
if (event_router) {
extensions::api::brave_rewards::OnCurrentReport::Properties properties;

properties.opening_balance = report.opening_balance_;
properties.closing_balance = report.closing_balance_;
properties.grants = report.grants_;
properties.earning_from_ads = report.earning_from_ads_;
properties.auto_contribute = report.auto_contribute_;
properties.recurring_donation = report.recurring_donation_;
properties.one_time_donation = report.one_time_donation_;
properties.ads = report.earning_from_ads_;
properties.closing = report.closing_balance_;
properties.contribute = report.auto_contribute_;
properties.deposit = report.deposits_;
properties.grant = report.grants_;
properties.tips = report.one_time_donation_;
properties.opening = report.opening_balance_;
properties.total = report.total_;
properties.recurring = report.recurring_donation_;

std::unique_ptr<base::ListValue> args(
extensions::api::brave_rewards::OnCurrentReport::Create(properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ transpile_web_ui("brave_rewards_panel") {
"components/app.tsx",
"components/panel.tsx",
"constants/rewards_panel_types.ts",
"utils.ts",
]

bundle_names = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@
"description": ""
},
"tokenGrant": {
"message": "New Token Grant",
"message": "Token Grant",
"description": ""
},
"earningsAds": {
"message": "Earnings from Brave Ads",
"description": ""
},
"rewardsContribute": {
"message": "Brave Auto-Contribute",
"message": "Auto-Contribute",
"description": ""
},
"oneTimeDonation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ const defaultState: RewardsExtension.State = {
rates: {}
},
report: {
ads: 0,
closing: 0,
contribute: 0,
donations: 0,
grants: 0,
oneTime: 0,
opening: 0,
total: 0
ads: '0',
closing: '0',
contribute: '0',
deposit: '0',
donation: '0',
grant: '0',
tips: '0',
opening: '0',
total: '0'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { connect } from 'react-redux'
import { WalletAddIcon, BatColorIcon } from 'brave-ui/components/icons'
import { WalletWrapper, WalletSummary, WalletSummarySlider, WalletPanel } from 'brave-ui/features/rewards'
import { Provider } from 'brave-ui/features/rewards/profile'
import BigNumber from 'bignumber.js'

// Utils
import * as rewardsPanelActions from '../actions/rewards_panel_actions'
import * as utils from '../../../ui/utils'
import * as utils from '../utils'

interface Props extends RewardsExtension.ComponentProps {
windowId: number
Expand Down Expand Up @@ -95,7 +94,7 @@ export class Panel extends React.Component<Props, State> {

return grants.map((grant: RewardsExtension.Grant) => {
return {
tokens: new BigNumber(grant.probi.toString()).dividedBy('1e18').toNumber(),
tokens: utils.convertProbiToFixed(grant.probi),
expireDate: new Date(grant.expiryTime * 1000).toLocaleDateString()
}
})
Expand All @@ -104,42 +103,19 @@ export class Panel extends React.Component<Props, State> {
getWalletSummary = () => {
const { walletProperties, report } = this.props.rewardsPanelData
const { rates } = walletProperties
const contributionMonthly = 10 // TODO NZ fix with new reports refactor https://github.com/brave/brave-core/pull/409
const convertedMonthly = utils.convertBalance(contributionMonthly, rates)

let props = {
contribute: {
tokens: contributionMonthly,
converted: convertedMonthly
}
}
let props = {}

if (report) {
if (report.ads) {
props['ads'] = {
tokens: report.ads,
converted: utils.convertBalance(report.ads, rates)
}
}

if (report.donations) {
props['donation'] = {
tokens: report.donations,
converted: utils.convertBalance(report.donations, rates)
}
}

if (report.grants) {
props['grant'] = {
tokens: report.grants,
converted: utils.convertBalance(report.grants, rates)
}
}

if (report.oneTime) {
props['tips'] = {
tokens: report.oneTime,
converted: utils.convertBalance(report.oneTime, rates)
for (let key in report) {
const item = report[key]

if (item.length > 1 && key !== 'total') {
const tokens = utils.convertProbiToFixed(item)
props[key] = {
tokens,
converted: utils.convertBalance(tokens, rates)
}
}
}
}
Expand All @@ -158,14 +134,14 @@ export class Panel extends React.Component<Props, State> {
render () {
const { balance, rates, grants } = this.props.rewardsPanelData.walletProperties
const publisher: RewardsExtension.Publisher | undefined = this.getPublisher()
const converted = utils.convertBalance(balance, rates)
const converted = utils.convertBalance(balance.toString(), rates)

return (
<WalletWrapper
compact={true}
contentPadding={false}
gradientTop={this.gradientColor}
tokens={balance}
balance={balance.toFixed(1)}
converted={utils.formatConverted(converted)}
actions={[
{
Expand Down Expand Up @@ -201,7 +177,24 @@ export class Panel extends React.Component<Props, State> {
includeInAuto={!publisher.excluded}
attentionScore={(publisher.percentage || 0).toString()}
donationAmounts={
[5, 10, 15, 20, 30, 50, 100]
[
{
tokens: '0.0',
converted: '0.00'
},
{
tokens: '1.0',
converted: '0.50'
},
{
tokens: '5.0',
converted: '2.50'
},
{
tokens: '10.0',
converted: '5.00'
}
]
}
onToggleTips={this.doNothing}
donationAction={this.doNothing}
Expand Down
Loading