diff --git a/src/CONST.ts b/src/CONST.ts index 310bb3959300..225b0bc8cea5 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -148,6 +148,14 @@ const CONST = { RESERVED_NAMES: ['Expensify', 'Concierge'], }, + GPS: { + // It's OK to get a cached location that is up to an hour old because the only accuracy needed is the country the user is in + MAX_AGE: 3600000, + + // 15 seconds, don't wait too long because the server can always fall back to using the IP address + TIMEOUT: 15000, + }, + LEGAL_NAME: { MAX_LENGTH: 40, }, diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index e33e4d8fb763..9d5bb4317c2d 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -400,11 +400,8 @@ function IOURequestStepConfirmation({ trackExpense(selectedParticipants, trimmedComment, receiptFile); }, { - // It's OK to get a cached location that is up to an hour old because the only accuracy needed is the country the user is in - maximumAge: 1000 * 60 * 60, - - // 15 seconds, don't wait too long because the server can always fall back to using the IP address - timeout: 15000, + maximumAge: CONST.GPS.MAX_AGE, + timeout: CONST.GPS.TIMEOUT, }, ); return; @@ -434,11 +431,8 @@ function IOURequestStepConfirmation({ requestMoney(selectedParticipants, trimmedComment, receiptFile); }, { - // It's OK to get a cached location that is up to an hour old because the only accuracy needed is the country the user is in - maximumAge: 1000 * 60 * 60, - - // 15 seconds, don't wait too long because the server can always fall back to using the IP address - timeout: 15000, + maximumAge: CONST.GPS.MAX_AGE, + timeout: CONST.GPS.TIMEOUT, }, ); return; diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 5a95b78779e5..bafad583bd74 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -22,6 +22,7 @@ import useLocalize from '@hooks/useLocalize'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import * as FileUtils from '@libs/fileDownload/FileUtils'; +import getCurrentPosition from '@libs/getCurrentPosition'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; @@ -245,32 +246,95 @@ function IOURequestStepScan({ }); return; } - if (iouType === CONST.IOU.TYPE.TRACK && report) { - IOU.trackExpense( - report, - 0, - transaction?.currency ?? 'USD', - transaction?.created ?? '', - '', - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - participants[0], - '', - receipt, - ); - return; - } - IOU.requestMoney( - report, - 0, - transaction?.currency ?? 'USD', - transaction?.created ?? '', - '', - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - participants[0], - '', - receipt, + getCurrentPosition( + (successData) => { + if (iouType === CONST.IOU.TYPE.TRACK && report) { + IOU.trackExpense( + report, + 0, + transaction?.currency ?? 'USD', + transaction?.created ?? '', + '', + currentUserPersonalDetails.login, + currentUserPersonalDetails.accountID, + participants[0], + '', + receipt, + '', + '', + '', + 0, + false, + policy, + {}, + {}, + { + lat: successData.coords.latitude, + long: successData.coords.longitude, + }, + ); + } else { + IOU.requestMoney( + report, + 0, + transaction?.currency ?? 'USD', + transaction?.created ?? '', + '', + currentUserPersonalDetails.login, + currentUserPersonalDetails.accountID, + participants[0], + '', + receipt, + '', + '', + '', + 0, + false, + policy, + {}, + {}, + { + lat: successData.coords.latitude, + long: successData.coords.longitude, + }, + ); + } + }, + (errorData) => { + Log.info('[IOURequestStepScan] getCurrentPosition failed', false, errorData); + // When there is an error, the money can still be requested, it just won't include the GPS coordinates + if (iouType === CONST.IOU.TYPE.TRACK && report) { + IOU.trackExpense( + report, + 0, + transaction?.currency ?? 'USD', + transaction?.created ?? '', + '', + currentUserPersonalDetails.login, + currentUserPersonalDetails.accountID, + participants[0], + '', + receipt, + ); + } else { + IOU.requestMoney( + report, + 0, + transaction?.currency ?? 'USD', + transaction?.created ?? '', + '', + currentUserPersonalDetails.login, + currentUserPersonalDetails.accountID, + participants[0], + '', + receipt, + ); + } + }, + { + maximumAge: CONST.GPS.MAX_AGE, + timeout: CONST.GPS.TIMEOUT, + }, ); return; } @@ -288,6 +352,7 @@ function IOURequestStepScan({ transaction, navigateToConfirmationPage, navigateToParticipantPage, + policy, ], ); diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index c391d87e23be..44b32754113a 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -23,6 +23,8 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as Browser from '@libs/Browser'; import * as FileUtils from '@libs/fileDownload/FileUtils'; +import getCurrentPosition from '@libs/getCurrentPosition'; +import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -285,32 +287,95 @@ function IOURequestStepScan({ }); return; } - if (iouType === CONST.IOU.TYPE.TRACK && report) { - IOU.trackExpense( - report, - 0, - transaction?.currency ?? 'USD', - transaction?.created ?? '', - '', - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - participants[0], - '', - receipt, - ); - return; - } - IOU.requestMoney( - report, - 0, - transaction?.currency ?? 'USD', - transaction?.created ?? '', - '', - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - participants[0], - '', - receipt, + getCurrentPosition( + (successData) => { + if (iouType === CONST.IOU.TYPE.TRACK && report) { + IOU.trackExpense( + report, + 0, + transaction?.currency ?? 'USD', + transaction?.created ?? '', + '', + currentUserPersonalDetails.login, + currentUserPersonalDetails.accountID, + participants[0], + '', + receipt, + '', + '', + '', + 0, + false, + policy, + {}, + {}, + { + lat: successData.coords.latitude, + long: successData.coords.longitude, + }, + ); + } else { + IOU.requestMoney( + report, + 0, + transaction?.currency ?? 'USD', + transaction?.created ?? '', + '', + currentUserPersonalDetails.login, + currentUserPersonalDetails.accountID, + participants[0], + '', + receipt, + '', + '', + '', + 0, + false, + policy, + {}, + {}, + { + lat: successData.coords.latitude, + long: successData.coords.longitude, + }, + ); + } + }, + (errorData) => { + Log.info('[IOURequestStepScan] getCurrentPosition failed', false, errorData); + // When there is an error, the money can still be requested, it just won't include the GPS coordinates + if (iouType === CONST.IOU.TYPE.TRACK && report) { + IOU.trackExpense( + report, + 0, + transaction?.currency ?? 'USD', + transaction?.created ?? '', + '', + currentUserPersonalDetails.login, + currentUserPersonalDetails.accountID, + participants[0], + '', + receipt, + ); + } else { + IOU.requestMoney( + report, + 0, + transaction?.currency ?? 'USD', + transaction?.created ?? '', + '', + currentUserPersonalDetails.login, + currentUserPersonalDetails.accountID, + participants[0], + '', + receipt, + ); + } + }, + { + maximumAge: CONST.GPS.MAX_AGE, + timeout: CONST.GPS.TIMEOUT, + }, ); return; } @@ -328,6 +393,7 @@ function IOURequestStepScan({ transaction, navigateToConfirmationPage, navigateToParticipantPage, + policy, ], );