-
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
[TS Migration] Migrate PlaidLink directory to TypeScript #30915
Changes from 5 commits
8c008e3
0205ca5
d7ca940
e55fe14
9e15bc8
a7ddf2c
42d0373
3d12dc8
2eaae67
b41332c
938887f
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 |
---|---|---|
@@ -1,27 +1,28 @@ | ||
import {useEffect} from 'react'; | ||
import {dismissLink, openLink, useDeepLinkRedirector, usePlaidEmitter} from 'react-native-plaid-link-sdk'; | ||
import {dismissLink, LinkEvent, openLink, useDeepLinkRedirector, usePlaidEmitter} from 'react-native-plaid-link-sdk'; | ||
import Log from '@libs/Log'; | ||
import CONST from '@src/CONST'; | ||
import {plaidLinkDefaultProps, plaidLinkPropTypes} from './plaidLinkPropTypes'; | ||
import PlaidLinkProps from './types'; | ||
|
||
function PlaidLink(props) { | ||
function PlaidLink({token, onSuccess = () => {}, onExit = () => {}, onEvent}: PlaidLinkProps) { | ||
useDeepLinkRedirector(); | ||
usePlaidEmitter((event) => { | ||
Log.info('[PlaidLink] Handled Plaid Event: ', false, event); | ||
props.onEvent(event.eventName, event.metadata); | ||
usePlaidEmitter((event: LinkEvent) => { | ||
Log.info('[PlaidLink] Handled Plaid Event: ', false, event.eventName); | ||
onEvent(event.eventName, event.metadata); | ||
}); | ||
useEffect(() => { | ||
props.onEvent(CONST.BANK_ACCOUNT.PLAID.EVENTS_NAME.OPEN, {}); | ||
onEvent(CONST.BANK_ACCOUNT.PLAID.EVENTS_NAME.OPEN); | ||
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. I know that this argument you've removed was probably unnecessary, but please make sure it doesn't cause any regressions. 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. This may actually cause a crash. Please do one of the following:
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. Done (1st option) |
||
openLink({ | ||
tokenConfig: { | ||
token: props.token, | ||
token, | ||
noLoadingState: false, | ||
JKobrynski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
onSuccess: ({publicToken, metadata}) => { | ||
props.onSuccess({publicToken, metadata}); | ||
onSuccess({publicToken, metadata}); | ||
}, | ||
onExit: (exitError, metadata) => { | ||
Log.info('[PlaidLink] Exit: ', false, {exitError, metadata}); | ||
props.onExit(); | ||
onExit: ({error, metadata}) => { | ||
Log.info('[PlaidLink] Exit: ', false, {error, metadata}); | ||
onExit(); | ||
}, | ||
}); | ||
|
||
|
@@ -35,8 +36,6 @@ function PlaidLink(props) { | |
return null; | ||
} | ||
|
||
PlaidLink.propTypes = plaidLinkPropTypes; | ||
PlaidLink.defaultProps = plaidLinkDefaultProps; | ||
PlaidLink.displayName = 'PlaidLink'; | ||
|
||
export default PlaidLink; |
JKobrynski marked this conversation as resolved.
Show resolved
Hide resolved
|
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||
import {LinkEventMetadata, LinkSuccessMetadata} from 'react-native-plaid-link-sdk'; | ||||||
import {PlaidLinkOnEventMetadata, PlaidLinkOnSuccessMetadata, PlaidLinkStableEvent} from 'react-plaid-link'; | ||||||
|
||||||
type PlaidLinkProps = { | ||||||
// Plaid Link SDK public token used to initialize the Plaid SDK | ||||||
token: string; | ||||||
|
||||||
// Callback to execute once the user taps continue after successfully entering their account information | ||||||
onSuccess?: (args: {publicToken?: string; metadata: PlaidLinkOnSuccessMetadata | LinkSuccessMetadata}) => void; | ||||||
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.
Suggested change
publicToken is not optional 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. Done! |
||||||
|
||||||
// Callback to execute when there is an error event emitted by the Plaid SDK | ||||||
onError?: (error: ErrorEvent | null) => void; | ||||||
|
||||||
// Callback to execute when the user leaves the Plaid widget flow without entering any information | ||||||
onExit?: () => void; | ||||||
|
||||||
// Callback to execute whenever a Plaid event occurs | ||||||
onEvent: (eventName: PlaidLinkStableEvent | string, metadata?: PlaidLinkOnEventMetadata | LinkEventMetadata) => void; | ||||||
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.
Suggested change
PlaidLinkStableEvent is a string 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. Updated |
||||||
|
||||||
// The redirect URI with an OAuth state ID. Needed to re-initialize the PlaidLink after directing the | ||||||
// user to their respective bank platform | ||||||
receivedRedirectURI?: string; | ||||||
}; | ||||||
|
||||||
export default PlaidLinkProps; |
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.
Are you sure there should be
event.eventName
here?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.
If you try to pass the whole
event
object, it produces the following error:Do you think we should keep it as it is or maybe
JSON.stringify
it?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.
Related to microsoft/TypeScript#15300. There is no correct way to fix. We can however apply a workaround:
{...event}
toLog.info
event: Pick<LinkEvent, keyof LinkEvent>
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.
Done (1st option)