Skip to content

Commit

Permalink
Merge pull request #5802 from Expensify/cmartins-fixOpenOldDotLink
Browse files Browse the repository at this point in the history
Open OldDot links on Safari
  • Loading branch information
luacmartins authored Oct 13, 2021
2 parents 185f43d + 75b398f commit 6e74f2a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/libs/actions/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {translateLocal} from '../translate';
import CONST from '../../CONST';
import * as API from '../API';
import CONFIG from '../../CONFIG';
import asyncOpenURL from '../asyncOpenURL';

let isNetworkOffline = false;
Onyx.connect({
Expand Down Expand Up @@ -35,10 +36,9 @@ function showGrowlIfOffline() {
*/
function openOldDotLink(url) {
if (!showGrowlIfOffline()) {
API.GetShortLivedAuthToken().then(({shortLivedAuthToken}) => {
// eslint-disable-next-line max-len
Linking.openURL(`${CONFIG.EXPENSIFY.URL_EXPENSIFY_COM}${url}${url.indexOf('?') === -1 ? '?' : '&'}authToken=${shortLivedAuthToken}&email=${encodeURIComponent(currentUserEmail)}`);
});
// eslint-disable-next-line max-len
const buildOldDotURL = ({shortLivedAuthToken}) => `${CONFIG.EXPENSIFY.URL_EXPENSIFY_COM}${url}${url.indexOf('?') === -1 ? '?' : '&'}authToken=${shortLivedAuthToken}&email=${encodeURIComponent(currentUserEmail)}`;
asyncOpenURL(API.GetShortLivedAuthToken(), buildOldDotURL);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libs/asyncOpenURL/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function asyncOpenURL(promise, url) {
return;
}

promise.then(() => {
Linking.openURL(url);
promise.then((params) => {
Linking.openURL(typeof url === 'string' ? url : url(params));
});
}
8 changes: 4 additions & 4 deletions src/libs/asyncOpenURL/index.website.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export default function asyncOpenURL(promise, url) {
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);

if (!isSafari) {
promise.then(() => {
Linking.openURL(url);
promise.then((params) => {
Linking.openURL(typeof url === 'string' ? url : url(params));
});
} else {
const windowRef = window.open();
promise
.then(() => {
windowRef.location = url;
.then((params) => {
windowRef.location = typeof url === 'string' ? url : url(params);
})
.catch(() => windowRef.close());
}
Expand Down

0 comments on commit 6e74f2a

Please sign in to comment.