From d070ad48c48b166461ee8f45b69b3d6dd22f2d53 Mon Sep 17 00:00:00 2001 From: Rocio Perez-Cano Date: Mon, 17 Jun 2024 16:13:04 -0400 Subject: [PATCH 1/4] New beta --- src/CONST.ts | 1 + src/libs/Permissions.ts | 6 ++++++ src/libs/TransactionUtils.ts | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/src/CONST.ts b/src/CONST.ts index 9311816c38a2..6b9e033cdd4b 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -356,6 +356,7 @@ const CONST = { CHRONOS_IN_CASH: 'chronosInCash', DEFAULT_ROOMS: 'defaultRooms', VIOLATIONS: 'violations', + DUPE_DETECTION: 'dupeDetection', REPORT_FIELDS: 'reportFields', P2P_DISTANCE_REQUESTS: 'p2pDistanceRequests', WORKFLOWS_DELAYED_SUBMISSION: 'workflowsDelayedSubmission', diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 45551fe1cad9..ee44af82f7da 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -23,6 +23,11 @@ function canUseViolations(betas: OnyxEntry): boolean { return !!betas?.includes(CONST.BETAS.VIOLATIONS) || canUseAllBetas(betas); } +function canUseDupeDetection(betas: OnyxEntry): boolean { + return !!betas?.includes(CONST.BETAS.DUPE_DETECTION) || canUseAllBetas(betas); +} + + function canUseP2PDistanceRequests(betas: OnyxEntry, iouType: IOUType | undefined): boolean { // Allow using P2P distance request for TrackExpense outside of the beta, because that project doesn't want to be limited by the more cautious P2P distance beta return !!betas?.includes(CONST.BETAS.P2P_DISTANCE_REQUESTS) || canUseAllBetas(betas) || iouType === CONST.IOU.TYPE.TRACK; @@ -56,6 +61,7 @@ export default { canUseDefaultRooms, canUseLinkPreviews, canUseViolations, + canUseDupeDetection, canUseReportFields, canUseP2PDistanceRequests, canUseWorkflowsDelayedSubmission, diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index cfeb866e572f..66fc196cbb16 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -13,6 +13,7 @@ import DateUtils from './DateUtils'; import * as Localize from './Localize'; import * as NumberUtils from './NumberUtils'; import {getCleanedTagName, getCustomUnitRate} from './PolicyUtils'; +import Permissions from "@libs/Permissions"; let allTransactions: OnyxCollection = {}; Onyx.connect({ @@ -640,6 +641,10 @@ function getRecentTransactions(transactions: Record, size = 2): * @param checkDismissed - whether to check if the violation has already been dismissed as well */ function isDuplicate(transactionID: string, checkDismissed = false): boolean { + if (Permissions.canUseDupeDetection(allBetas ?? [])) { + return false; + } + const hasDuplicatedViolation = !!allTransactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]?.some( (violation: TransactionViolation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION, ); From 3c7d2f756b4cbff1eae4bd6a11c7bc4f272d5b26 Mon Sep 17 00:00:00 2001 From: Rocio Perez-Cano Date: Mon, 17 Jun 2024 16:16:15 -0400 Subject: [PATCH 2/4] Check for message --- src/libs/TransactionUtils.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 66fc196cbb16..6a4d3533353b 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -14,6 +14,7 @@ import * as Localize from './Localize'; import * as NumberUtils from './NumberUtils'; import {getCleanedTagName, getCustomUnitRate} from './PolicyUtils'; import Permissions from "@libs/Permissions"; +import {Beta} from "@src/types/onyx"; let allTransactions: OnyxCollection = {}; Onyx.connect({ @@ -51,6 +52,12 @@ Onyx.connect({ }, }); +let allBetas: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.BETAS, + callback: (value) => (allBetas = value), +}); + function isDistanceRequest(transaction: OnyxEntry): boolean { // This is used during the expense creation flow before the transaction has been saved to the server if (lodashHas(transaction, 'iouRequestType')) { @@ -641,7 +648,7 @@ function getRecentTransactions(transactions: Record, size = 2): * @param checkDismissed - whether to check if the violation has already been dismissed as well */ function isDuplicate(transactionID: string, checkDismissed = false): boolean { - if (Permissions.canUseDupeDetection(allBetas ?? [])) { + if (!Permissions.canUseDupeDetection(allBetas ?? [])) { return false; } @@ -698,6 +705,10 @@ function hasNoticeTypeViolation(transactionID: string, transactionViolations: On * Checks if any violations for the provided transaction are of type 'warning' */ function hasWarningTypeViolation(transactionID: string, transactionViolations: OnyxCollection): boolean { + if (!Permissions.canUseDupeDetection(allBetas ?? [])) { + return false; + } + return !!transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some((violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.WARNING); } From 7bfda311031bab438e886827dfd516cecfc43dd9 Mon Sep 17 00:00:00 2001 From: Rocio Perez-Cano Date: Mon, 17 Jun 2024 16:28:17 -0400 Subject: [PATCH 3/4] Linter --- src/libs/TransactionUtils.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 6a4d3533353b..4aa9bef3e50f 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -4,7 +4,7 @@ import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {OnyxInputOrEntry, Policy, RecentWaypoint, Report, TaxRate, TaxRates, Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx'; +import type {Beta, OnyxInputOrEntry, Policy, RecentWaypoint, Report, TaxRate, TaxRates, Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx'; import type {Comment, Receipt, TransactionChanges, TransactionPendingFieldsKey, Waypoint, WaypointCollection} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type {IOURequestType} from './actions/IOU'; @@ -12,9 +12,8 @@ import {isCorporateCard, isExpensifyCard} from './CardUtils'; import DateUtils from './DateUtils'; import * as Localize from './Localize'; import * as NumberUtils from './NumberUtils'; +import Permissions from "./Permissions"; import {getCleanedTagName, getCustomUnitRate} from './PolicyUtils'; -import Permissions from "@libs/Permissions"; -import {Beta} from "@src/types/onyx"; let allTransactions: OnyxCollection = {}; Onyx.connect({ From 9a7b9ae3aec50c29c1668a5ca46857afe5421386 Mon Sep 17 00:00:00 2001 From: Rocio Perez-Cano Date: Mon, 17 Jun 2024 16:36:53 -0400 Subject: [PATCH 4/4] prettier --- src/libs/Permissions.ts | 1 - src/libs/TransactionUtils.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index ee44af82f7da..7ef4c9325a14 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -27,7 +27,6 @@ function canUseDupeDetection(betas: OnyxEntry): boolean { return !!betas?.includes(CONST.BETAS.DUPE_DETECTION) || canUseAllBetas(betas); } - function canUseP2PDistanceRequests(betas: OnyxEntry, iouType: IOUType | undefined): boolean { // Allow using P2P distance request for TrackExpense outside of the beta, because that project doesn't want to be limited by the more cautious P2P distance beta return !!betas?.includes(CONST.BETAS.P2P_DISTANCE_REQUESTS) || canUseAllBetas(betas) || iouType === CONST.IOU.TYPE.TRACK; diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 4aa9bef3e50f..c6b9f56378bd 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -12,7 +12,7 @@ import {isCorporateCard, isExpensifyCard} from './CardUtils'; import DateUtils from './DateUtils'; import * as Localize from './Localize'; import * as NumberUtils from './NumberUtils'; -import Permissions from "./Permissions"; +import Permissions from './Permissions'; import {getCleanedTagName, getCustomUnitRate} from './PolicyUtils'; let allTransactions: OnyxCollection = {};