Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Plaid triggered again on selector bank accounts page after coming back from offline #17136

Merged
merged 4 commits into from
Apr 12, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.hasPlaidData()) {
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.hasPlaidData()) {
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 Plaid data yet, we need to re-run our call to kick off Plaid
hoangzinh marked this conversation as resolved.
Show resolved Hide resolved
BankAccounts.openPlaidBankLogin(this.props.allowDebit, this.props.bankAccountID);
}

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

/**
* @returns {Boolean}
*/
hasPlaidData() {
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