Skip to content

Commit

Permalink
Merge pull request #41208 from Expensify/alberto-gps
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored May 6, 2024
2 parents 8787a64 + 79ff479 commit a395fb3
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 62 deletions.
8 changes: 8 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
14 changes: 4 additions & 10 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
117 changes: 91 additions & 26 deletions src/pages/iou/request/step/IOURequestStepScan/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand All @@ -288,6 +352,7 @@ function IOURequestStepScan({
transaction,
navigateToConfirmationPage,
navigateToParticipantPage,
policy,
],
);

Expand Down
118 changes: 92 additions & 26 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand All @@ -328,6 +393,7 @@ function IOURequestStepScan({
transaction,
navigateToConfirmationPage,
navigateToParticipantPage,
policy,
],
);

Expand Down

0 comments on commit a395fb3

Please sign in to comment.