Skip to content

Commit

Permalink
Update PlaidLink to check for receivedRedirectURI
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Murray committed Dec 2, 2021
1 parent 7d27703 commit 34d2422
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/components/AddPlaidBankAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class AddPlaidBankAccount extends React.Component {
super(props);

this.selectAccount = this.selectAccount.bind(this);
this.getPlaidLinkToken = this.getPlaidLinkToken.bind(this);

this.state = {
selectedIndex: undefined,
Expand Down Expand Up @@ -155,14 +156,26 @@ class AddPlaidBankAccount extends React.Component {
});
}

/**
* @returns {String}
*/
getPlaidLinkToken() {
if (!_.isEmpty(this.props.plaidLinkToken)) {
return this.props.plaidLinkToken;
}

if (this.props.receivedRedirectURI) {
return this.props.plaidLinkOAuthToken;
}
}

render() {
const accounts = this.getAccounts();
const options = _.map(accounts, (account, index) => ({
value: index, label: `${account.addressName} ${account.accountNumber}`,
}));
const {icon, iconSize} = getBankIcon(this.state.institution.name);
const hasPlaidLinkToken = !_.isEmpty(this.props.plaidLinkToken) || !_.isEmpty(this.props.plaidLinkOAuthToken);
const plaidLinkToken = !_.isEmpty(this.props.plaidLinkToken) ? this.props.plaidLinkToken : this.props.plaidLinkOAuthToken;

return (
<>
Expand All @@ -174,7 +187,7 @@ class AddPlaidBankAccount extends React.Component {
)}
{hasPlaidLinkToken && (
<PlaidLink
token={plaidLinkToken}
token={this.getPlaidLinkToken()}
onSuccess={({publicToken, metadata}) => {
Log.info('[PlaidLink] Success!');
BankAccounts.getPlaidBankAccounts(publicToken, metadata.institution.name);
Expand Down

0 comments on commit 34d2422

Please sign in to comment.