diff --git a/package.json b/package.json index 74f8dce17bd6..801341ed68bb 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand", "perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", - "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=245 --cache --cache-location=node_modules/.cache/eslint", + "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=244 --cache --cache-location=node_modules/.cache/eslint", "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh", "lint-watch": "npx eslint-watch --watch --changed", "shellcheck": "./scripts/shellCheck.sh", diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index 01e51614b476..184febe9ca4c 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -113,15 +113,6 @@ Onyx.connect({ }, }); -let allTransactionDrafts: OnyxCollection = {}; -Onyx.connect({ - key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, - waitForCollectionCallback: true, - callback: (value) => { - allTransactionDrafts = value ?? {}; - }, -}); - let allReports: OnyxCollection = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, @@ -1395,10 +1386,6 @@ function getTaxName(policy: OnyxEntry, transaction: OnyxEntry taxRate.code === (transaction?.taxCode ?? defaultTaxCode))?.modifiedName; } -function getTransactionOrDraftTransaction(transactionID: string): OnyxEntry { - return allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? allTransactionDrafts?.[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`]; -} - type FieldsToCompare = Record>; type FieldsToChange = { category?: Array; @@ -1981,7 +1968,6 @@ export { isPartialTransaction, isPendingCardOrScanningTransaction, isScanning, - getTransactionOrDraftTransaction, checkIfShouldShowMarkAsCashButton, getOriginalTransactionWithSplitInfo, getTransactionPendingAction, diff --git a/src/pages/iou/request/step/IOURequestStepScan/ReceiptView/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/ReceiptView/index.tsx index fcf4e3a75b46..276cb06c59c5 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/ReceiptView/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/ReceiptView/index.tsx @@ -12,7 +12,6 @@ import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; -import {getTransactionOrDraftTransaction} from '@libs/TransactionUtils'; import type {ReceiptFile} from '@pages/iou/request/step/IOURequestStepScan/types'; import {removeDraftTransaction, removeTransactionReceipt, replaceDefaultDraftTransaction} from '@userActions/TransactionEdit'; import CONST from '@src/CONST'; @@ -37,7 +36,6 @@ function ReceiptView({route}: ReceiptViewProps) { const {setAttachmentError} = useAttachmentErrors(); const {shouldShowArrows, setShouldShowArrows, autoHideArrows, cancelAutoHideArrows} = useCarouselArrows(); const styles = useThemeStyles(); - const [currentReceipt, setCurrentReceipt] = useState(); const [page, setPage] = useState(-1); const [isDeleteReceiptConfirmModalVisible, setIsDeleteReceiptConfirmModalVisible] = useState(false); @@ -49,7 +47,8 @@ function ReceiptView({route}: ReceiptViewProps) { .filter((receipt): receipt is ReceiptWithTransactionIDAndSource => !!receipt), canBeMissing: true, }); - + const secondTransactionID = receipts.at(1)?.transactionID; + const [secondTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${secondTransactionID}`, {canBeMissing: true}); useEffect(() => { if (!receipts || receipts.length === 0) { return; @@ -74,16 +73,14 @@ function ReceiptView({route}: ReceiptViewProps) { return; } - const secondTransactionID = receipts.at(1)?.transactionID; - const secondTransaction = secondTransactionID ? getTransactionOrDraftTransaction(secondTransactionID) : undefined; - replaceDefaultDraftTransaction(secondTransaction); + replaceDefaultDraftTransaction(secondTransactionID ? secondTransaction : undefined); return; } removeDraftTransaction(currentReceipt.transactionID); }); Navigation.goBack(); - }, [currentReceipt, receipts]); + }, [currentReceipt, receipts.length, secondTransaction, secondTransactionID]); const handleCloseConfirmModal = () => { setIsDeleteReceiptConfirmModalVisible(false);