Skip to content

Commit

Permalink
Merge pull request #27696 from ginsuma/fix/23888
Browse files Browse the repository at this point in the history
(cherry picked from commit 762b0de)
  • Loading branch information
thienlnam authored and OSBotify committed Sep 20, 2023
1 parent ba3dd6a commit 60ea792
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
22 changes: 2 additions & 20 deletions src/components/AddPlaidBankAccount.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'underscore';
import React, {useEffect, useRef, useCallback, useMemo} from 'react';
import React, {useEffect, useRef, useCallback} from 'react';
import {ActivityIndicator, View} from 'react-native';
import {useIsFocused} from '@react-navigation/native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
Expand Down Expand Up @@ -39,9 +38,6 @@ const propTypes = {
/** Fired when the user exits the Plaid flow */
onExitPlaid: PropTypes.func,

/** Fired when the screen is blurred */
onBlurPlaid: PropTypes.func,

/** Fired when the user selects an account */
onSelect: PropTypes.func,

Expand All @@ -65,7 +61,6 @@ const defaultProps = {
selectedPlaidAccountID: '',
plaidLinkToken: '',
onExitPlaid: () => {},
onBlurPlaid: () => {},
onSelect: () => {},
text: '',
receivedRedirectURI: null,
Expand All @@ -80,7 +75,6 @@ function AddPlaidBankAccount({
selectedPlaidAccountID,
plaidLinkToken,
onExitPlaid,
onBlurPlaid,
onSelect,
text,
receivedRedirectURI,
Expand All @@ -94,7 +88,6 @@ function AddPlaidBankAccount({

const {translate} = useLocalize();
const {isOffline} = useNetwork();
const isFocused = useIsFocused();

/**
* @returns {String}
Expand All @@ -109,11 +102,6 @@ function AddPlaidBankAccount({
}
};

/**
* @returns {Array}
*/
const plaidBankAccounts = useMemo(() => lodashGet(plaidData, 'bankAccounts') || [], [plaidData]);

/**
* @returns {Boolean}
* I'm using useCallback so the useEffect which uses this function doesn't run on every render.
Expand Down Expand Up @@ -163,13 +151,6 @@ function AddPlaidBankAccount({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (isFocused || plaidBankAccounts.length) {
return;
}
onBlurPlaid();
}, [isFocused, onBlurPlaid, plaidBankAccounts.length]);

useEffect(() => {
// If we are coming back from offline and we haven't authenticated with Plaid yet, we need to re-run our call to kick off Plaid
// previousNetworkState.current also makes sure that this doesn't run on the first render.
Expand All @@ -179,6 +160,7 @@ function AddPlaidBankAccount({
previousNetworkState.current = isOffline;
}, [allowDebit, bankAccountID, isAuthenticatedWithPlaid, isOffline]);

const plaidBankAccounts = lodashGet(plaidData, 'bankAccounts') || [];
const token = getPlaidLinkToken();
const options = _.map(plaidBankAccounts, (account) => ({
value: account.plaidAccountID,
Expand Down
13 changes: 11 additions & 2 deletions src/pages/ReimbursementAccount/BankAccountPlaidStep.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useCallback} from 'react';
import React, {useCallback, useEffect} from 'react';
import {useIsFocused} from '@react-navigation/native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import lodashGet from 'lodash/get';
Expand Down Expand Up @@ -41,6 +42,7 @@ const defaultProps = {

function BankAccountPlaidStep(props) {
const {plaidData, receivedRedirectURI, plaidLinkOAuthToken, reimbursementAccount, reimbursementAccountDraft, onBackButtonPress, getDefaultStateForField, translate} = props;
const isFocused = useIsFocused();

const validate = useCallback((values) => {
const errorFields = {};
Expand All @@ -51,6 +53,14 @@ function BankAccountPlaidStep(props) {
return errorFields;
}, []);

useEffect(() => {
const plaidBankAccounts = lodashGet(plaidData, 'bankAccounts') || [];
if (isFocused || plaidBankAccounts.length) {
return;
}
BankAccounts.setBankAccountSubStep(null);
}, [isFocused, plaidData]);

const submit = useCallback(() => {
const selectedPlaidBankAccount = _.findWhere(lodashGet(plaidData, 'bankAccounts', []), {
plaidAccountID: lodashGet(reimbursementAccountDraft, 'plaidAccountID', ''),
Expand Down Expand Up @@ -103,7 +113,6 @@ function BankAccountPlaidStep(props) {
}}
plaidData={plaidData}
onExitPlaid={() => BankAccounts.setBankAccountSubStep(null)}
onBlurPlaid={() => BankAccounts.setBankAccountSubStep(null)}
receivedRedirectURI={receivedRedirectURI}
plaidLinkOAuthToken={plaidLinkOAuthToken}
allowDebit
Expand Down

0 comments on commit 60ea792

Please sign in to comment.