-
Notifications
You must be signed in to change notification settings - Fork 155
/
component.tsx
65 lines (57 loc) · 1.61 KB
/
component.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from 'react';
import {
PlaidLink,
PlaidLinkOnSuccess,
PlaidLinkOnEvent,
PlaidLinkOnExit,
} from 'react-plaid-link';
interface Props {}
interface State {
token: null;
}
class PlaidLinkClass extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { token: null };
}
async createLinkToken() {
// get a link_token from your server
const response = await fetch('/api/create_link_token', { method: 'POST' });
const { link_token } = await response.json();
return link_token;
}
async componentDidMount() {
const token = await this.createLinkToken();
this.setState({ token });
}
onSuccess: PlaidLinkOnSuccess = (publicToken, metadata) => {
// send public_token to your server
// https://plaid.com/docs/api/tokens/#token-exchange-flow
console.log(publicToken, metadata);
};
onEvent: PlaidLinkOnEvent = (eventName, metadata) => {
// log onEvent callbacks from Link
// https://plaid.com/docs/link/web/#onevent
console.log(eventName, metadata);
};
onExit: PlaidLinkOnExit = (error, metadata) => {
// log onExit callbacks from Link, handle errors
// https://plaid.com/docs/link/web/#onexit
console.log(error, metadata);
};
render() {
return (
<PlaidLink
className="CustomButton"
style={{ padding: '20px', fontSize: '16px', cursor: 'pointer' }}
token={this.state.token}
onSuccess={this.onSuccess}
onEvent={this.onEvent}
onExit={this.onExit}
>
Link your bank account
</PlaidLink>
);
}
}
export default PlaidLinkClass;