From 861428a99b6bc1c90c1663115a2dcbbdcfc9ca6d Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Tue, 27 Jul 2021 17:47:37 +0200 Subject: [PATCH 1/7] Make sure users are signed in when clicking on managed cards --- src/CONST.js | 8 +++++-- src/ROUTES.js | 27 ++++++++++++++++++++++++ src/libs/API.js | 10 +++++++++ src/pages/workspace/WorkspaceCardPage.js | 10 +++------ 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 1b0a49e36d181..46b4fb47a52eb 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -124,8 +124,12 @@ const CONST = { PRIVACY_URL: 'https://use.expensify.com/privacy', LICENSES_URL: 'https://use.expensify.com/licenses', PLAY_STORE_URL: 'https://play.google.com/store/apps/details?id=com.expensify.chat&hl=en', - ADD_SECONDARY_LOGIN_URL: 'settings?param={%22section%22:%22account%22}', - MANAGE_CARDS_URL: 'domain_companycards', + ADD_SECONDARY_LOGIN_URL: '/settings?param={%22section%22:%22account%22}', + VALIDATE_CODE_URL: (accountID, validateCode, exitTo = '') => { + const exitToURL = exitTo ? `?exitTo=${exitTo}` : ''; + return `v/${accountID}/${validateCode}${exitToURL}`; + }, + MANAGE_CARDS_URL: '/domain_companycards', OPTION_TYPE: { REPORT: 'report', PERSONAL_DETAIL: 'personalDetail', diff --git a/src/ROUTES.js b/src/ROUTES.js index bbe1883d441e0..9155a2c492971 100644 --- a/src/ROUTES.js +++ b/src/ROUTES.js @@ -1,5 +1,11 @@ import lodashGet from 'lodash/get'; +import {Linking} from 'react-native'; +import Onyx from 'react-native-onyx'; import {addTrailingForwardSlash} from './libs/Url'; +import {GetAccountValidateCode} from './libs/API'; +import CONFIG from './CONFIG'; +import CONST from './CONST'; +import ONYXKEYS from './ONYXKEYS'; /** * This is a file containing constants for all of the routes we want to be able to go to @@ -14,6 +20,14 @@ const IOU_REQUEST_CURRENCY = `${IOU_REQUEST}/currency`; const IOU_BILL_CURRENCY = `${IOU_BILL}/currency`; const IOU_SEND_CURRENCY = `${IOU_SEND}/currency`; +let currentUserAccountID; +Onyx.connect({ + key: ONYXKEYS.SESSION, + callback: (val) => { + currentUserAccountID = lodashGet(val, 'accountID', ''); + }, +}); + export default { BANK_ACCOUNT: 'bank-account/:stepToOpen?', BANK_ACCOUNT_PERSONAL: 'bank-account/personal', @@ -81,6 +95,19 @@ export default { WORKSPACE_INVITE: 'workspace/:policyID/invite', REQUEST_CALL: 'request-call', + /** + * This links to a page in e.com ensuring the user is logged in. + * It does so by getting a validate code and redirecting to the validate URL with exitTo set to the URL + * we want to visit + * @param {string} url relative URL to open in expensify.com + */ + openSignedInLink: (url) => { + GetAccountValidateCode().then((response) => { + Linking.openURL(CONFIG.EXPENSIFY.URL_EXPENSIFY_COM + + CONST.VALIDATE_CODE_URL(currentUserAccountID, response.validateCode, url)); + }); + }, + /** * @param {String} route * @returns {Object} diff --git a/src/libs/API.js b/src/libs/API.js index c885298411b0e..15f51e9fbc1c3 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -420,6 +420,15 @@ function GetAccountStatus(parameters) { return Network.post(commandName, parameters); } +/** + * Returns a validate code for this account + * @returns {Promise} + */ +function GetAccountValidateCode() { + const commandName = 'GetAccountValidateCode'; + return Network.post(commandName); +} + /** * @param {Object} parameters * @param {String} parameters.debtorEmail @@ -1067,6 +1076,7 @@ export { DeleteLogin, Get, GetAccountStatus, + GetAccountValidateCode, GetIOUReport, GetPolicyList, GetPolicySummaryList, diff --git a/src/pages/workspace/WorkspaceCardPage.js b/src/pages/workspace/WorkspaceCardPage.js index 98f18de118736..be840dd4780c9 100644 --- a/src/pages/workspace/WorkspaceCardPage.js +++ b/src/pages/workspace/WorkspaceCardPage.js @@ -1,6 +1,6 @@ import React from 'react'; import { - View, ScrollView, Linking, StyleSheet, + View, ScrollView, StyleSheet, } from 'react-native'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; @@ -18,7 +18,6 @@ import Button from '../../components/Button'; import variables from '../../styles/variables'; import themeDefault from '../../styles/themes/default'; import ROUTES from '../../ROUTES'; -import CONFIG from '../../CONFIG'; import CONST from '../../CONST'; import HeroCardWebImage from '../../../assets/images/cascading-cards-web.svg'; import HeroCardMobileImage from '../../../assets/images/cascading-cards-mobile.svg'; @@ -61,9 +60,6 @@ const defaultProps = { }, }; -const publicLink = CONFIG.EXPENSIFY.URL_EXPENSIFY_COM + CONST.ADD_SECONDARY_LOGIN_URL; -const manageCardLink = CONFIG.EXPENSIFY.URL_EXPENSIFY_COM + CONST.MANAGE_CARDS_URL; - const WorkspaceCardPage = ({ user, translate, @@ -84,9 +80,9 @@ const WorkspaceCardPage = ({ const onPress = () => { if (user.isFromPublicDomain) { - Linking.openURL(publicLink); + ROUTES.openSignedInLink(CONST.ADD_SECONDARY_LOGIN_URL); } else if (user.isUsingExpensifyCard) { - Linking.openURL(manageCardLink); + ROUTES.openSignedInLink(CONST.MANAGE_CARDS_URL); } else { Navigation.navigate(ROUTES.getBankAccountRoute()); } From fe491f615c422ee7069305c99edafb97a9aba521 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Tue, 27 Jul 2021 18:39:40 +0200 Subject: [PATCH 2/7] Clarify param and move method to ROUTES --- src/CONST.js | 4 ---- src/ROUTES.js | 9 ++++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 46b4fb47a52eb..d1defb411e375 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -125,10 +125,6 @@ const CONST = { LICENSES_URL: 'https://use.expensify.com/licenses', PLAY_STORE_URL: 'https://play.google.com/store/apps/details?id=com.expensify.chat&hl=en', ADD_SECONDARY_LOGIN_URL: '/settings?param={%22section%22:%22account%22}', - VALIDATE_CODE_URL: (accountID, validateCode, exitTo = '') => { - const exitToURL = exitTo ? `?exitTo=${exitTo}` : ''; - return `v/${accountID}/${validateCode}${exitToURL}`; - }, MANAGE_CARDS_URL: '/domain_companycards', OPTION_TYPE: { REPORT: 'report', diff --git a/src/ROUTES.js b/src/ROUTES.js index 9155a2c492971..5dcca0aec8d8a 100644 --- a/src/ROUTES.js +++ b/src/ROUTES.js @@ -4,7 +4,6 @@ import Onyx from 'react-native-onyx'; import {addTrailingForwardSlash} from './libs/Url'; import {GetAccountValidateCode} from './libs/API'; import CONFIG from './CONFIG'; -import CONST from './CONST'; import ONYXKEYS from './ONYXKEYS'; /** @@ -94,17 +93,21 @@ export default { getWorkspaceInviteRoute: policyID => `workspace/${policyID}/invite`, WORKSPACE_INVITE: 'workspace/:policyID/invite', REQUEST_CALL: 'request-call', + VALIDATE_CODE_URL: (accountID, validateCode, exitTo = '') => { + const exitToURL = exitTo ? `?exitTo=${exitTo}` : ''; + return `v/${accountID}/${validateCode}${exitToURL}`; + }, /** * This links to a page in e.com ensuring the user is logged in. * It does so by getting a validate code and redirecting to the validate URL with exitTo set to the URL * we want to visit - * @param {string} url relative URL to open in expensify.com + * @param {string} url relative URL starting with `/` to open in expensify.com */ openSignedInLink: (url) => { GetAccountValidateCode().then((response) => { Linking.openURL(CONFIG.EXPENSIFY.URL_EXPENSIFY_COM - + CONST.VALIDATE_CODE_URL(currentUserAccountID, response.validateCode, url)); + + this.VALIDATE_CODE_URL(currentUserAccountID, response.validateCode, url)); }); }, From 4766bf71f9dff3ed80405df42f0c4f76e834e69c Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Tue, 27 Jul 2021 19:20:40 +0200 Subject: [PATCH 3/7] Move method to App --- src/ROUTES.js | 21 -------------------- src/libs/actions/App.js | 25 ++++++++++++++++++++++++ src/pages/workspace/WorkspaceCardPage.js | 5 +++-- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/ROUTES.js b/src/ROUTES.js index 5dcca0aec8d8a..e0135e822647b 100644 --- a/src/ROUTES.js +++ b/src/ROUTES.js @@ -19,14 +19,6 @@ const IOU_REQUEST_CURRENCY = `${IOU_REQUEST}/currency`; const IOU_BILL_CURRENCY = `${IOU_BILL}/currency`; const IOU_SEND_CURRENCY = `${IOU_SEND}/currency`; -let currentUserAccountID; -Onyx.connect({ - key: ONYXKEYS.SESSION, - callback: (val) => { - currentUserAccountID = lodashGet(val, 'accountID', ''); - }, -}); - export default { BANK_ACCOUNT: 'bank-account/:stepToOpen?', BANK_ACCOUNT_PERSONAL: 'bank-account/personal', @@ -98,19 +90,6 @@ export default { return `v/${accountID}/${validateCode}${exitToURL}`; }, - /** - * This links to a page in e.com ensuring the user is logged in. - * It does so by getting a validate code and redirecting to the validate URL with exitTo set to the URL - * we want to visit - * @param {string} url relative URL starting with `/` to open in expensify.com - */ - openSignedInLink: (url) => { - GetAccountValidateCode().then((response) => { - Linking.openURL(CONFIG.EXPENSIFY.URL_EXPENSIFY_COM - + this.VALIDATE_CODE_URL(currentUserAccountID, response.validateCode, url)); - }); - }, - /** * @param {String} route * @returns {Object} diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 9635948348cd7..9528ee3d9f659 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -1,6 +1,17 @@ import Onyx from 'react-native-onyx'; +import {Linking} from 'react-native'; +import lodashGet from 'lodash/get'; import ONYXKEYS from '../../ONYXKEYS'; import * as API from '../API'; +import CONFIG from '../../CONFIG'; + +let currentUserAccountID; +Onyx.connect({ + key: ONYXKEYS.SESSION, + callback: (val) => { + currentUserAccountID = lodashGet(val, 'accountID', ''); + }, +}); /** * @param {String} url @@ -17,7 +28,21 @@ function setLocale(locale) { Onyx.merge(ONYXKEYS.NVP_PREFERRED_LOCALE, locale); } +/** + * This links to a page in e.com ensuring the user is logged in. + * It does so by getting a validate code and redirecting to the validate URL with exitTo set to the URL + * we want to visit + * @param {string} url relative URL starting with `/` to open in expensify.com + */ +function openSignedInLink(url) { + API.GetAccountValidateCode().then((response) => { + Linking.openURL(CONFIG.EXPENSIFY.URL_EXPENSIFY_COM + + this.VALIDATE_CODE_URL(currentUserAccountID, response.validateCode, url)); + }); +} + export { setCurrentURL, setLocale, + openSignedInLink, }; diff --git a/src/pages/workspace/WorkspaceCardPage.js b/src/pages/workspace/WorkspaceCardPage.js index be840dd4780c9..96b26b761f3a6 100644 --- a/src/pages/workspace/WorkspaceCardPage.js +++ b/src/pages/workspace/WorkspaceCardPage.js @@ -21,6 +21,7 @@ import ROUTES from '../../ROUTES'; import CONST from '../../CONST'; import HeroCardWebImage from '../../../assets/images/cascading-cards-web.svg'; import HeroCardMobileImage from '../../../assets/images/cascading-cards-mobile.svg'; +import {openSignedInLink} from '../../libs/actions/App'; const propTypes = { /* Onyx Props */ @@ -80,9 +81,9 @@ const WorkspaceCardPage = ({ const onPress = () => { if (user.isFromPublicDomain) { - ROUTES.openSignedInLink(CONST.ADD_SECONDARY_LOGIN_URL); + openSignedInLink(CONST.ADD_SECONDARY_LOGIN_URL); } else if (user.isUsingExpensifyCard) { - ROUTES.openSignedInLink(CONST.MANAGE_CARDS_URL); + openSignedInLink(CONST.MANAGE_CARDS_URL); } else { Navigation.navigate(ROUTES.getBankAccountRoute()); } From 71f676c48a75435d7ddfd4778c145c214c77ce3c Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Tue, 27 Jul 2021 19:27:37 +0200 Subject: [PATCH 4/7] Lint --- src/ROUTES.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ROUTES.js b/src/ROUTES.js index e0135e822647b..ab583dd6935f4 100644 --- a/src/ROUTES.js +++ b/src/ROUTES.js @@ -1,10 +1,5 @@ import lodashGet from 'lodash/get'; -import {Linking} from 'react-native'; -import Onyx from 'react-native-onyx'; import {addTrailingForwardSlash} from './libs/Url'; -import {GetAccountValidateCode} from './libs/API'; -import CONFIG from './CONFIG'; -import ONYXKEYS from './ONYXKEYS'; /** * This is a file containing constants for all of the routes we want to be able to go to From 274b0f390d09127ea8177f1b76527e74f67412f1 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Wed, 28 Jul 2021 14:29:36 +0200 Subject: [PATCH 5/7] Fix code --- src/libs/actions/App.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 9528ee3d9f659..bebf6d7575cac 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -4,6 +4,7 @@ import lodashGet from 'lodash/get'; import ONYXKEYS from '../../ONYXKEYS'; import * as API from '../API'; import CONFIG from '../../CONFIG'; +import ROUTES from '../../ROUTES'; let currentUserAccountID; Onyx.connect({ @@ -37,7 +38,7 @@ function setLocale(locale) { function openSignedInLink(url) { API.GetAccountValidateCode().then((response) => { Linking.openURL(CONFIG.EXPENSIFY.URL_EXPENSIFY_COM - + this.VALIDATE_CODE_URL(currentUserAccountID, response.validateCode, url)); + + ROUTES.VALIDATE_CODE_URL(currentUserAccountID, response.validateCode, url)); }); } From fa178411bd8f39d8069bef2a5b2e25a01896e81e Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Thu, 29 Jul 2021 06:05:58 -0600 Subject: [PATCH 6/7] Fix bad conflict resolution --- src/libs/actions/App.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 687c177e365d7..cad9bcce3e236 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -14,6 +14,8 @@ Onyx.connect({ callback: (val) => { currentUserAccountID = lodashGet(val, 'accountID', ''); }, +}); + let isSidebarLoaded; Onyx.connect({ key: ONYXKEYS.IS_SIDEBAR_LOADED, From 62a9835c6421aec20a76fd0aa41663f5358d8432 Mon Sep 17 00:00:00 2001 From: OSBotify Date: Fri, 30 Jul 2021 20:15:06 +0000 Subject: [PATCH 7/7] Update version to 1.0.81-6 --- android/app/build.gradle | 4 ++-- ios/ExpensifyCash/Info.plist | 2 +- ios/ExpensifyCashTests/Info.plist | 2 +- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index b44828db2e7d1..74396642fdec1 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -150,8 +150,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled rootProject.ext.multiDexEnabled - versionCode 1001008105 - versionName "1.0.81-5" + versionCode 1001008106 + versionName "1.0.81-6" } splits { abi { diff --git a/ios/ExpensifyCash/Info.plist b/ios/ExpensifyCash/Info.plist index 2c30175257a7d..da951d33c0b8b 100644 --- a/ios/ExpensifyCash/Info.plist +++ b/ios/ExpensifyCash/Info.plist @@ -30,7 +30,7 @@ CFBundleVersion - 1.0.81.5 + 1.0.81.6 ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes diff --git a/ios/ExpensifyCashTests/Info.plist b/ios/ExpensifyCashTests/Info.plist index cba2c4e516da9..326c3d0e2fe0a 100644 --- a/ios/ExpensifyCashTests/Info.plist +++ b/ios/ExpensifyCashTests/Info.plist @@ -19,6 +19,6 @@ CFBundleSignature ???? CFBundleVersion - 1.0.81.5 + 1.0.81.6 diff --git a/package-lock.json b/package-lock.json index 6ea8dfcbe9fbc..70e58fc525ff7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "expensify.cash", - "version": "1.0.81-5", + "version": "1.0.81-6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 73d60c3113de5..dace87611ca36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "expensify.cash", - "version": "1.0.81-5", + "version": "1.0.81-6", "author": "Expensify, Inc.", "homepage": "https://new.expensify.com", "description": "Expensify.cash is the next generation of Expensify: a reimagination of payments based atop a foundation of chat.",