-
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
Merged
mountiny
merged 11 commits into
Expensify:main
from
JKobrynski:migratePlaidLinkToTypeScript
Nov 28, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8c008e3
start migrating PlaidLink to TypeScript
JKobrynski 0205ca5
migrate PlaidLinks native module to TypeScript, create a file for types
JKobrynski d7ca940
Merge branch 'main' into migratePlaidLinkToTypeScript
JKobrynski e55fe14
migrate native PlaidLink to TypeScript
JKobrynski 9e15bc8
make onEvent a required prop to avoid optional chaining
JKobrynski a7ddf2c
Merge branch 'main' into migratePlaidLinkToTypeScript
JKobrynski 42d0373
remove unused nativeModule
JKobrynski 3d12dc8
pass event to Log.info
JKobrynski 2eaae67
allow metadata to be undefined in onEvent
JKobrynski b41332c
make publicToken required param
JKobrynski 938887f
change eventName type to string
JKobrynski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {useEffect} from 'react'; | ||
import {dismissLink, LinkEvent, openLink, useDeepLinkRedirector, usePlaidEmitter} from 'react-native-plaid-link-sdk'; | ||
import Log from '@libs/Log'; | ||
import CONST from '@src/CONST'; | ||
import PlaidLinkProps from './types'; | ||
|
||
function PlaidLink({token, onSuccess = () => {}, onExit = () => {}, onEvent}: PlaidLinkProps) { | ||
useDeepLinkRedirector(); | ||
usePlaidEmitter((event: LinkEvent) => { | ||
Log.info('[PlaidLink] Handled Plaid Event: ', false, {...event}); | ||
onEvent(event.eventName, event.metadata); | ||
}); | ||
useEffect(() => { | ||
onEvent(CONST.BANK_ACCOUNT.PLAID.EVENTS_NAME.OPEN); | ||
openLink({ | ||
tokenConfig: { | ||
token, | ||
noLoadingState: false, | ||
JKobrynski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
onSuccess: ({publicToken, metadata}) => { | ||
onSuccess({publicToken, metadata}); | ||
}, | ||
onExit: ({error, metadata}) => { | ||
Log.info('[PlaidLink] Exit: ', false, {error, metadata}); | ||
onExit(); | ||
}, | ||
}); | ||
|
||
return () => { | ||
dismissLink(); | ||
}; | ||
|
||
// We generally do not need to include the token as a dependency here as it is only provided once via props and should not change | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
return null; | ||
} | ||
|
||
PlaidLink.displayName = 'PlaidLink'; | ||
|
||
export default PlaidLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
26 changes: 10 additions & 16 deletions
26
...omponents/PlaidLink/plaidLinkPropTypes.js → src/components/PlaidLink/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,25 @@ | ||
import PropTypes from 'prop-types'; | ||
import {LinkEventMetadata, LinkSuccessMetadata} from 'react-native-plaid-link-sdk'; | ||
import {PlaidLinkOnEventMetadata, PlaidLinkOnSuccessMetadata} from 'react-plaid-link'; | ||
|
||
const plaidLinkPropTypes = { | ||
type PlaidLinkProps = { | ||
// Plaid Link SDK public token used to initialize the Plaid SDK | ||
token: PropTypes.string.isRequired, | ||
token: string; | ||
|
||
// Callback to execute once the user taps continue after successfully entering their account information | ||
onSuccess: PropTypes.func, | ||
onSuccess?: (args: {publicToken: string; metadata: PlaidLinkOnSuccessMetadata | LinkSuccessMetadata}) => void; | ||
|
||
// Callback to execute when there is an error event emitted by the Plaid SDK | ||
onError: PropTypes.func, | ||
onError?: (error: ErrorEvent | null) => void; | ||
|
||
// Callback to execute when the user leaves the Plaid widget flow without entering any information | ||
onExit: PropTypes.func, | ||
onExit?: () => void; | ||
|
||
// Callback to execute whenever a Plaid event occurs | ||
onEvent: PropTypes.func, | ||
onEvent: (eventName: string, metadata?: PlaidLinkOnEventMetadata | LinkEventMetadata) => void; | ||
|
||
// The redirect URI with an OAuth state ID. Needed to re-initialize the PlaidLink after directing the | ||
// user to their respective bank platform | ||
receivedRedirectURI: PropTypes.string, | ||
receivedRedirectURI?: string; | ||
}; | ||
|
||
const plaidLinkDefaultProps = { | ||
onSuccess: () => {}, | ||
onError: () => {}, | ||
onExit: () => {}, | ||
receivedRedirectURI: null, | ||
}; | ||
|
||
export {plaidLinkPropTypes, plaidLinkDefaultProps}; | ||
export default PlaidLinkProps; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This may actually cause a crash. Please do one of the following:
types.ts
to mark metadata as required)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)