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

Update Plaid Link Component #6362

Merged
merged 8 commits into from
Nov 22, 2021
Merged
Changes from 6 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
59 changes: 25 additions & 34 deletions src/components/PlaidLink/index.native.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,46 @@
import React from 'react';
import {useEffect} from 'react';
import {NativeEventEmitter} from 'react-native';
import {openLink} from 'react-native-plaid-link-sdk';
import {openLink, useDeepLinkRedirector} from 'react-native-plaid-link-sdk';
import Log from '../../libs/Log';
import CONST from '../../CONST';
import nativeModule from './nativeModule';
import {plaidLinkPropTypes, plaidLinkDefaultProps} from './plaidLinkPropTypes';

class PlaidLink extends React.Component {
constructor(props) {
super(props);
this.listener = undefined;
}

componentDidMount() {
const PlaidLink = (props) => {
let listener;
useDeepLinkRedirector();
useEffect(() => {
const emitter = new NativeEventEmitter(nativeModule);
this.listener = emitter.addListener('onEvent', this.onEvent.bind(this));
listener = emitter.addListener('onEvent', (event) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it will work, but I noticed there's also this in the docs

https://github.com/plaid/react-native-plaid-link-sdk#to-receive-onevent-callbacks

Log.info('[PlaidLink] Handled Plaid Event: ', false, event);
if (event.eventName === CONST.PLAID.EVENT.ERROR) {
props.onError(event.metadata);
} else if (event.eventName === CONST.PLAID.EVENT.EXIT) {
props.onExit();
}
});

openLink({
tokenConfig: {
token: this.props.token,
token: props.token,
},
onSuccess: ({publicToken, metadata}) => {
this.props.onSuccess({publicToken, metadata});
props.onSuccess({publicToken, metadata});
},
});
}

componentWillUnmount() {
if (!this.listener) {
return;
}

this.listener.remove();
}
return () => {
if (listener) {
return;
}

/**
* @param {*} event
*/
onEvent(event) {
Log.info('[PlaidLink] Handled Plaid Event: ', false, event);
if (event.eventName === CONST.PLAID.EVENT.ERROR) {
this.props.onError(event.metadata);
} else if (event.eventName === CONST.PLAID.EVENT.EXIT) {
this.props.onExit();
}
}
listener.remove();
};
}, []);

render() {
return null;
}
}
return null;
};

PlaidLink.propTypes = plaidLinkPropTypes;
PlaidLink.defaultProps = plaidLinkDefaultProps;
Expand Down