Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using OpenOldDotLink #9943

Merged
merged 2 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/libs/actions/Link.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Onyx from 'react-native-onyx';
import lodashGet from 'lodash/get';
import {Linking} from 'react-native';
import ONYXKEYS from '../../ONYXKEYS';
import Growl from '../Growl';
import * as Localize from '../Localize';
import CONST from '../../CONST';
import * as DeprecatedAPI from '../deprecatedAPI';
import CONFIG from '../../CONFIG';
import asyncOpenURL from '../asyncOpenURL';
import * as API from '../API';

let isNetworkOffline = false;
Onyx.connect({
Expand Down Expand Up @@ -38,15 +39,25 @@ function openOldDotLink(url) {
return;
}

function buildOldDotURL({shortLivedAuthToken}) {
function buildOldDotURL(shortLivedAuthToken) {
const hasHashParams = url.indexOf('#') !== -1;
const hasURLParams = url.indexOf('?') !== -1;

// If the URL contains # or ?, we can assume they don't need to have the `?` token to start listing url parameters.
return `${CONFIG.EXPENSIFY.EXPENSIFY_URL}${url}${hasHashParams || hasURLParams ? '&' : '?'}authToken=${shortLivedAuthToken}&email=${encodeURIComponent(currentUserEmail)}`;
}

asyncOpenURL(DeprecatedAPI.GetShortLivedAuthToken(), buildOldDotURL);
// We use makeRequestWithSideEffects here because we need to block until after we get the shortLivedAuthToken back from the server (link won't work without it!).
// eslint-disable-next-line rulesdir/no-api-side-effects-method
API.makeRequestWithSideEffects(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing AsyncOpenURL caused a bug on Safari browsers #21189

'OpenOldDotLink', {}, {},
).then((response) => {
if (response.jsonCode === 200) {
Linking.openURL(buildOldDotURL(response.shortLivedAuthToken));
} else {
Growl.show(response.message, CONST.GROWL.WARNING);
}
});
}

/**
Expand Down
10 changes: 0 additions & 10 deletions src/libs/deprecatedAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,6 @@ function GetAccountStatus(parameters) {
return Network.post(commandName, parameters);
}

/**
* Returns a short lived authToken for this account
* @returns {Promise}
*/
function GetShortLivedAuthToken() {
const commandName = 'GetShortLivedAuthToken';
return Network.post(commandName);
}

/**
* @param {Object} parameters
* @param {String} parameters.debtorEmail
Expand Down Expand Up @@ -842,7 +833,6 @@ export {
DeleteBankAccount,
Get,
GetAccountStatus,
GetShortLivedAuthToken,
GetStatementPDF,
GetIOUReport,
GetFullPolicy,
Expand Down