Skip to content

Commit 738111c

Browse files
authored
Merge pull request #52799 from Expensify/blimpich-fixStatementsOnStagingUrl
fix statement modal being broken on staging environment
2 parents 85d8b88 + 7dbe07e commit 738111c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/libs/Environment/Environment.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Config from 'react-native-config';
22
import CONFIG from '@src/CONFIG';
33
import CONST from '@src/CONST';
44
import getEnvironment from './getEnvironment';
5+
import type Environment from './getEnvironment/types';
56

67
const ENVIRONMENT_URLS = {
78
[CONST.ENVIRONMENT.DEV]: CONST.DEV_NEW_EXPENSIFY_URL + CONFIG.DEV_PORT,
@@ -47,11 +48,18 @@ function getEnvironmentURL(): Promise<string> {
4748
});
4849
}
4950

51+
/**
52+
* Given the environment get the corresponding oldDot URL
53+
*/
54+
function getOldDotURLFromEnvironment(environment: Environment): string {
55+
return OLDDOT_ENVIRONMENT_URLS[environment];
56+
}
57+
5058
/**
5159
* Get the corresponding oldDot URL based on the environment we are in
5260
*/
5361
function getOldDotEnvironmentURL(): Promise<string> {
5462
return getEnvironment().then((environment) => OLDDOT_ENVIRONMENT_URLS[environment]);
5563
}
5664

57-
export {getEnvironment, isInternalTestBuild, isDevelopment, isProduction, getEnvironmentURL, getOldDotEnvironmentURL};
65+
export {getEnvironment, isInternalTestBuild, isDevelopment, isProduction, getEnvironmentURL, getOldDotEnvironmentURL, getOldDotURLFromEnvironment};

src/pages/wallet/WalletStatementPage.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOffli
77
import HeaderWithBackButton from '@components/HeaderWithBackButton';
88
import ScreenWrapper from '@components/ScreenWrapper';
99
import WalletStatementModal from '@components/WalletStatementModal';
10+
import useEnvironment from '@hooks/useEnvironment';
1011
import useLocalize from '@hooks/useLocalize';
1112
import useNetwork from '@hooks/useNetwork';
1213
import usePrevious from '@hooks/usePrevious';
1314
import useThemePreference from '@hooks/useThemePreference';
1415
import DateUtils from '@libs/DateUtils';
16+
import {getOldDotURLFromEnvironment} from '@libs/Environment/Environment';
1517
import fileDownload from '@libs/fileDownload';
1618
import Navigation from '@libs/Navigation/Navigation';
19+
import {addTrailingForwardSlash} from '@libs/Url';
1720
import type {WalletStatementNavigatorParamList} from '@navigation/types';
1821
import * as User from '@userActions/User';
19-
import CONFIG from '@src/CONFIG';
2022
import CONST from '@src/CONST';
2123
import ONYXKEYS from '@src/ONYXKEYS';
2224
import type SCREENS from '@src/SCREENS';
@@ -31,8 +33,11 @@ function WalletStatementPage({route}: WalletStatementPageProps) {
3133
const prevIsWalletStatementGenerating = usePrevious(isWalletStatementGenerating);
3234
const [isDownloading, setIsDownloading] = useState(isWalletStatementGenerating);
3335
const {translate, preferredLocale} = useLocalize();
36+
const {environment} = useEnvironment();
3437
const {isOffline} = useNetwork();
3538

39+
const baseURL = addTrailingForwardSlash(getOldDotURLFromEnvironment(environment));
40+
3641
useEffect(() => {
3742
const currentYearMonth = format(new Date(), CONST.DATE.YEAR_MONTH_FORMAT);
3843
if (!yearMonth || yearMonth.length !== 6 || yearMonth > currentYearMonth) {
@@ -55,13 +60,13 @@ function WalletStatementPage({route}: WalletStatementPageProps) {
5560
// We already have a file URL for this statement, so we can download it immediately
5661
const downloadFileName = `Expensify_Statement_${yearMonth}.pdf`;
5762
const fileName = walletStatement[yearMonth];
58-
const pdfURL = `${CONFIG.EXPENSIFY.EXPENSIFY_URL}secure?secureType=pdfreport&filename=${fileName}&downloadName=${downloadFileName}`;
63+
const pdfURL = `${baseURL}secure?secureType=pdfreport&filename=${fileName}&downloadName=${downloadFileName}`;
5964
fileDownload(pdfURL, downloadFileName).finally(() => setIsDownloading(false));
6065
return;
6166
}
6267

6368
User.generateStatementPDF(yearMonth);
64-
}, [isWalletStatementGenerating, walletStatement, yearMonth]);
69+
}, [baseURL, isWalletStatementGenerating, walletStatement, yearMonth]);
6570

6671
// eslint-disable-next-line rulesdir/prefer-early-return
6772
useEffect(() => {
@@ -79,7 +84,7 @@ function WalletStatementPage({route}: WalletStatementPageProps) {
7984
const month = yearMonth?.substring(4) || getMonth(new Date());
8085
const monthName = format(new Date(Number(year), Number(month) - 1), CONST.DATE.MONTH_FORMAT);
8186
const title = translate('statementPage.title', {year, monthName});
82-
const url = `${CONFIG.EXPENSIFY.EXPENSIFY_URL}statement.php?period=${yearMonth}${themePreference === CONST.THEME.DARK ? '&isDarkMode=true' : ''}`;
87+
const url = `${baseURL}statement.php?period=${yearMonth}${themePreference === CONST.THEME.DARK ? '&isDarkMode=true' : ''}`;
8388

8489
return (
8590
<ScreenWrapper

0 commit comments

Comments
 (0)