From e25506e44ea368f176190474bd1b6c6689d16c19 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 29 Apr 2024 12:54:04 +0200 Subject: [PATCH 1/6] add gps function --- .../step/IOURequestStepScan/index.native.tsx | 73 ++++++++++++------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 5a95b78779e5..59d5dd0f6aab 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -37,6 +37,7 @@ import type {Receipt} from '@src/types/onyx/Transaction'; import CameraPermission from './CameraPermission'; import NavigationAwareCamera from './NavigationAwareCamera'; import type {IOURequestStepOnyxProps, IOURequestStepScanProps} from './types'; +import getCurrentPosition from "@libs/getCurrentPosition"; function IOURequestStepScan({ report, @@ -245,32 +246,52 @@ 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, + ); + } else { + IOU.requestMoney( + report, + 0, + transaction?.currency ?? 'USD', + transaction?.created ?? '', + '', + currentUserPersonalDetails.login, + currentUserPersonalDetails.accountID, + participants[0], + '', + receipt, + ); + } + requestMoney(selectedParticipants, trimmedComment, receiptFile, { + 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 + 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, + }, ); return; } From 71d0d61530b2281f30a05a4d3e94c09f7e9b83c3 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 29 Apr 2024 12:59:03 +0200 Subject: [PATCH 2/6] handle GPS points --- .../step/IOURequestStepScan/index.native.tsx | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 59d5dd0f6aab..3fe660cdc86a 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -260,6 +260,18 @@ function IOURequestStepScan({ participants[0], '', receipt, + '', + '', + '', + 0, + false, + policy, + {}, + {}, + { + lat: successData.coords.latitude, + long: successData.coords.longitude, + } ); } else { IOU.requestMoney( @@ -273,17 +285,51 @@ function IOURequestStepScan({ participants[0], '', receipt, + '', + '', + '', + 0, + false, + policy, + {}, + {}, + { + lat: successData.coords.latitude, + long: successData.coords.longitude, + } ); } - requestMoney(selectedParticipants, trimmedComment, receiptFile, { - 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 - requestMoney(selectedParticipants, trimmedComment, receiptFile); + 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, + ); + } }, { // 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 From ed0253798c743fca7a53cc6e6148e663c9f60a6e Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 29 Apr 2024 13:12:43 +0200 Subject: [PATCH 3/6] add for web too --- .../request/step/IOURequestStepScan/index.tsx | 120 ++++++++++++++---- 1 file changed, 94 insertions(+), 26 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index c391d87e23be..c6b4eac4bda0 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -39,6 +39,8 @@ import type {Receipt} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import NavigationAwareCamera from './NavigationAwareCamera'; import type {IOURequestStepOnyxProps, IOURequestStepScanProps} from './types'; +import getCurrentPosition from "@libs/getCurrentPosition"; +import Log from "@libs/Log"; function IOURequestStepScan({ report, @@ -285,32 +287,98 @@ 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, + ); + } + }, + { + // 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, + }, ); return; } From 57365b850fd82f8b7eb37563cb3ae7586924be5a Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 29 Apr 2024 13:13:21 +0200 Subject: [PATCH 4/6] prettier --- .../iou/request/step/IOURequestStepScan/index.native.tsx | 6 +++--- src/pages/iou/request/step/IOURequestStepScan/index.tsx | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 3fe660cdc86a..905e33b53d37 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'; @@ -37,7 +38,6 @@ import type {Receipt} from '@src/types/onyx/Transaction'; import CameraPermission from './CameraPermission'; import NavigationAwareCamera from './NavigationAwareCamera'; import type {IOURequestStepOnyxProps, IOURequestStepScanProps} from './types'; -import getCurrentPosition from "@libs/getCurrentPosition"; function IOURequestStepScan({ report, @@ -271,7 +271,7 @@ function IOURequestStepScan({ { lat: successData.coords.latitude, long: successData.coords.longitude, - } + }, ); } else { IOU.requestMoney( @@ -296,7 +296,7 @@ function IOURequestStepScan({ { lat: successData.coords.latitude, long: successData.coords.longitude, - } + }, ); } }, diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index c6b4eac4bda0..e6ae28e6cc1a 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'; @@ -39,8 +41,6 @@ import type {Receipt} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import NavigationAwareCamera from './NavigationAwareCamera'; import type {IOURequestStepOnyxProps, IOURequestStepScanProps} from './types'; -import getCurrentPosition from "@libs/getCurrentPosition"; -import Log from "@libs/Log"; function IOURequestStepScan({ report, @@ -312,7 +312,7 @@ function IOURequestStepScan({ { lat: successData.coords.latitude, long: successData.coords.longitude, - } + }, ); } else { IOU.requestMoney( @@ -337,7 +337,7 @@ function IOURequestStepScan({ { lat: successData.coords.latitude, long: successData.coords.longitude, - } + }, ); } }, From 9764e0c3663f8f9a4c523ed141375096f7e8c362 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 29 Apr 2024 15:38:04 +0200 Subject: [PATCH 5/6] dependencies --- src/pages/iou/request/step/IOURequestStepScan/index.native.tsx | 1 + src/pages/iou/request/step/IOURequestStepScan/index.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 905e33b53d37..6d3ca6dbc23b 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -355,6 +355,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 e6ae28e6cc1a..c80ced70e633 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -396,6 +396,7 @@ function IOURequestStepScan({ transaction, navigateToConfirmationPage, navigateToParticipantPage, + policy, ], ); From 79ff4799fdea4594c182164029b7f70c2e50d857 Mon Sep 17 00:00:00 2001 From: Alberto Date: Fri, 3 May 2024 17:14:47 +0900 Subject: [PATCH 6/6] move to CONST --- src/CONST.ts | 8 ++++++++ .../request/step/IOURequestStepConfirmation.tsx | 14 ++++---------- .../step/IOURequestStepScan/index.native.tsx | 7 ++----- .../iou/request/step/IOURequestStepScan/index.tsx | 7 ++----- 4 files changed, 16 insertions(+), 20 deletions(-) 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 6d3ca6dbc23b..bafad583bd74 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -332,11 +332,8 @@ function IOURequestStepScan({ } }, { - // 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.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index c80ced70e633..44b32754113a 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -373,11 +373,8 @@ function IOURequestStepScan({ } }, { - // 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;