-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 and refactor VBBA setup flow #13236
Changes from all commits
687cac6
2af34d4
4f01183
51b3bbd
027802b
9110d5c
e9ffd6f
f88f7f9
8f6c6ea
a18a5af
a90b064
101175c
65f61de
7590db5
eeb4ec7
23f96df
99a780b
36303c4
687612f
193a858
a216a65
d581526
6cfea8e
1190b6a
153a928
87b322d
1bbd590
4fa052c
5515fdb
2df31d6
c55f574
4a1ff1f
a2536ad
ab5417a
6f0af2c
bcf8248
c680b84
cba528a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ import { | |
View, | ||
} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import lodashGet from 'lodash/get'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import lodashGet from 'lodash/get'; | ||
import Log from '../libs/Log'; | ||
import PlaidLink from './PlaidLink'; | ||
import * as BankAccounts from '../libs/actions/BankAccounts'; | ||
|
@@ -16,15 +16,15 @@ import themeColors from '../styles/themes/default'; | |
import compose from '../libs/compose'; | ||
import withLocalize, {withLocalizePropTypes} from './withLocalize'; | ||
import Picker from './Picker'; | ||
import plaidDataPropTypes from '../pages/ReimbursementAccount/plaidDataPropTypes'; | ||
import {plaidDataPropTypes} from '../pages/ReimbursementAccount/plaidDataPropTypes'; | ||
import Text from './Text'; | ||
import getBankIcon from './Icon/BankIcons'; | ||
import Icon from './Icon'; | ||
import FullPageOfflineBlockingView from './BlockingViews/FullPageOfflineBlockingView'; | ||
|
||
const propTypes = { | ||
/** Contains plaid data */ | ||
plaidData: plaidDataPropTypes, | ||
plaidData: plaidDataPropTypes.isRequired, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, can't seem to reproduce this error anymore but it was when clicking on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During my multiple testings, I think I also got it once, but then it disappeared. |
||
|
||
/** Selected account ID from the Picker associated with the end of the Plaid flow */ | ||
selectedPlaidAccountID: PropTypes.string, | ||
|
@@ -57,14 +57,6 @@ const propTypes = { | |
}; | ||
|
||
const defaultProps = { | ||
plaidData: { | ||
bankName: '', | ||
plaidAccessToken: '', | ||
bankAccounts: [], | ||
isLoading: false, | ||
error: '', | ||
errors: {}, | ||
}, | ||
selectedPlaidAccountID: '', | ||
plaidLinkToken: '', | ||
onExitPlaid: () => {}, | ||
|
@@ -85,7 +77,9 @@ 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(this.props.plaidData)) { | ||
if ((this.props.receivedRedirectURI && this.props.plaidLinkOAuthToken) | ||
|| !_.isEmpty(lodashGet(this.props.plaidData, 'bankAccounts')) | ||
|| !_.isEmpty(lodashGet(this.props.plaidData, 'errors'))) { | ||
return; | ||
} | ||
|
||
|
@@ -106,20 +100,22 @@ class AddPlaidBankAccount extends React.Component { | |
} | ||
|
||
render() { | ||
const plaidBankAccounts = lodashGet(this.props.plaidData, 'bankAccounts', []); | ||
const plaidBankAccounts = lodashGet(this.props.plaidData, 'bankAccounts') || []; | ||
const token = this.getPlaidLinkToken(); | ||
const options = _.map(plaidBankAccounts, account => ({ | ||
value: account.plaidAccountID, | ||
label: `${account.addressName} ${account.mask}`, | ||
})); | ||
const {icon, iconSize} = getBankIcon(); | ||
const plaidDataErrorMessage = !_.isEmpty(this.props.plaidData.errors) ? _.chain(this.props.plaidData.errors).values().first().value() : this.props.plaidData.error; | ||
const plaidErrors = lodashGet(this.props.plaidData, 'errors'); | ||
const plaidDataErrorMessage = !_.isEmpty(plaidErrors) ? _.chain(plaidErrors).values().first().value() : ''; | ||
const bankName = lodashGet(this.props.plaidData, 'bankName'); | ||
|
||
// Plaid Link view | ||
if (!plaidBankAccounts.length) { | ||
return ( | ||
<FullPageOfflineBlockingView> | ||
{this.props.plaidData.isLoading && ( | ||
{lodashGet(this.props.plaidData, 'isLoading') && ( | ||
<View style={[styles.flex1, styles.alignItemsCenter, styles.justifyContentCenter]}> | ||
<ActivityIndicator color={themeColors.spinner} size="large" /> | ||
</View> | ||
|
@@ -129,13 +125,12 @@ class AddPlaidBankAccount extends React.Component { | |
{plaidDataErrorMessage} | ||
</Text> | ||
)} | ||
{Boolean(token) && ( | ||
{Boolean(token) && !bankName && ( | ||
<PlaidLink | ||
token={token} | ||
onSuccess={({publicToken, metadata}) => { | ||
Log.info('[PlaidLink] Success!'); | ||
BankAccounts.openPlaidBankAccountSelector(publicToken, metadata.institution.name, this.props.allowDebit); | ||
BankAccounts.updatePlaidData({institution: metadata.institution}); | ||
}} | ||
onError={(error) => { | ||
Log.hmmm('[PlaidLink] Error: ', error.message); | ||
|
@@ -163,7 +158,7 @@ class AddPlaidBankAccount extends React.Component { | |
height={iconSize} | ||
width={iconSize} | ||
/> | ||
<Text style={[styles.ml3, styles.textStrong]}>{this.props.plaidData.bankName}</Text> | ||
<Text style={[styles.ml3, styles.textStrong]}>{bankName}</Text> | ||
</View> | ||
<View style={[styles.mb5]}> | ||
<Picker | ||
|
@@ -188,9 +183,6 @@ AddPlaidBankAccount.defaultProps = defaultProps; | |
export default compose( | ||
withLocalize, | ||
withOnyx({ | ||
plaidData: { | ||
key: ONYXKEYS.PLAID_DATA, | ||
}, | ||
plaidLinkToken: { | ||
key: ONYXKEYS.PLAID_LINK_TOKEN, | ||
initWithStoredValues: false, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import _ from 'underscore'; | ||
import lodashGet from 'lodash/get'; | ||
import * as BankAccounts from './actions/BankAccounts'; | ||
import FormHelper from './FormHelper'; | ||
|
@@ -15,28 +14,16 @@ const clearErrors = (props, paths) => formHelper.clearErrors(props, paths); | |
/** | ||
* Get the default state for input fields in the VBA flow | ||
* | ||
* @param {Object} props | ||
* @param {Object} reimbursementAccountDraft | ||
* @param {Object} reimbursementAccount | ||
* @param {String} fieldName | ||
* @param {*} defaultValue | ||
* | ||
* @returns {*} | ||
*/ | ||
function getDefaultStateForField(props, fieldName, defaultValue = '') { | ||
return lodashGet(props, ['reimbursementAccountDraft', fieldName]) | ||
|| lodashGet(props, ['reimbursementAccount', 'achData', fieldName], defaultValue); | ||
} | ||
|
||
/** | ||
* @param {Object} props | ||
* @param {Array} fieldNames | ||
* | ||
* @returns {*} | ||
*/ | ||
function getBankAccountFields(props, fieldNames) { | ||
return { | ||
..._.pick(lodashGet(props, 'reimbursementAccount.achData'), ...fieldNames), | ||
..._.pick(props.reimbursementAccountDraft, ...fieldNames), | ||
}; | ||
function getDefaultStateForField(reimbursementAccountDraft, reimbursementAccount, fieldName, defaultValue = '') { | ||
Comment on lines
-35
to
-39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious why this function was moved to CompanyStep.js instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because it's only used there |
||
return lodashGet(reimbursementAccountDraft, fieldName) | ||
|| lodashGet(reimbursementAccount, ['achData', fieldName], defaultValue); | ||
} | ||
|
||
/** | ||
|
@@ -56,5 +43,4 @@ export { | |
clearError, | ||
clearErrors, | ||
getErrorText, | ||
getBankAccountFields, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming from #32906, this change caused a regression, after this change the plaid token is not cleared.