-
Notifications
You must be signed in to change notification settings - Fork 121
/
PlaidLink.js
141 lines (124 loc) · 4.03 KB
/
PlaidLink.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import PropTypes from 'prop-types';
import React from 'react';
import { Button, NativeModules, Platform, View } from 'react-native';
const openLink = async ({ onExit, onSuccess, ...serializable }) => {
if (Platform.OS === 'android') {
const constants = NativeModules.PlaidAndroid.getConstants();
NativeModules.PlaidAndroid.startLinkActivityForResult(
JSON.stringify(serializable),
result => {
switch (result.resultCode) {
case constants.RESULT_SUCCESS:
if (onSuccess != null) {
onSuccess(result.data);
}
break;
case constants.RESULT_EXCEPTION:
case constants.RESULT_CANCELLED:
case constants.RESULT_EXIT:
if (onExit != null) {
onExit(result.data);
}
break;
}
},
);
} else {
NativeModules.RNLinksdk.create(serializable);
NativeModules.RNLinksdk.open((error, metadata) => {
if (error) {
if (onExit != null) {
var data = metadata || {};
data.error = error;
onExit(data);
}
} else {
switch (metadata.status) {
case 'connected':
if (onSuccess != null) {
onSuccess(metadata);
}
break;
default:
if (onExit != null) {
onExit(metadata);
}
break;
}
}
});
}
};
export const PlaidLink = ({
children,
className,
title,
accessibilityLabel,
color,
...linkProps
}) => {
return (
<View>
<Button
className={className}
onPress={() => openLink(linkProps)}
title={title}
accessibilityLabel={accessibilityLabel}
color={color}
>
{children}
</Button>
</View>
);
};
PlaidLink.propTypes = {
// Required props
// Displayed once a user has successfully linked their account
clientName: PropTypes.string.isRequired,
// The Plaid API environment on which to create user accounts.
env: PropTypes.oneOf(['development', 'sandbox', 'production']).isRequired,
// A function that is called when a user has successfully onboarded their
// account. The function should expect two arguments, the public_key and a
// metadata object.
onSuccess: PropTypes.func.isRequired,
// The Plaid product(s) you wish to use, an array containing some of
// auth, identity, income, transactions, assets, liabilities, investments.
product: PropTypes.arrayOf(
PropTypes.oneOf([
'auth',
'identity',
'income',
'transactions',
'assets',
'liabilities',
'investments',
]),
).isRequired,
// The public_key associated with your account; available from
// the Plaid dashboard (https://dashboard.plaid.com).
publicKey: PropTypes.string.isRequired,
// Optional props
// Button class name as a string.
className: PropTypes.string,
// A list of Plaid-supported country codes using the ISO-3166-1 alpha-2
// country code standard.
countryCodes: PropTypes.arrayOf(PropTypes.string),
// Plaid-supported language to localize Link. English will be used by default.
language: PropTypes.string,
// A function that is called when a user has specifically exited Link flow.
onExit: PropTypes.func,
// Specify an existing user's public token to launch Link in update mode.
// This will cause Link to open directly to the authentication step for
// that user's institution.
token: PropTypes.string,
// Specify a user to enable all Auth features. Reach out to your
// account manager or integrations@plaid.com to get enabled. See the Auth
// [https://plaid.com/docs#auth] docs for integration details.
userEmailAddress: PropTypes.string,
userLegalName: PropTypes.string,
userPhoneNumber: PropTypes.string,
// Specify a webhook to associate with a user.
webhook: PropTypes.string,
// Note: onEvent is omitted here, to handle onEvent callbacks refer to
// the documentation here: https://github.com/plaid/react-native-plaid-link-sdk#to-receive-onevent-callbacks
};