Skip to content

Commit

Permalink
Add Get bankAccountList to verify secure endpoints will work
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaaron committed Apr 26, 2021
1 parent ed3c40c commit 6f6ddea
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
EXPENSIFY_URL_CASH=https://expensify.cash/
EXPENSIFY_URL_SECURE=https://secure.expensify.com.dev/
EXPENSIFY_URL_COM=https://www.expensify.com.dev/
EXPENSIFY_PARTNER_NAME=chat-expensify-com
EXPENSIFY_PARTNER_PASSWORD=e21965746fd75f82bb66
Expand Down
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
EXPENSIFY_URL_CASH=https://expensify.cash/
EXPENSIFY_URL_SECURE=https://secure.expensify.com/
EXPENSIFY_URL_COM=https://www.expensify.com/
EXPENSIFY_PARTNER_NAME=chat-expensify-com
EXPENSIFY_PARTNER_PASSWORD=e21965746fd75f82bb66
Expand Down
1 change: 1 addition & 0 deletions .env.staging
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
EXPENSIFY_URL_CASH=https://staging.expensify.cash/
EXPENSIFY_URL_SECURE=https://staging-secure.expensify.com/
EXPENSIFY_URL_COM=https://www.expensify.com/
EXPENSIFY_PARTNER_NAME=chat-expensify-com
EXPENSIFY_PARTNER_PASSWORD=e21965746fd75f82bb66
Expand Down
7 changes: 6 additions & 1 deletion src/CONFIG.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const ngrokURL = addTrailingForwardSlash(lodashGet(Config, 'NGROK_URL', ''));
const useNgrok = lodashGet(Config, 'USE_NGROK', 'false') === 'true';
const useWebProxy = lodashGet(Config, 'USE_WEB_PROXY', 'true') === 'true';
const expensifyComWithProxy = getPlatform() === 'web' && useWebProxy ? '/' : expensifyURL;
const secureURLRoot = addTrailingForwardSlash(lodashGet(
Config, 'EXPENSIFY_URL_SECURE', 'https://secure.expensify.com/',
));

// Ngrok helps us avoid many of our cross-domain issues with connecting to our API
// and is required for viewing images on mobile and for developing on android
Expand All @@ -21,8 +24,10 @@ export default {
APP_NAME: 'ExpensifyCash',
AUTH_TOKEN_EXPIRATION_TIME: 1000 * 60 * 90,
EXPENSIFY: {
// Note: This will be EXACTLY what is set for EXPENSIFY_URL_COM whether the proxy is enabled or not.
// Note: This will be EXACTLY what is set for EXPENSIFY_URL_COM and EXPENSIFY_URL_SECURE whether the proxy is
// enabled or not.
URL_EXPENSIFY_COM: expensifyURL,
URL_EXPENSIFY_SECURE: secureURLRoot,
URL_EXPENSIFY_CASH: expensifyCashURL,
URL_API_ROOT: expensifyURLRoot,
PARTNER_NAME: lodashGet(Config, 'EXPENSIFY_PARTNER_NAME', 'chat-expensify-com'),
Expand Down
5 changes: 3 additions & 2 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,13 @@ function DeleteLogin(parameters) {
/**
* @param {Object} parameters
* @param {String} parameters.returnValueList
* @param {Boolean} shouldUseSecure
* @returns {Promise}
*/
function Get(parameters) {
function Get(parameters, shouldUseSecure = false) {
const commandName = 'Get';
requireParameters(['returnValueList'], parameters, commandName);
return Network.post(commandName, parameters);
return Network.post(commandName, parameters, 'post', shouldUseSecure);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/libs/HttpUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ function processHTTPRequest(url, method = 'get', body = null) {
* @param {String} command the name of the API command
* @param {Object} data parameters for the API command
* @param {String} type HTTP request type (get/post)
* @param {Boolean} shouldUseSecure should we use the secure server
* @returns {Promise}
*/
function xhr(command, data, type = 'post') {
function xhr(command, data, type = 'post', shouldUseSecure = false) {
const formData = new FormData();
_.each(data, (val, key) => formData.append(key, val));
return processHTTPRequest(`${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=${command}`, type, formData);
const apiRoot = shouldUseSecure ? CONFIG.URL_EXPENSIFY_SECURE : CONFIG.EXPENSIFY.URL_API_ROOT;
return processHTTPRequest(`${apiRoot}api?command=${command}`, type, formData);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
fetchAllReports,
} from '../../actions/Report';
import * as PersonalDetails from '../../actions/PersonalDetails';
import * as BankAccounts from '../../actions/BankAccounts';
import * as Pusher from '../../Pusher/pusher';
import PusherConnectionManager from '../../PusherConnectionManager';
import UnreadIndicatorUpdater from '../../UnreadIndicatorUpdater';
Expand Down Expand Up @@ -121,6 +122,7 @@ class AuthScreens extends React.Component {
User.getBetas();
fetchAllReports(true, true, true);
fetchCountryCodeByRequestIP();
BankAccounts.fetchBankAccountList();
UnreadIndicatorUpdater.listenForReportChanges();

// Refresh the personal details, timezone and betas every 30 minutes
Expand Down
6 changes: 4 additions & 2 deletions src/libs/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function processNetworkRequestQueue() {
return;
}

HttpUtils.xhr(queuedRequest.command, finalParameters, queuedRequest.type)
HttpUtils.xhr(queuedRequest.command, finalParameters, queuedRequest.type, queuedRequest.shouldUseSecure)
.then(response => onResponse(queuedRequest, response))
.catch(error => onError(queuedRequest, error));
});
Expand All @@ -174,9 +174,10 @@ setInterval(processNetworkRequestQueue, 1000);
* @param {String} command
* @param {*} [data]
* @param {String} [type]
* @param {Boolean} shouldUseSecure - Whether we should use the secure API
* @returns {Promise}
*/
function post(command, data = {}, type = 'post') {
function post(command, data = {}, type = 'post', shouldUseSecure = false) {
return new Promise((resolve, reject) => {
// Add the write request to a queue of actions to perform
networkRequestQueue.push({
Expand All @@ -185,6 +186,7 @@ function post(command, data = {}, type = 'post') {
type,
resolve,
reject,
shouldUseSecure,
});

// Try to fire off the request as soon as it's queued so we don't add a delay to every queued command
Expand Down
11 changes: 11 additions & 0 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as API from '../API';

function fetchBankAccountList() {
// Note: For the moment, we are just running this to verify that we can successfully return data from the secure API
API.Get({returnValueList: 'bankAccountList'}, true);
}

export {
// eslint-disable-next-line import/prefer-default-export
fetchBankAccountList,
};

0 comments on commit 6f6ddea

Please sign in to comment.