Skip to content

Commit

Permalink
Prevent Plaid triggered again on selector bank accounts page after ba…
Browse files Browse the repository at this point in the history
…ck from offline
  • Loading branch information
hoangzinh committed Apr 7, 2023
1 parent 64f4a78 commit 2630132
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/AddPlaidBankAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,19 @@ class AddPlaidBankAccount extends React.Component {

componentDidMount() {
// If we're coming from Plaid OAuth flow then we need to reuse the existing plaidLinkToken
if ((this.props.receivedRedirectURI && this.props.plaidLinkOAuthToken)
|| !_.isEmpty(lodashGet(this.props.plaidData, 'bankAccounts'))
|| !_.isEmpty(lodashGet(this.props.plaidData, 'errors'))) {
if ((this.props.receivedRedirectURI && this.props.plaidLinkOAuthToken) || this.hasPlaidBankAccountsData()) {
return;
}

BankAccounts.openPlaidBankLogin(this.props.allowDebit, this.props.bankAccountID);
}

componentDidUpdate(prevProps) {
if (!prevProps.network.isOffline || this.props.network.isOffline) {
if (!prevProps.network.isOffline || this.props.network.isOffline || this.hasPlaidBankAccountsData()) {
return;
}

// If we are coming back from offline, we need to re-run our call to kick off Plaid
// If we are coming back from offline and we haven't had bank accounts data yet, we need to re-run our call to kick off Plaid
BankAccounts.openPlaidBankLogin(this.props.allowDebit, this.props.bankAccountID);
}

Expand All @@ -109,6 +107,13 @@ class AddPlaidBankAccount extends React.Component {
}
}

/**
* @returns {Boolean}
*/
hasPlaidBankAccountsData() {
return !_.isEmpty(lodashGet(this.props.plaidData, 'bankAccounts')) || !_.isEmpty(lodashGet(this.props.plaidData, 'errors'));
}

render() {
const plaidBankAccounts = lodashGet(this.props.plaidData, 'bankAccounts') || [];
const token = this.getPlaidLinkToken();
Expand Down

0 comments on commit 2630132

Please sign in to comment.