From e5e708a6b293a3706f8a1e4d38f69fbd35b89745 Mon Sep 17 00:00:00 2001 From: Kitress3 Date: Fri, 20 Feb 2026 20:38:26 -0500 Subject: [PATCH 1/2] Fix wallet statement PDF download auth in hybrid --- src/pages/wallet/WalletStatementPage.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/pages/wallet/WalletStatementPage.tsx b/src/pages/wallet/WalletStatementPage.tsx index 948225191097a..c0371fa4a4252 100644 --- a/src/pages/wallet/WalletStatementPage.tsx +++ b/src/pages/wallet/WalletStatementPage.tsx @@ -11,6 +11,8 @@ import useNetwork from '@hooks/useNetwork'; import useOnyx from '@hooks/useOnyx'; import usePrevious from '@hooks/usePrevious'; import useThemePreference from '@hooks/useThemePreference'; +import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; +import * as Browser from '@libs/Browser'; import {getOldDotURLFromEnvironment} from '@libs/Environment/Environment'; import fileDownload from '@libs/fileDownload'; import Navigation from '@libs/Navigation/Navigation'; @@ -18,6 +20,7 @@ import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavig import addTrailingForwardSlash from '@libs/UrlUtils'; import type {WalletStatementNavigatorParamList} from '@navigation/types'; import {generateStatementPDF} from '@userActions/User'; +import {emailSelector} from '@selectors/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; @@ -26,6 +29,7 @@ type WalletStatementPageProps = PlatformStackScreenProps setIsDownloading(false)); + const pdfURL = `${baseURL}secure?secureType=pdfreport&filename=${encodeURIComponent(fileName)}&downloadName=${encodeURIComponent(downloadFileName)}&email=${encodeURIComponent( + currentUserLogin, + )}`; + const pdfURLWithAuth = addEncryptedAuthTokenToURL(pdfURL, true); + fileDownload(translate, pdfURLWithAuth, downloadFileName, '', Browser.isMobileSafari()).finally(() => setIsDownloading(false)); return; } generateStatementPDF(yearMonth); - }, [baseURL, isWalletStatementGenerating, translate, walletStatement, yearMonth]); + }, [baseURL, currentUserLogin, isWalletStatementGenerating, translate, walletStatement, yearMonth]); // eslint-disable-next-line rulesdir/prefer-early-return useEffect(() => { From 3971b81e5b9be4c1fd3278971d4a80d96a9e35bd Mon Sep 17 00:00:00 2001 From: Kitress3 Date: Sat, 21 Feb 2026 16:48:21 -0500 Subject: [PATCH 2/2] Fix cached statement download when session email temporarily missing --- src/pages/wallet/WalletStatementPage.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pages/wallet/WalletStatementPage.tsx b/src/pages/wallet/WalletStatementPage.tsx index c0371fa4a4252..0fbde460bbf63 100644 --- a/src/pages/wallet/WalletStatementPage.tsx +++ b/src/pages/wallet/WalletStatementPage.tsx @@ -55,7 +55,14 @@ function WalletStatementPage({route}: WalletStatementPageProps) { } setIsDownloading(true); - if (walletStatement?.[yearMonth] && currentUserLogin) { + if (walletStatement?.[yearMonth]) { + // Avoid re-triggering generation when we already have a cached statement URL. + // `session.email` can be temporarily undefined during hydration. + if (!currentUserLogin) { + setIsDownloading(false); + return; + } + // We already have a file URL for this statement, so we can download it immediately. // Auth token and email are required so the hybrid app's native download manager can authenticate with the secure endpoint. const downloadFileName = `Expensify_Statement_${yearMonth}.pdf`;