Skip to content
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
3 changes: 1 addition & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type DynamicRoutes = Record<string, DynamicRouteConfig>;
const DYNAMIC_ROUTES = {
VERIFY_ACCOUNT: {
path: 'verify-account',
entryScreens: [],
entryScreens: [SCREENS.SETTINGS.WALLET.ROOT],
},
} as const satisfies DynamicRoutes;

Expand Down Expand Up @@ -359,7 +359,6 @@ const ROUTES = {
SETTINGS_ABOUT: 'settings/about',
SETTINGS_APP_DOWNLOAD_LINKS: 'settings/about/app-download-links',
SETTINGS_WALLET: 'settings/wallet',
SETTINGS_WALLET_VERIFY_ACCOUNT: `settings/wallet/${VERIFY_ACCOUNT}`,
SETTINGS_WALLET_DOMAIN_CARD: {
route: 'settings/wallet/card/:cardID?',
getRoute: (cardID: string) => `settings/wallet/card/${cardID}` as const,
Expand Down
1 change: 0 additions & 1 deletion src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ const SCREENS = {

WALLET: {
ROOT: 'Settings_Wallet',
VERIFY_ACCOUNT: 'Settings_Wallet_VerifyAccount',
DOMAIN_CARD: 'Settings_Wallet_DomainCard',
DOMAIN_CARD_CONFIRM_MAGIC_CODE: 'Settings_Wallet_DomainCard_ConfirmMagicCode',
CARD_MISSING_DETAILS: 'Settings_Wallet_Card_MissingDetails',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.SETTINGS.CLOSE]: () => require<ReactComponentModule>('../../../../pages/settings/Security/CloseAccountPage').default,
[SCREENS.SETTINGS.APP_DOWNLOAD_LINKS]: () => require<ReactComponentModule>('../../../../pages/settings/AppDownloadLinks').default,
[SCREENS.SETTINGS.WALLET.CARDS_DIGITAL_DETAILS_UPDATE_ADDRESS]: () => require<ReactComponentModule>('../../../../pages/settings/Profile/PersonalDetails/PersonalAddressPage').default,
[SCREENS.SETTINGS.WALLET.VERIFY_ACCOUNT]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/VerifyAccountPage').default,
[SCREENS.SETTINGS.WALLET.DOMAIN_CARD]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/ExpensifyCardPage/index').default,
[SCREENS.SETTINGS.WALLET.DOMAIN_CARD_CONFIRM_MAGIC_CODE]: () =>
require<ReactComponentModule>('../../../../pages/settings/Wallet/ExpensifyCardPage/ExpensifyCardVerifyAccountPage').default,
Expand Down
9 changes: 4 additions & 5 deletions src/libs/Navigation/helpers/getLastSuffixFromPath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Log from '@libs/Log';
import splitPathAndQuery from './splitPathAndQuery';

/**
* Extracts the last segment from a URL path, removing query parameters and trailing slashes.
Expand All @@ -7,16 +8,14 @@ import Log from '@libs/Log';
* @returns The last segment of the path as a string
*/
function getLastSuffixFromPath(path: string | undefined): string {
const pathWithoutParams = path?.split('?').at(0);
const [normalizedPath] = splitPathAndQuery(path ?? '');

if (!pathWithoutParams) {
if (!normalizedPath) {
Log.warn('[getLastSuffixFromPath.ts] Failed to parse the path, path is empty');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: We changed the error to warn and now returning ''. Are we sure it won't cause regression elsewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should be safe from regressions. Since we verify that the path exists before calling this function, that if statement is effectively unreachable. It was added primarily to satisfy TypeScript/ESLint requirements

return '';
}

const pathWithoutTrailingSlash = pathWithoutParams.endsWith('/') ? pathWithoutParams.slice(0, -1) : pathWithoutParams;

const lastSuffix = pathWithoutTrailingSlash.split('/').pop() ?? '';
const lastSuffix = normalizedPath.split('/').pop() ?? '';

return lastSuffix;
}
Expand Down
9 changes: 3 additions & 6 deletions src/libs/Navigation/helpers/getPathFromState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import type {NavigationState, PartialState} from '@react-navigation/routers';
import {linkingConfig} from '@libs/Navigation/linkingConfig';
import {normalizedConfigs} from '@libs/Navigation/linkingConfig/config';
import {DYNAMIC_ROUTES} from '@src/ROUTES';
import type {DynamicRouteSuffix} from '@src/ROUTES';
import type {Screen} from '@src/SCREENS';

type State = NavigationState | Omit<PartialState<NavigationState>, 'stale'>;

const dynamicRouteEntries = Object.values(DYNAMIC_ROUTES);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: Do you think using Set makes more sense? We're looping for every call in isDynamicRouteScreen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Switching to a Set is a smart optimization for the future, even though we currently don't have many dynamic routes. I'll update the function. Thanks for the suggestion! 👍

const dynamicRoutePaths = new Set(dynamicRouteEntries.map(({path}) => path));

/**
* Checks if a screen name is a dynamic route screen
Expand All @@ -19,12 +21,7 @@ function isDynamicRouteScreen(screenName: Screen): boolean {
return false;
}

for (const {path} of dynamicRouteEntries) {
if (screenPath === path) {
return true;
}
}
return false;
return dynamicRoutePaths.has(screenPath as DynamicRouteSuffix);
}

const getPathFromState = (state: State): string => {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/helpers/splitPathAndQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* and the second element is the query string (if any).
*/
function splitPathAndQuery(fullPath: string | undefined): [string | undefined, string | undefined] {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it's best we add some unit tests for the same.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I can see the tests are added in the next PR #81859 (review)

const [path, query] = fullPath?.split('?') ?? [undefined, undefined];
const [path, query] = fullPath?.split('?', 2) ?? [undefined, undefined];
const normalizedPath = path?.endsWith('/') && path.length > 1 ? path.slice(0, -1) : path;
return [normalizedPath, query];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: I am not sure if the paths in our App have # in the query string? do you think it could be an issue here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't believe we use # in our query strings, so we should be safe here

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const SETTINGS_TO_RHP: Partial<Record<keyof SettingsSplitNavigatorParamList, str
SCREENS.SETTINGS.WALLET.PERSONAL_CARD_DETAILS,
SCREENS.SETTINGS.WALLET.PERSONAL_CARD_EDIT_NAME,
SCREENS.SETTINGS.WALLET.PERSONAL_CARD_EDIT_TRANSACTION_START_DATE,
SCREENS.SETTINGS.WALLET.VERIFY_ACCOUNT,
SCREENS.SETTINGS.WALLET.TRANSFER_BALANCE,
SCREENS.SETTINGS.WALLET.CHOOSE_TRANSFER_ACCOUNT,
SCREENS.SETTINGS.WALLET.IMPORT_TRANSACTIONS,
Expand Down
4 changes: 0 additions & 4 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
path: ROUTES.SETTINGS_WALLET_CARD_MISSING_DETAILS_CONFIRM_MAGIC_CODE.route,
exact: true,
},
[SCREENS.SETTINGS.WALLET.VERIFY_ACCOUNT]: {
path: ROUTES.SETTINGS_WALLET_VERIFY_ACCOUNT,
exact: true,
},
[SCREENS.SETTINGS.WALLET.REPORT_VIRTUAL_CARD_FRAUD]: {
path: ROUTES.SETTINGS_REPORT_FRAUD.route,
exact: true,
Expand Down
1 change: 0 additions & 1 deletion src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ type SettingsNavigatorParamList = {
[SCREENS.WORKSPACE.WORKFLOWS_PAYER]: {
policyID: string;
};
[SCREENS.SETTINGS.WALLET.VERIFY_ACCOUNT]: undefined;
[SCREENS.SETTINGS.WALLET.TRANSFER_BALANCE]: undefined;
[SCREENS.SETTINGS.WALLET.CHOOSE_TRANSFER_ACCOUNT]: undefined;
[SCREENS.SETTINGS.WALLET.IMPORT_TRANSACTIONS]: undefined;
Expand Down
10 changes: 7 additions & 3 deletions src/pages/settings/DynamicVerifyAccountPage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need to add a new page prefixing Dynamic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think, that's a great way to clearly distinguish between static and dynamic pages, I’ll update the documentation to include this context. As a follow-up I’m also planning to add an ESLint rule to help validate these naming conventions for dynamic screens and components 😄

import useDynamicBackPath from '@hooks/useDynamicBackPath';
import {DYNAMIC_ROUTES} from '@src/ROUTES';
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
import VerifyAccountPageBase from './VerifyAccountPageBase';

function DynamicVerifyAccountPage() {
const backPath = useDynamicBackPath(DYNAMIC_ROUTES.VERIFY_ACCOUNT.path);
// currently, the default behavior of this component after completing verification is to navigate back
const forwardPath = backPath;

let forwardPath = backPath;
if (backPath === ROUTES.SETTINGS_WALLET) {
forwardPath = ROUTES.SETTINGS_ENABLE_PAYMENTS;
Comment thread
collectioneur marked this conversation as resolved.
Resolved
}

return (
<VerifyAccountPageBase
navigateBackTo={backPath}
Expand Down
14 changes: 0 additions & 14 deletions src/pages/settings/Wallet/VerifyAccountPage.tsx

This file was deleted.

5 changes: 3 additions & 2 deletions src/pages/settings/Wallet/WalletPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {hasDisplayableAssignedCards, maskCardNumber} from '@libs/CardUtils';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import createDynamicRoute from '@libs/Navigation/helpers/createDynamicRoute';
import Navigation from '@libs/Navigation/Navigation';
import {formatPaymentMethods, getPaymentMethodDescription} from '@libs/PaymentUtils';
import {getDescriptionForPolicyDomainCard, hasActiveAdminWorkspaces, hasEligibleActiveAdminFromWorkspaces} from '@libs/PolicyUtils';
Expand All @@ -47,7 +48,7 @@ import {clearWalletError, clearWalletTermsError, deletePaymentCard, getPaymentMe
import {navigateToBankAccountRoute} from '@userActions/ReimbursementAccount';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import {getEmptyObject} from '@src/types/utils/EmptyObject';
import type {CardPressHandlerParams, PaymentMethodPressHandlerParams} from './types';
Expand Down Expand Up @@ -717,7 +718,7 @@ function WalletPage() {
}

if (!isUserValidated) {
Navigation.navigate(ROUTES.SETTINGS_WALLET_VERIFY_ACCOUNT);
Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.VERIFY_ACCOUNT.path));
return;
}
Navigation.navigate(ROUTES.SETTINGS_ENABLE_PAYMENTS);
Expand Down
Loading