Skip to content

Commit 16fe4ff

Browse files
committed
refactor(money): rename selector to selectWalletHomeOnboardingFlowVisible (MUSD-788)
Address review: clearer name for the wallet-home onboarding flow visibility selector and its consumer; drop the explanatory comment.
1 parent 11584b3 commit 16fe4ff

4 files changed

Lines changed: 28 additions & 34 deletions

File tree

app/components/UI/Money/components/MoneyBalanceCard/MoneyBalanceCard.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { strings } from '../../../../../../locales/i18n';
77
import Routes from '../../../../../constants/navigation/Routes';
88
import useMoneyAccountBalance from '../../hooks/useMoneyAccountBalance';
99
import { selectMoneyOnboardingSeen } from '../../../../../reducers/user/selectors';
10-
import { selectInWalletHomeOnboardingFlow } from '../../../../../selectors/onboarding';
10+
import { selectWalletHomeOnboardingFlowVisible } from '../../../../../selectors/onboarding';
1111
import { useMoneyNavigation } from '../../hooks/useMoneyNavigation';
1212

1313
const mockNavigate = jest.fn();
@@ -40,13 +40,13 @@ jest.mock('../../../../../reducers/user/selectors', () => ({
4040

4141
jest.mock('../../../../../selectors/onboarding', () => ({
4242
__esModule: true,
43-
selectInWalletHomeOnboardingFlow: jest.fn(),
43+
selectWalletHomeOnboardingFlowVisible: jest.fn(),
4444
}));
4545

4646
const mockUseMoneyAccountBalance = jest.mocked(useMoneyAccountBalance);
4747
const mockSelectMoneyOnboardingSeen = jest.mocked(selectMoneyOnboardingSeen);
48-
const mockSelectInWalletHomeOnboardingFlow = jest.mocked(
49-
selectInWalletHomeOnboardingFlow,
48+
const mockSelectWalletHomeOnboardingFlowVisible = jest.mocked(
49+
selectWalletHomeOnboardingFlowVisible,
5050
);
5151
const mockUseMoneyNavigation = jest.mocked(useMoneyNavigation);
5252

@@ -87,7 +87,7 @@ describe('MoneyBalanceCard', () => {
8787
jest.clearAllMocks();
8888
mockUseMoneyAccountBalance.mockReturnValue(createBalanceMock());
8989
mockSelectMoneyOnboardingSeen.mockReturnValue(true);
90-
mockSelectInWalletHomeOnboardingFlow.mockReturnValue(false);
90+
mockSelectWalletHomeOnboardingFlowVisible.mockReturnValue(false);
9191
mockUseMoneyNavigation.mockReturnValue({
9292
navigateToMoneyHome: mockNavigateToMoneyHome,
9393
});
@@ -175,7 +175,7 @@ describe('MoneyBalanceCard', () => {
175175

176176
describe('when the wallet-home onboarding stepper is not displayed', () => {
177177
beforeEach(() => {
178-
mockSelectInWalletHomeOnboardingFlow.mockReturnValue(false);
178+
mockSelectWalletHomeOnboardingFlowVisible.mockReturnValue(false);
179179
});
180180

181181
it('renders the Earn button with the earn label', () => {
@@ -212,7 +212,7 @@ describe('MoneyBalanceCard', () => {
212212

213213
describe('when the wallet-home onboarding stepper is displayed', () => {
214214
beforeEach(() => {
215-
mockSelectInWalletHomeOnboardingFlow.mockReturnValue(true);
215+
mockSelectWalletHomeOnboardingFlowVisible.mockReturnValue(true);
216216
});
217217

218218
it('renders the Get started button with the get_started label', () => {

app/components/UI/Money/components/MoneyBalanceCard/MoneyBalanceCard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { strings } from '../../../../../../locales/i18n';
2626
import Routes from '../../../../../constants/navigation/Routes';
2727
import { useStyles } from '../../../../../component-library/hooks';
2828
import { selectMoneyOnboardingSeen } from '../../../../../reducers/user/selectors';
29-
import { selectInWalletHomeOnboardingFlow } from '../../../../../selectors/onboarding';
29+
import { selectWalletHomeOnboardingFlowVisible } from '../../../../../selectors/onboarding';
3030
import useMoneyAccountBalance from '../../hooks/useMoneyAccountBalance';
3131
import styleSheet from './MoneyBalanceCard.styles';
3232
import { MoneyBalanceCardTestIds } from './MoneyBalanceCard.testIds';
@@ -47,8 +47,8 @@ const MoneyBalanceCard = () => {
4747
} = useMoneyAccountBalance();
4848
const { navigateToMoneyHome } = useMoneyNavigation();
4949
const hasSeenMoneyOnboarding = useSelector(selectMoneyOnboardingSeen);
50-
const inWalletHomeOnboardingFlow = useSelector(
51-
selectInWalletHomeOnboardingFlow,
50+
const walletHomeOnboardingFlowVisible = useSelector(
51+
selectWalletHomeOnboardingFlowVisible,
5252
);
5353

5454
const isEmpty = totalFiatRaw === undefined || totalFiatRaw === '0';
@@ -62,7 +62,7 @@ const MoneyBalanceCard = () => {
6262
if (isNewUser) {
6363
balanceText = EMPTY_BALANCE_DISPLAY;
6464
containerTestId = MoneyBalanceCardTestIds.NEW_USER_CONTAINER;
65-
if (inWalletHomeOnboardingFlow) {
65+
if (walletHomeOnboardingFlowVisible) {
6666
buttonVariant = ButtonVariant.Secondary;
6767
buttonLabel = strings('homepage.sections.money_empty_state.get_started');
6868
buttonTestId = MoneyBalanceCardTestIds.GET_STARTED_BUTTON;

app/selectors/onboarding/index.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
selectWalletHomeOnboardingSteps,
66
selectWalletHomeOnboardingStepsEligible,
77
selectShouldShowWalletHomeOnboardingSteps,
8-
selectInWalletHomeOnboardingFlow,
8+
selectWalletHomeOnboardingFlowVisible,
99
} from '.';
1010
import { RootState } from '../../reducers';
1111
import { AccountType } from '../../constants/onboarding';
@@ -107,7 +107,7 @@ describe('Onboarding selectors', () => {
107107
});
108108
});
109109

110-
describe('selectInWalletHomeOnboardingFlow', () => {
110+
describe('selectWalletHomeOnboardingFlowVisible', () => {
111111
// shouldShow comes from selectShouldShowWalletHomeOnboardingSteps:
112112
// eligible && steps.suppressedReason === null.
113113
const stateWithShouldShow = (shouldShow: boolean) =>
@@ -126,33 +126,33 @@ describe('Onboarding selectors', () => {
126126
it('is true when all three inputs are true', () => {
127127
mockSelectHomepageSectionsV1Enabled.mockReturnValue(true);
128128
mockSelectWalletHomeOnboardingStepsEnabled.mockReturnValue(true);
129-
expect(selectInWalletHomeOnboardingFlow(stateWithShouldShow(true))).toBe(
130-
true,
131-
);
129+
expect(
130+
selectWalletHomeOnboardingFlowVisible(stateWithShouldShow(true)),
131+
).toBe(true);
132132
});
133133

134134
it('is false when sectionsV1 is false', () => {
135135
mockSelectHomepageSectionsV1Enabled.mockReturnValue(false);
136136
mockSelectWalletHomeOnboardingStepsEnabled.mockReturnValue(true);
137-
expect(selectInWalletHomeOnboardingFlow(stateWithShouldShow(true))).toBe(
138-
false,
139-
);
137+
expect(
138+
selectWalletHomeOnboardingFlowVisible(stateWithShouldShow(true)),
139+
).toBe(false);
140140
});
141141

142142
it('is false when stepsEnabled is false', () => {
143143
mockSelectHomepageSectionsV1Enabled.mockReturnValue(true);
144144
mockSelectWalletHomeOnboardingStepsEnabled.mockReturnValue(false);
145-
expect(selectInWalletHomeOnboardingFlow(stateWithShouldShow(true))).toBe(
146-
false,
147-
);
145+
expect(
146+
selectWalletHomeOnboardingFlowVisible(stateWithShouldShow(true)),
147+
).toBe(false);
148148
});
149149

150150
it('is false when shouldShow is false', () => {
151151
mockSelectHomepageSectionsV1Enabled.mockReturnValue(true);
152152
mockSelectWalletHomeOnboardingStepsEnabled.mockReturnValue(true);
153-
expect(selectInWalletHomeOnboardingFlow(stateWithShouldShow(false))).toBe(
154-
false,
155-
);
153+
expect(
154+
selectWalletHomeOnboardingFlowVisible(stateWithShouldShow(false)),
155+
).toBe(false);
156156
});
157157
});
158158
});

app/selectors/onboarding/index.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,9 @@ export const selectShouldShowWalletHomeOnboardingSteps = createSelector(
5555
(eligible, steps) => eligible && steps?.suppressedReason === null,
5656
);
5757

58-
// Plain (non-memoized) composition: a module-load `createSelector(...)` would
59-
// dereference these imported selectors at evaluation time, and this module is
60-
// eagerly pulled in via `app/reducers/index.ts`. Any suite that builds a store
61-
// while partially mocking `featureFlagController/homepage` would then hit
62-
// reselect's "input-selectors must be functions" assertion at require time and
63-
// take down the whole file. Composing at call time keeps it mock/cycle-safe;
64-
// the body is a trivial boolean AND over already-memoized selectors, so there
65-
// is nothing to memoize.
66-
export const selectInWalletHomeOnboardingFlow = (state: RootState): boolean =>
58+
export const selectWalletHomeOnboardingFlowVisible = (
59+
state: RootState,
60+
): boolean =>
6761
selectHomepageSectionsV1Enabled(state) &&
6862
selectWalletHomeOnboardingStepsEnabled(state) &&
6963
selectShouldShowWalletHomeOnboardingSteps(state);

0 commit comments

Comments
 (0)