From 61fcff1333d8c04d69f1ebb4f8bcb4af469fede3 Mon Sep 17 00:00:00 2001 From: madmax330 Date: Mon, 30 May 2022 16:18:09 +0400 Subject: [PATCH 01/10] Refactor ChangePassword --- src/libs/actions/User.js | 4 ++-- src/pages/settings/PasswordPage.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 5727c0b880a1..eaedc9390a02 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -46,7 +46,7 @@ Onyx.connect({ * @param {String} password * @returns {Promise} */ -function changePasswordAndNavigate(oldPassword, password) { +function changePassword(oldPassword, password) { Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, loading: true}); return DeprecatedAPI.ChangePassword({oldPassword, password}) @@ -429,7 +429,7 @@ function generateStatementPDF(period) { } export { - changePasswordAndNavigate, + changePassword, closeAccount, getBetas, getUserDetails, diff --git a/src/pages/settings/PasswordPage.js b/src/pages/settings/PasswordPage.js index 8e68e734ec29..19d126aec076 100755 --- a/src/pages/settings/PasswordPage.js +++ b/src/pages/settings/PasswordPage.js @@ -133,7 +133,7 @@ class PasswordPage extends Component { if (!this.validate()) { return; } - User.changePasswordAndNavigate(this.state.currentPassword, this.state.newPassword); + User.changePassword(this.state.currentPassword, this.state.newPassword); } render() { From 8a55952a9c41ef7ad8bcd117669bba8e60909400 Mon Sep 17 00:00:00 2001 From: madmax330 Date: Fri, 3 Jun 2022 08:40:51 +0400 Subject: [PATCH 02/10] use new api --- src/libs/actions/User.js | 42 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index eaedc9390a02..d1a32415dbc5 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -47,22 +47,32 @@ Onyx.connect({ * @returns {Promise} */ function changePassword(oldPassword, password) { - Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, loading: true}); - - return DeprecatedAPI.ChangePassword({oldPassword, password}) - .then((response) => { - if (response.jsonCode !== 200) { - const error = lodashGet(response, 'message', 'Unable to change password. Please try again.'); - Onyx.merge(ONYXKEYS.ACCOUNT, {error}); - return; - } - - const success = lodashGet(response, 'message', 'Password changed successfully.'); - Onyx.merge(ONYXKEYS.ACCOUNT, {success}); - }) - .finally(() => { - Onyx.merge(ONYXKEYS.ACCOUNT, {loading: false}); - }); + const optimisticData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.ACCOUNT, + value: {...CONST.DEFAULT_ACCOUNT_DATA, isLoading: true}, + }, + ]; + const successData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.ACCOUNT, + value: {isLoading: false}, + }, + ]; + const failureData = [ + { + onyxMethod: 'merge', + key: ONYXKEYS.ACCOUNT, + value: {isLoading: false}, + }, + ]; + + API.write('ChangePassword', { + oldPassword, + password, + }, {optimisticData, successData, failureData}); } /** From da0f558cc3d19dd9d8cd481b5db7a901438b31d8 Mon Sep 17 00:00:00 2001 From: madmax330 Date: Fri, 3 Jun 2022 08:57:23 +0400 Subject: [PATCH 03/10] add import --- src/libs/actions/User.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index daa0be0b4359..bca61bf26c2d 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -6,6 +6,7 @@ import {PUBLIC_DOMAINS as COMMON_PUBLIC_DOMAINS} from 'expensify-common/lib/CONS import moment from 'moment'; import ONYXKEYS from '../../ONYXKEYS'; import * as DeprecatedAPI from '../deprecatedAPI'; +import * as API from '../API'; import CONFIG from '../../CONFIG'; import CONST from '../../CONST'; import Navigation from '../Navigation/Navigation'; From ba9c8de63a4b794e33fe055c66258d439d868ddd Mon Sep 17 00:00:00 2001 From: madmax330 Date: Fri, 3 Jun 2022 10:08:57 +0400 Subject: [PATCH 04/10] lint fix --- src/libs/actions/User.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index bca61bf26c2d..ab4f9c2501a3 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -47,7 +47,6 @@ Onyx.connect({ * * @param {String} oldPassword * @param {String} password - * @returns {Promise} */ function changePassword(oldPassword, password) { const optimisticData = [ From e7ca7afeab2ff823fb12934f30c520487c48f2e8 Mon Sep 17 00:00:00 2001 From: madmax330 Date: Fri, 3 Jun 2022 14:52:09 +0400 Subject: [PATCH 05/10] small updates --- src/libs/actions/User.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index ab4f9c2501a3..6fa64069702f 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -53,21 +53,21 @@ function changePassword(oldPassword, password) { { onyxMethod: 'merge', key: ONYXKEYS.ACCOUNT, - value: {...CONST.DEFAULT_ACCOUNT_DATA, isLoading: true}, + value: {...CONST.DEFAULT_ACCOUNT_DATA, loading: true}, }, ]; const successData = [ { onyxMethod: 'merge', key: ONYXKEYS.ACCOUNT, - value: {isLoading: false}, + value: {loading: false}, }, ]; const failureData = [ { onyxMethod: 'merge', key: ONYXKEYS.ACCOUNT, - value: {isLoading: false}, + value: {loading: false}, }, ]; From c734f5475ac4d06629e5bc72c63ed7d2b382492a Mon Sep 17 00:00:00 2001 From: madmax330 Date: Mon, 6 Jun 2022 11:44:30 +0400 Subject: [PATCH 06/10] pass values directly --- src/libs/actions/User.js | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 6fa64069702f..64ec221ff572 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -49,32 +49,32 @@ Onyx.connect({ * @param {String} password */ function changePassword(oldPassword, password) { - const optimisticData = [ - { - onyxMethod: 'merge', - key: ONYXKEYS.ACCOUNT, - value: {...CONST.DEFAULT_ACCOUNT_DATA, loading: true}, - }, - ]; - const successData = [ - { - onyxMethod: 'merge', - key: ONYXKEYS.ACCOUNT, - value: {loading: false}, - }, - ]; - const failureData = [ - { - onyxMethod: 'merge', - key: ONYXKEYS.ACCOUNT, - value: {loading: false}, - }, - ]; - API.write('ChangePassword', { oldPassword, password, - }, {optimisticData, successData, failureData}); + }, { + optimisticData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.ACCOUNT, + value: {...CONST.DEFAULT_ACCOUNT_DATA, loading: true}, + }, + ], + successData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.ACCOUNT, + value: {loading: false}, + }, + ], + failureData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.ACCOUNT, + value: {loading: false}, + }, + ], + }); } /** From 53431af69017f6bb779c202377cfaed3cada555c Mon Sep 17 00:00:00 2001 From: madmax330 Date: Wed, 8 Jun 2022 11:45:24 +0400 Subject: [PATCH 07/10] Use new command --- src/libs/actions/User.js | 6 +++--- src/pages/settings/PasswordPage.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 64ec221ff572..8a4074d6f01e 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -48,8 +48,8 @@ Onyx.connect({ * @param {String} oldPassword * @param {String} password */ -function changePassword(oldPassword, password) { - API.write('ChangePassword', { +function updatePassword(oldPassword, password) { + API.write('UpdatePassword', { oldPassword, password, }, { @@ -453,7 +453,7 @@ function generateStatementPDF(period) { } export { - changePassword, + updatePassword, closeAccount, getBetas, getUserDetails, diff --git a/src/pages/settings/PasswordPage.js b/src/pages/settings/PasswordPage.js index 19d126aec076..2e5aeb84189d 100755 --- a/src/pages/settings/PasswordPage.js +++ b/src/pages/settings/PasswordPage.js @@ -133,7 +133,7 @@ class PasswordPage extends Component { if (!this.validate()) { return; } - User.changePassword(this.state.currentPassword, this.state.newPassword); + User.updatePassword(this.state.currentPassword, this.state.newPassword); } render() { From 2019c4b6bfe1360f243a409e4994b7a56bb89017 Mon Sep 17 00:00:00 2001 From: madmax330 Date: Mon, 20 Jun 2022 09:22:03 +0400 Subject: [PATCH 08/10] Force shouldrety and cancel for deprecated api --- src/libs/Network/SequentialQueue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Network/SequentialQueue.js b/src/libs/Network/SequentialQueue.js index fc670d118405..a8288545eda7 100644 --- a/src/libs/Network/SequentialQueue.js +++ b/src/libs/Network/SequentialQueue.js @@ -32,7 +32,7 @@ function process() { } const task = _.reduce(persistedRequests, (previousRequest, request) => previousRequest.then(() => { - currentRequest = Request.processWithMiddleware(request, true); + currentRequest = Request.processWithMiddleware({...request, shouldRetry: true, canCancel: true}, true); return currentRequest; }), Promise.resolve()); From bf05d5d398ccdb20b2706678373e831a9fc4b6eb Mon Sep 17 00:00:00 2001 From: madmax330 Date: Mon, 20 Jun 2022 09:43:47 +0400 Subject: [PATCH 09/10] Fix infinite loop --- src/libs/API.js | 9 ++++++++- src/libs/Network/SequentialQueue.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libs/API.js b/src/libs/API.js index 7bda882e82bd..164bb6cb7a84 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -19,7 +19,14 @@ function write(command, apiCommandParameters = {}, onyxData = {}) { // Assemble all the request data we'll be storing in the queue const request = { command, - data, + data: { + ...data, + + // We add this here because this was passed in the old api requests and some middlewares still expect this. + // This should be removed once we are no longer using deprecatedAPI + shouldRetry: true, + canCancel: true, + }, ..._.omit(onyxData, 'optimisticData'), }; diff --git a/src/libs/Network/SequentialQueue.js b/src/libs/Network/SequentialQueue.js index a8288545eda7..fc670d118405 100644 --- a/src/libs/Network/SequentialQueue.js +++ b/src/libs/Network/SequentialQueue.js @@ -32,7 +32,7 @@ function process() { } const task = _.reduce(persistedRequests, (previousRequest, request) => previousRequest.then(() => { - currentRequest = Request.processWithMiddleware({...request, shouldRetry: true, canCancel: true}, true); + currentRequest = Request.processWithMiddleware(request, true); return currentRequest; }), Promise.resolve()); From d457cb199d4ea7c36fab6730f9c1ad7677027a42 Mon Sep 17 00:00:00 2001 From: madmax330 Date: Tue, 21 Jun 2022 09:26:16 +0400 Subject: [PATCH 10/10] Add issue + remove comment --- src/libs/API.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/API.js b/src/libs/API.js index 164bb6cb7a84..ae7336cc2032 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -22,8 +22,7 @@ function write(command, apiCommandParameters = {}, onyxData = {}) { data: { ...data, - // We add this here because this was passed in the old api requests and some middlewares still expect this. - // This should be removed once we are no longer using deprecatedAPI + // This should be removed once we are no longer using deprecatedAPI https://github.com/Expensify/Expensify/issues/215650 shouldRetry: true, canCancel: true, },