From 6b71211f6aa6fea96092f769e9fafa554cae16b7 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Tue, 28 Jun 2022 15:04:16 +0400 Subject: [PATCH 01/45] Use new API command: TransferBalance --- src/libs/actions/PaymentMethods.js | 29 +++++++++++++++++-- .../settings/Payments/TransferBalancePage.js | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/PaymentMethods.js b/src/libs/actions/PaymentMethods.js index 987095e63a72..7d951c4dc793 100644 --- a/src/libs/actions/PaymentMethods.js +++ b/src/libs/actions/PaymentMethods.js @@ -4,6 +4,7 @@ import lodashGet from 'lodash/get'; import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../ONYXKEYS'; import * as DeprecatedAPI from '../deprecatedAPI'; +import * as API from '../API'; import CONST from '../../CONST'; import Growl from '../Growl'; import * as Localize from '../Localize'; @@ -213,7 +214,7 @@ function clearDebitCardFormErrorAndSubmit() { * @param {*} paymentMethod.methodID * @param {String} paymentMethod.accountType */ -function transferWalletBalance(paymentMethod) { +function transferBalance(transferAmount, paymentMethod) { const paymentMethodIDKey = paymentMethod.accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT ? CONST.PAYMENT_METHOD_ID_KEYS.BANK_ACCOUNT : CONST.PAYMENT_METHOD_ID_KEYS.DEBIT_CARD; @@ -234,6 +235,30 @@ function transferWalletBalance(paymentMethod) { Growl.error(Localize.translateLocal('transferAmountPage.failedTransfer')); Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {loading: false}); }); + + API.write('TransferBalance', parameters, { + optimisticData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.WALLET_TRANSFER, + value: {transferAmount, loading: true, error: null}, + }, + ], + successData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.WALLET_TRANSFER, + value: {loading: false}, + }, + ], + failureData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.WALLET_TRANSFER, + value: {loading: false}, + }, + ], + }); } function resetWalletTransferData() { @@ -282,7 +307,7 @@ export { kycWallRef, continueSetup, clearDebitCardFormErrorAndSubmit, - transferWalletBalance, + transferBalance, resetWalletTransferData, saveWalletTransferAmount, saveWalletTransferAccountTypeAndID, diff --git a/src/pages/settings/Payments/TransferBalancePage.js b/src/pages/settings/Payments/TransferBalancePage.js index 08ad9da9356e..bd434235d306 100644 --- a/src/pages/settings/Payments/TransferBalancePage.js +++ b/src/pages/settings/Payments/TransferBalancePage.js @@ -138,7 +138,7 @@ class TransferBalancePage extends React.Component { */ saveTransferAmountAndStartTransfer(transferAmount, selectedAccount) { PaymentMethods.saveWalletTransferAmount(transferAmount); - PaymentMethods.transferWalletBalance(selectedAccount); + PaymentMethods.transferBalance(transferAmount, selectedAccount); } /** From 2f7b9cc4f24605e94a0752694b5c849325b609a6 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Tue, 28 Jun 2022 15:04:57 +0400 Subject: [PATCH 02/45] Remove unnecessary saveWalletTransferAmount method --- src/libs/actions/PaymentMethods.js | 8 -------- src/pages/settings/Payments/TransferBalancePage.js | 1 - 2 files changed, 9 deletions(-) diff --git a/src/libs/actions/PaymentMethods.js b/src/libs/actions/PaymentMethods.js index 7d951c4dc793..6af5bafe9b72 100644 --- a/src/libs/actions/PaymentMethods.js +++ b/src/libs/actions/PaymentMethods.js @@ -271,13 +271,6 @@ function resetWalletTransferData() { }); } -/** - * @param {Number} transferAmount - */ -function saveWalletTransferAmount(transferAmount) { - Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {transferAmount}); -} - /** * @param {String} selectedAccountType * @param {String} selectedAccountID @@ -309,7 +302,6 @@ export { clearDebitCardFormErrorAndSubmit, transferBalance, resetWalletTransferData, - saveWalletTransferAmount, saveWalletTransferAccountTypeAndID, saveWalletTransferMethodType, dismissWalletConfirmModal, diff --git a/src/pages/settings/Payments/TransferBalancePage.js b/src/pages/settings/Payments/TransferBalancePage.js index bd434235d306..14d1aa06e21c 100644 --- a/src/pages/settings/Payments/TransferBalancePage.js +++ b/src/pages/settings/Payments/TransferBalancePage.js @@ -137,7 +137,6 @@ class TransferBalancePage extends React.Component { * @param {Object} selectedAccount */ saveTransferAmountAndStartTransfer(transferAmount, selectedAccount) { - PaymentMethods.saveWalletTransferAmount(transferAmount); PaymentMethods.transferBalance(transferAmount, selectedAccount); } From aec686556fcc08ff09e09c0928bf76e33d87f2f2 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Tue, 28 Jun 2022 15:19:35 +0400 Subject: [PATCH 03/45] Remove usage of deprecated API command --- src/libs/actions/PaymentMethods.js | 60 ++++++++++++------------------ 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/src/libs/actions/PaymentMethods.js b/src/libs/actions/PaymentMethods.js index 6af5bafe9b72..110915b36f48 100644 --- a/src/libs/actions/PaymentMethods.js +++ b/src/libs/actions/PaymentMethods.js @@ -221,44 +221,30 @@ function transferBalance(transferAmount, paymentMethod) { const parameters = { [paymentMethodIDKey]: paymentMethod.methodID, }; - Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {loading: true}); - DeprecatedAPI.TransferWalletBalance(parameters) - .then((response) => { - if (response.jsonCode !== 200) { - throw new Error(response.message); - } - Onyx.merge(ONYXKEYS.USER_WALLET, {currentBalance: 0}); - Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {shouldShowConfirmModal: true, loading: false}); - Navigation.navigate(ROUTES.SETTINGS_PAYMENTS); - }).catch(() => { - Growl.error(Localize.translateLocal('transferAmountPage.failedTransfer')); - Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {loading: false}); - }); - - API.write('TransferBalance', parameters, { - optimisticData: [ - { - onyxMethod: 'merge', - key: ONYXKEYS.WALLET_TRANSFER, - value: {transferAmount, loading: true, error: null}, - }, - ], - successData: [ - { - onyxMethod: 'merge', - key: ONYXKEYS.WALLET_TRANSFER, - value: {loading: false}, - }, - ], - failureData: [ - { - onyxMethod: 'merge', - key: ONYXKEYS.WALLET_TRANSFER, - value: {loading: false}, - }, - ], - }); + API.write('TransferBalance', parameters, { + optimisticData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.WALLET_TRANSFER, + value: {transferAmount, loading: true, error: null}, + }, + ], + successData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.WALLET_TRANSFER, + value: {loading: false}, + }, + ], + failureData: [ + { + onyxMethod: 'merge', + key: ONYXKEYS.WALLET_TRANSFER, + value: {loading: false}, + }, + ], + }); } function resetWalletTransferData() { From a4f35dd92c8e62b82f709f4ffad18d0f4a6a8e5f Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Tue, 28 Jun 2022 15:29:14 +0400 Subject: [PATCH 04/45] Fix JSDoc and remove unused import --- src/libs/actions/PaymentMethods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/PaymentMethods.js b/src/libs/actions/PaymentMethods.js index 110915b36f48..4bb4a45cf4be 100644 --- a/src/libs/actions/PaymentMethods.js +++ b/src/libs/actions/PaymentMethods.js @@ -10,7 +10,6 @@ import Growl from '../Growl'; import * as Localize from '../Localize'; import Navigation from '../Navigation/Navigation'; import * as CardUtils from '../CardUtils'; -import ROUTES from '../../ROUTES'; import NameValuePair from './NameValuePair'; import * as store from './ReimbursementAccount/store'; @@ -210,6 +209,7 @@ function clearDebitCardFormErrorAndSubmit() { /** * Call the API to transfer wallet balance. + * @param {Number} transferAmount * @param {Object} paymentMethod * @param {*} paymentMethod.methodID * @param {String} paymentMethod.accountType From 6f4c9bb2f0fd1ed8d711304a54fd771eb1e61569 Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Thu, 30 Jun 2022 10:49:03 +0400 Subject: [PATCH 05/45] Add successful balance transfer page --- .../Payments/SuccessfulBalanceTransferPage.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/pages/settings/Payments/SuccessfulBalanceTransferPage.js diff --git a/src/pages/settings/Payments/SuccessfulBalanceTransferPage.js b/src/pages/settings/Payments/SuccessfulBalanceTransferPage.js new file mode 100644 index 000000000000..59fd8f0fd6ef --- /dev/null +++ b/src/pages/settings/Payments/SuccessfulBalanceTransferPage.js @@ -0,0 +1,40 @@ +import React from 'react'; +import { + View, +} from 'react-native'; +import CONST from '../../CONST'; +import Text from '../../components/Text'; +import TextLink from '../../components/TextLink'; +import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; +import styles from '../../styles/styles'; + +const propTypes = { + ...withLocalizePropTypes, +}; + +const SuccessfulBalanceTransferPage = props => ( + + + + Your wallet balance has been successfully transferred! Please reach out to + + {CONST.EMAIL.CONCIERGE} + + if you have any questions. + +