11import React , { useCallback , useEffect , useRef , useState } from 'react' ;
22import { ActivityIndicator , View } from 'react-native' ;
33import type { OnyxEntry } from 'react-native-onyx' ;
4- import { withOnyx } from 'react-native-onyx' ;
54import useLocalize from '@hooks/useLocalize' ;
65import useNetwork from '@hooks/useNetwork' ;
6+ import useOnyx from '@hooks/useOnyx' ;
77import useTheme from '@hooks/useTheme' ;
88import useThemeStyles from '@hooks/useThemeStyles' ;
99import { handlePlaidError , openPlaidBankAccountSelector , openPlaidBankLogin , setPlaidEvent } from '@libs/actions/BankAccounts' ;
@@ -22,15 +22,7 @@ import PlaidLink from './PlaidLink';
2222import RadioButtons from './RadioButtons' ;
2323import Text from './Text' ;
2424
25- type AddPlaidBankAccountOnyxProps = {
26- /** If the user has been throttled from Plaid */
27- isPlaidDisabled : OnyxEntry < boolean > ;
28-
29- /** Plaid SDK token to use to initialize the widget */
30- plaidLinkToken : OnyxEntry < string > ;
31- } ;
32-
33- type AddPlaidBankAccountProps = AddPlaidBankAccountOnyxProps & {
25+ type AddPlaidBankAccountProps = {
3426 /** Contains plaid data */
3527 plaidData : OnyxEntry < PlaidData > ;
3628
@@ -71,15 +63,13 @@ type AddPlaidBankAccountProps = AddPlaidBankAccountOnyxProps & {
7163function AddPlaidBankAccount ( {
7264 plaidData,
7365 selectedPlaidAccountID = '' ,
74- plaidLinkToken,
7566 onExitPlaid = ( ) => { } ,
7667 onSelect = ( ) => { } ,
7768 text = '' ,
7869 receivedRedirectURI,
7970 plaidLinkOAuthToken = '' ,
8071 bankAccountID = 0 ,
8172 allowDebit = false ,
82- isPlaidDisabled,
8373 errorText = '' ,
8474 onInputChange = ( ) => { } ,
8575 isDisplayedInWalletFlow = false ,
@@ -88,12 +78,13 @@ function AddPlaidBankAccount({
8878 const styles = useThemeStyles ( ) ;
8979 const plaidBankAccounts = plaidData ?. bankAccounts ?? [ ] ;
9080 const defaultSelectedPlaidAccount = plaidBankAccounts . find ( ( account ) => account . plaidAccountID === selectedPlaidAccountID ) ;
91- const defaultSelectedPlaidAccountID = defaultSelectedPlaidAccount ?. plaidAccountID ?? '-1' ;
81+ const defaultSelectedPlaidAccountID = defaultSelectedPlaidAccount ?. plaidAccountID ;
9282 const defaultSelectedPlaidAccountMask = plaidBankAccounts . find ( ( account ) => account . plaidAccountID === selectedPlaidAccountID ) ?. mask ?? '' ;
9383 const subscribedKeyboardShortcuts = useRef < Array < ( ) => void > > ( [ ] ) ;
9484 const previousNetworkState = useRef < boolean | undefined > ( undefined ) ;
9585 const [ selectedPlaidAccountMask , setSelectedPlaidAccountMask ] = useState ( defaultSelectedPlaidAccountMask ) ;
96-
86+ const [ plaidLinkToken ] = useOnyx ( ONYXKEYS . PLAID_LINK_TOKEN , { canBeMissing : true , initWithStoredValues : false } ) ;
87+ const [ isPlaidDisabled ] = useOnyx ( ONYXKEYS . IS_PLAID_DISABLED , { canBeMissing : true } ) ;
9788 const { translate} = useLocalize ( ) ;
9889 const { isOffline} = useNetwork ( ) ;
9990
@@ -287,12 +278,4 @@ function AddPlaidBankAccount({
287278
288279AddPlaidBankAccount . displayName = 'AddPlaidBankAccount' ;
289280
290- export default withOnyx < AddPlaidBankAccountProps , AddPlaidBankAccountOnyxProps > ( {
291- plaidLinkToken : {
292- key : ONYXKEYS . PLAID_LINK_TOKEN ,
293- initWithStoredValues : false ,
294- } ,
295- isPlaidDisabled : {
296- key : ONYXKEYS . IS_PLAID_DISABLED ,
297- } ,
298- } ) ( AddPlaidBankAccount ) ;
281+ export default AddPlaidBankAccount ;
0 commit comments