From 2630132a75e7ddf10693e4b20c6f09bf34c0e1d7 Mon Sep 17 00:00:00 2001 From: VH Date: Sat, 1 Apr 2023 09:21:57 +0700 Subject: [PATCH 1/4] Prevent Plaid triggered again on selector bank accounts page after back from offline --- src/components/AddPlaidBankAccount.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/AddPlaidBankAccount.js b/src/components/AddPlaidBankAccount.js index 8d15e8e23fab..4fe5cc542613 100644 --- a/src/components/AddPlaidBankAccount.js +++ b/src/components/AddPlaidBankAccount.js @@ -78,9 +78,7 @@ 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; } @@ -88,11 +86,11 @@ class AddPlaidBankAccount extends React.Component { } 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); } @@ -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(); From 93f32d03fc94ffa83313546687aea13ac3864361 Mon Sep 17 00:00:00 2001 From: VH Date: Fri, 7 Apr 2023 22:36:45 +0700 Subject: [PATCH 2/4] Rename method --- src/components/AddPlaidBankAccount.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/AddPlaidBankAccount.js b/src/components/AddPlaidBankAccount.js index 4fe5cc542613..99a837c6471c 100644 --- a/src/components/AddPlaidBankAccount.js +++ b/src/components/AddPlaidBankAccount.js @@ -78,7 +78,7 @@ 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) || this.hasPlaidBankAccountsData()) { + if ((this.props.receivedRedirectURI && this.props.plaidLinkOAuthToken) || this.hasPlaidBankData()) { return; } @@ -86,11 +86,11 @@ class AddPlaidBankAccount extends React.Component { } componentDidUpdate(prevProps) { - if (!prevProps.network.isOffline || this.props.network.isOffline || this.hasPlaidBankAccountsData()) { + if (!prevProps.network.isOffline || this.props.network.isOffline || this.hasPlaidBankData()) { return; } - // 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 + // If we are coming back from offline and we haven't had Plaid bank data yet, we need to re-run our call to kick off Plaid BankAccounts.openPlaidBankLogin(this.props.allowDebit, this.props.bankAccountID); } @@ -110,7 +110,7 @@ class AddPlaidBankAccount extends React.Component { /** * @returns {Boolean} */ - hasPlaidBankAccountsData() { + hasPlaidBankData() { return !_.isEmpty(lodashGet(this.props.plaidData, 'bankAccounts')) || !_.isEmpty(lodashGet(this.props.plaidData, 'errors')); } From dff86729ffe66ed557b5f659e6c92b5a091cf9e0 Mon Sep 17 00:00:00 2001 From: VH Date: Sat, 8 Apr 2023 00:16:38 +0700 Subject: [PATCH 3/4] Rename method hasPlaidData --- src/components/AddPlaidBankAccount.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/AddPlaidBankAccount.js b/src/components/AddPlaidBankAccount.js index 99a837c6471c..0ffb1ebdd84f 100644 --- a/src/components/AddPlaidBankAccount.js +++ b/src/components/AddPlaidBankAccount.js @@ -78,7 +78,7 @@ 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) || this.hasPlaidBankData()) { + if ((this.props.receivedRedirectURI && this.props.plaidLinkOAuthToken) || this.hasPlaidData()) { return; } @@ -86,11 +86,11 @@ class AddPlaidBankAccount extends React.Component { } componentDidUpdate(prevProps) { - if (!prevProps.network.isOffline || this.props.network.isOffline || this.hasPlaidBankData()) { + if (!prevProps.network.isOffline || this.props.network.isOffline || this.hasPlaidData()) { return; } - // If we are coming back from offline and we haven't had Plaid bank data yet, 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 BankAccounts.openPlaidBankLogin(this.props.allowDebit, this.props.bankAccountID); } @@ -110,7 +110,7 @@ class AddPlaidBankAccount extends React.Component { /** * @returns {Boolean} */ - hasPlaidBankData() { + hasPlaidData() { return !_.isEmpty(lodashGet(this.props.plaidData, 'bankAccounts')) || !_.isEmpty(lodashGet(this.props.plaidData, 'errors')); } From a7f8c8b81aefebe3b2f24e28e7a4ac947cced644 Mon Sep 17 00:00:00 2001 From: VH Date: Wed, 12 Apr 2023 16:04:50 +0700 Subject: [PATCH 4/4] Reuse checking Plaid bank login for both componentDidAmount and componentDidUpdate --- src/components/AddPlaidBankAccount.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/AddPlaidBankAccount.js b/src/components/AddPlaidBankAccount.js index 0ffb1ebdd84f..1977795e2301 100644 --- a/src/components/AddPlaidBankAccount.js +++ b/src/components/AddPlaidBankAccount.js @@ -78,7 +78,7 @@ 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) || this.hasPlaidData()) { + if (this.isAuthenticatedWithPlaid()) { return; } @@ -86,11 +86,11 @@ class AddPlaidBankAccount extends React.Component { } componentDidUpdate(prevProps) { - if (!prevProps.network.isOffline || this.props.network.isOffline || this.hasPlaidData()) { + if (!prevProps.network.isOffline || this.props.network.isOffline || this.isAuthenticatedWithPlaid()) { return; } - // 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 + // 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 BankAccounts.openPlaidBankLogin(this.props.allowDebit, this.props.bankAccountID); } @@ -110,8 +110,10 @@ class AddPlaidBankAccount extends React.Component { /** * @returns {Boolean} */ - hasPlaidData() { - return !_.isEmpty(lodashGet(this.props.plaidData, 'bankAccounts')) || !_.isEmpty(lodashGet(this.props.plaidData, 'errors')); + isAuthenticatedWithPlaid() { + return ((this.props.receivedRedirectURI && this.props.plaidLinkOAuthToken) + || !_.isEmpty(lodashGet(this.props.plaidData, 'bankAccounts')) + || !_.isEmpty(lodashGet(this.props.plaidData, 'errors'))); } render() {