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

Improve rewards onboarding experience #7135

Merged
merged 1 commit into from
Nov 13, 2020
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
5 changes: 2 additions & 3 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1640,8 +1640,7 @@ void RewardsServiceImpl::SetAutoContributeEnabled(bool enabled) {
}

bool RewardsServiceImpl::ShouldShowOnboarding() const {
PrefService* prefs = profile_->GetPrefs();
const base::Time onboard_time = prefs->GetTime(prefs::kOnboarded);
const bool legacy_enabled = profile_->GetPrefs()->GetBoolean(prefs::kEnabled);

bool ads_enabled = false;
bool ads_supported = true;
Expand All @@ -1651,7 +1650,7 @@ bool RewardsServiceImpl::ShouldShowOnboarding() const {
ads_supported = ads_service->IsSupportedLocale();
}

return onboard_time.is_null() && !ads_enabled && ads_supported;
return !legacy_enabled && !ads_enabled && ads_supported;
diracdeltas marked this conversation as resolved.
Show resolved Hide resolved
}

void RewardsServiceImpl::SaveOnboardingResult(OnboardingResult result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ void CreateWallet(brave_rewards::RewardsServiceImpl* rewards_service) {
ASSERT_TRUE(success);
}

void SetOnboardingBypassed(Browser* browser, bool bypassed) {
DCHECK(browser);
// Rewards onboarding will be skipped if the legacy "enabled" pref
// is set to true.
PrefService* prefs = browser->profile()->GetPrefs();
prefs->SetBoolean(brave_rewards::prefs::kEnabled, bypassed);
}

} // namespace rewards_browsertest_util
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void WaitForLedgerStop(brave_rewards::RewardsServiceImpl* rewards_service);

void CreateWallet(brave_rewards::RewardsServiceImpl* rewards_service);

void SetOnboardingBypassed(Browser* browser, bool bypassed = true);

} // namespace rewards_browsertest_util

#endif // BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_TEST_COMMON_REWARDS_BROWSERTEST_UTIL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ class RewardsBrowserTest : public InProcessBrowserTest {
contribution_->Initialize(browser(), rewards_service_);
promotion_->Initialize(browser(), rewards_service_);

// Bypass onboarding UX by default
rewards_service_->SaveOnboardingResult(
brave_rewards::OnboardingResult::kDismissed);
rewards_browsertest_util::SetOnboardingBypassed(browser());
}

void TearDown() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class RewardsContributionBrowserTest : public InProcessBrowserTest {
promotion_->Initialize(browser(), rewards_service_);
contribution_->Initialize(browser(), rewards_service_);

// Bypass onboarding UX by default
rewards_service_->SaveOnboardingResult(
brave_rewards::OnboardingResult::kDismissed);
rewards_browsertest_util::SetOnboardingBypassed(browser());
}

void TearDown() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ class RewardsFlagBrowserTest : public InProcessBrowserTest {
base::Unretained(this)));
rewards_service_->SetLedgerEnvForTesting();

// Bypass onboarding UX by default
rewards_service_->SaveOnboardingResult(
brave_rewards::OnboardingResult::kDismissed);
rewards_browsertest_util::SetOnboardingBypassed(browser());
}

void GetTestResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ class RewardsNotificationBrowserTest
rewards_notification_service_ = rewards_service_->GetNotificationService();
rewards_notification_service_->AddObserver(this);

// Bypass onboarding UX by default
rewards_service_->SaveOnboardingResult(
brave_rewards::OnboardingResult::kDismissed);
rewards_browsertest_util::SetOnboardingBypassed(browser());
}

void TearDown() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ class RewardsPromotionBrowserTest : public InProcessBrowserTest {
// Other
promotion_->Initialize(browser(), rewards_service_);

// Bypass onboarding UX by default
rewards_service_->SaveOnboardingResult(
brave_rewards::OnboardingResult::kDismissed);
rewards_browsertest_util::SetOnboardingBypassed(browser());
}

void TearDown() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ class RewardsPublisherBrowserTest : public InProcessBrowserTest {
base::Unretained(this)));
rewards_service_->SetLedgerEnvForTesting();

// Bypass onboarding UX by default
rewards_service_->SaveOnboardingResult(
brave_rewards::OnboardingResult::kDismissed);
rewards_browsertest_util::SetOnboardingBypassed(browser());
}

void TearDown() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
* 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 { OnboardingCompletedStore } from '../../../../shared/lib/onboarding_completed_store'
import { types } from '../../constants/rewards_panel_types'
import { Reducer } from 'redux'
import { setBadgeText } from '../browserAction'
import { isPublisherConnectedOrVerified } from '../../utils'

const onboardingCompletedStore = new OnboardingCompletedStore()

const getTabKey = (id: number) => {
return `key_${id}`
}
Expand Down Expand Up @@ -242,12 +245,17 @@ export const rewardsPanelReducer: Reducer<RewardsExtension.State | undefined> =
break
}
case types.ON_SHOULD_SHOW_ONBOARDING: {
state = { ...state, showOnboarding: payload.showOnboarding }
const completed = onboardingCompletedStore.load()
state = {
...state,
showOnboarding: payload.showOnboarding && !completed
}
break
}
case types.SAVE_ONBOARDING_RESULT: {
state = { ...state, showOnboarding: false }
chrome.braveRewards.saveOnboardingResult(payload.result)
onboardingCompletedStore.save()
break
}
case types.ON_PUBLISHER_LIST_NORMALIZED: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

import { Reducer } from 'redux'

import { OnboardingCompletedStore } from '../../shared/lib/onboarding_completed_store'

// Constant
import { types } from '../constants/rewards_types'
import { defaultState } from '../storage'

const onboardingCompletedStore = new OnboardingCompletedStore()

const rewardsReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State, action) => {
if (!state) {
return
Expand Down Expand Up @@ -439,15 +443,17 @@ const rewardsReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State
break
}
case types.ON_ONBOARDING_STATUS: {
const completed = onboardingCompletedStore.load()
state = {
...state,
showOnboarding: action.payload.showOnboarding
showOnboarding: action.payload.showOnboarding && !completed
}
break
}
case types.SAVE_ONBOARDING_RESULT: {
chrome.send('brave_rewards.saveOnboardingResult', [action.payload.result])
chrome.send('brave_rewards.getAutoContributeProperties')
onboardingCompletedStore.save()
state = {
...state,
showOnboarding: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* 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/. */

// An OnboardingCompletedStore can be used by apps that include
// rewards onboarding UX to store whether the user has interacted
// with the onboarding experience.
export class OnboardingCompletedStore {

load () {
return Boolean(localStorage.rewardsOnboardingComplete)
}

save () {
localStorage.rewardsOnboardingComplete = String(Date.now())
zenparsing marked this conversation as resolved.
Show resolved Hide resolved
}
}
6 changes: 5 additions & 1 deletion components/brave_rewards/resources/tip/lib/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* 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 { OnboardingCompletedStore } from '../../shared/lib/onboarding_completed_store'

import { createStateManager } from './state_manager'

import {
Expand Down Expand Up @@ -58,6 +60,7 @@ function addWebUIListeners (listeners: Record<string, any>) {
export function createHost (): Host {
const stateManager = createStateManager<HostState>({})
const dialogArgs = getDialogArgs()
const onboardingCompleted = new OnboardingCompletedStore()

addWebUIListeners({

Expand Down Expand Up @@ -95,7 +98,7 @@ export function createHost (): Host {

onboardingStatusUpdated (result: { showOnboarding: boolean }) {
stateManager.update({
showOnboarding: result.showOnboarding
showOnboarding: result.showOnboarding && !onboardingCompleted.load()
})
},

Expand Down Expand Up @@ -193,6 +196,7 @@ export function createHost (): Host {
saveOnboardingResult (result: OnboardingResult) {
chrome.send('saveOnboardingResult', [result])
stateManager.update({ showOnboarding: false })
onboardingCompleted.save()
},

processTip (amount: number, kind: TipKind) {
Expand Down