Skip to content

Commit

Permalink
Merge pull request brave#992 from brave/fix-2265
Browse files Browse the repository at this point in the history
Fix brave#2265: Resolved values in brave://rewards were using defaults ins…
  • Loading branch information
bsclifton committed Nov 30, 2018
1 parent 705ef5d commit fb9654b
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 2 deletions.
14 changes: 14 additions & 0 deletions browser/ui/webui/brave_rewards_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ void RewardsDOMHandler::OnWalletProperties(
std::unique_ptr<brave_rewards::WalletProperties> wallet_properties) {

if (web_ui()->CanCallJavascript()) {
base::DictionaryValue values;
values.SetBoolean("enabledContribute",
rewards_service->GetAutoContribute());
values.SetInteger("contributionMinTime",
rewards_service->GetPublisherMinVisitTime());
values.SetInteger("contributionMinVisits",
rewards_service->GetPublisherMinVisits());
values.SetBoolean("contributionNonVerified",
rewards_service->GetPublisherAllowNonVerified());
values.SetBoolean("contributionVideos",
rewards_service->GetPublisherAllowVideos());
web_ui()->CallJavascriptFunctionUnsafe(
"brave_rewards.initAutoContributeSettings", values);

base::DictionaryValue result;
result.SetInteger("status", error_code);
auto walletInfo = std::make_unique<base::DictionaryValue>();
Expand Down
5 changes: 5 additions & 0 deletions components/brave_rewards/browser/rewards_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@ class RewardsService : public KeyedService {
virtual uint64_t GetReconcileStamp() const = 0;
virtual std::map<std::string, std::string> GetAddresses() const = 0;
virtual void SetRewardsMainEnabled(bool enabled) const = 0;
virtual uint64_t GetPublisherMinVisitTime() const = 0;
virtual void SetPublisherMinVisitTime(uint64_t duration_in_seconds) const = 0;
virtual unsigned int GetPublisherMinVisits() const = 0;
virtual void SetPublisherMinVisits(unsigned int visits) const = 0;
virtual bool GetPublisherAllowNonVerified() const = 0;
virtual void SetPublisherAllowNonVerified(bool allow) const = 0;
virtual bool GetPublisherAllowVideos() const = 0;
virtual void SetPublisherAllowVideos(bool allow) const = 0;
virtual void SetContributionAmount(double amount) const = 0;
virtual void SetUserChangedContribution() const = 0;
virtual bool GetAutoContribute() const = 0;
virtual void SetAutoContribute(bool enabled) const = 0;
virtual void SetTimer(uint64_t time_offset, uint32_t& timer_id) = 0;
virtual std::map<std::string, brave_rewards::BalanceReport> GetAllBalanceReports() = 0;
Expand Down
20 changes: 20 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1057,19 +1057,35 @@ void RewardsServiceImpl::SetRewardsMainEnabled(bool enabled) const {
return ledger_->SetRewardsMainEnabled(enabled);
}

uint64_t RewardsServiceImpl::GetPublisherMinVisitTime() const {
return ledger_->GetPublisherMinVisitTime();
}

void RewardsServiceImpl::SetPublisherMinVisitTime(
uint64_t duration_in_seconds) const {
return ledger_->SetPublisherMinVisitTime(duration_in_seconds);
}

unsigned int RewardsServiceImpl::GetPublisherMinVisits() const {
return ledger_->GetPublisherMinVisits();
}

void RewardsServiceImpl::SetPublisherMinVisits(unsigned int visits) const {
return ledger_->SetPublisherMinVisits(visits);
}

bool RewardsServiceImpl::GetPublisherAllowNonVerified() const {
return ledger_->GetPublisherAllowNonVerified();
}

void RewardsServiceImpl::SetPublisherAllowNonVerified(bool allow) const {
return ledger_->SetPublisherAllowNonVerified(allow);
}

bool RewardsServiceImpl::GetPublisherAllowVideos() const {
return ledger_->GetPublisherAllowVideos();
}

void RewardsServiceImpl::SetPublisherAllowVideos(bool allow) const {
return ledger_->SetPublisherAllowVideos(allow);
}
Expand All @@ -1086,6 +1102,10 @@ void RewardsServiceImpl::SetUserChangedContribution() const {
ledger_->SetUserChangedContribution();
}

bool RewardsServiceImpl::GetAutoContribute() const {
return ledger_->GetAutoContribute();
}

void RewardsServiceImpl::SetAutoContribute(bool enabled) const {
return ledger_->SetAutoContribute(enabled);
}
Expand Down
5 changes: 5 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class RewardsServiceImpl : public RewardsService,
std::string URIEncode(const std::string& value) override;
uint64_t GetReconcileStamp() const override;
std::map<std::string, std::string> GetAddresses() const override;
bool GetAutoContribute() const override;
uint64_t GetPublisherMinVisitTime() const override;
unsigned int GetPublisherMinVisits() const override;
bool GetPublisherAllowNonVerified() const override;
bool GetPublisherAllowVideos() const override;
void LoadMediaPublisherInfo(
const std::string& media_key,
ledger::PublisherInfoCallback callback) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ export const onCurrentTips = (list: Rewards.Publisher[]) => action(types.ON_CURR
export const getDonationTable = () => action(types.GET_DONATION_TABLE)

export const getContributeList = () => action(types.GET_CONTRIBUTE_LIST)

export const onInitAutoContributeSettings = (properties: any) => action(types.INIT_AUTOCONTRIBUTE_SETTINGS, {
properties
})
7 changes: 6 additions & 1 deletion components/brave_rewards/resources/ui/brave_rewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ window.cr.define('brave_rewards', function () {
getActions().onCurrentTips(list)
}

function initAutoContributeSettings (properties: any) {
getActions().onInitAutoContributeSettings(properties)
}

return {
initialize,
walletCreated,
Expand All @@ -135,7 +139,8 @@ window.cr.define('brave_rewards', function () {
walletExists,
contributionAmount,
recurringDonationUpdate,
currentTips
currentTips,
initAutoContributeSettings
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ export const enum types {
ON_REMOVE_RECURRING = '@@rewards/ON_REMOVE_RECURRING',
ON_CURRENT_TIPS = '@@rewards/ON_CURRENT_TIPS',
GET_DONATION_TABLE = '@@rewards/GET_DONATION_TABLE',
GET_CONTRIBUTE_LIST = '@@rewards/GET_CONTRIBUTE_LIST'
GET_CONTRIBUTE_LIST = '@@rewards/GET_CONTRIBUTE_LIST',
INIT_AUTOCONTRIBUTE_SETTINGS = '@@rewards/INIT_AUTOCONTRIBUTE_SETTINGS'
}
17 changes: 17 additions & 0 deletions components/brave_rewards/resources/ui/reducers/rewards_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ import { types } from '../constants/rewards_types'

const rewardsReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State, action) => {
switch (action.type) {
case types.INIT_AUTOCONTRIBUTE_SETTINGS:
{
let properties = action.payload.properties

if (!properties || Object.keys(properties).length === 0) {
break
}

state = { ...state }

Object.keys(properties).map((property: string) => {
if (properties[property] !== undefined) {
state[property] = properties[property]
}
})
break
}
case types.ON_SETTING_SAVE:
state = { ...state }
const key = action.payload.key
Expand Down

0 comments on commit fb9654b

Please sign in to comment.