@@ -3,8 +3,7 @@ import type {ReactElement, Ref} from 'react';
3
3
import React , { useCallback , useMemo } from 'react' ;
4
4
import type { GestureResponderEvent , StyleProp , ViewStyle } from 'react-native' ;
5
5
import { FlatList , View } from 'react-native' ;
6
- import type { OnyxEntry } from 'react-native-onyx' ;
7
- import { useOnyx , withOnyx } from 'react-native-onyx' ;
6
+ import { useOnyx } from 'react-native-onyx' ;
8
7
import type { SvgProps } from 'react-native-svg/lib/typescript/ReactNativeSVG' ;
9
8
import type { ValueOf } from 'type-fest' ;
10
9
import type { RenderSuggestionMenuItemProps } from '@components/AutoCompleteSuggestions/types' ;
@@ -18,6 +17,7 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback';
18
17
import Text from '@components/Text' ;
19
18
import useLocalize from '@hooks/useLocalize' ;
20
19
import useNetwork from '@hooks/useNetwork' ;
20
+ import type { FormattedSelectedPaymentMethodIcon } from '@hooks/usePaymentMethodState/types' ;
21
21
import useStyleUtils from '@hooks/useStyleUtils' ;
22
22
import useThemeStyles from '@hooks/useThemeStyles' ;
23
23
import * as CardUtils from '@libs/CardUtils' ;
@@ -30,29 +30,14 @@ import * as PaymentMethods from '@userActions/PaymentMethods';
30
30
import CONST from '@src/CONST' ;
31
31
import ONYXKEYS from '@src/ONYXKEYS' ;
32
32
import ROUTES from '@src/ROUTES' ;
33
- import type { AccountData , BankAccountList , CardList } from '@src/types/onyx' ;
33
+ import type { AccountData } from '@src/types/onyx' ;
34
34
import type { BankIcon } from '@src/types/onyx/Bank' ;
35
35
import type { Errors } from '@src/types/onyx/OnyxCommon' ;
36
36
import type PaymentMethod from '@src/types/onyx/PaymentMethod' ;
37
37
import type { FilterMethodPaymentType } from '@src/types/onyx/WalletTransfer' ;
38
38
import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
39
- import type { FormattedSelectedPaymentMethodIcon } from './WalletPage/types' ;
40
39
41
- type PaymentMethodListOnyxProps = {
42
- /** List of bank accounts */
43
- bankAccountList : OnyxEntry < BankAccountList > ;
44
-
45
- /** List of assigned cards */
46
- cardList : OnyxEntry < CardList > ;
47
-
48
- /** List of user's cards */
49
- // fundList: OnyxEntry<FundList>;
50
-
51
- /** Are we loading payment methods? */
52
- isLoadingPaymentMethods : OnyxEntry < boolean > ;
53
- } ;
54
-
55
- type PaymentMethodListProps = PaymentMethodListOnyxProps & {
40
+ type PaymentMethodListProps = {
56
41
/** Type of active/highlighted payment method */
57
42
actionPaymentMethodType ?: string ;
58
43
@@ -92,6 +77,9 @@ type PaymentMethodListProps = PaymentMethodListOnyxProps & {
92
77
/** Whether the add Payment button be shown on the list */
93
78
shouldShowAddPaymentMethodButton ?: boolean ;
94
79
80
+ /** Whether the add Bank account button be shown on the list */
81
+ shouldShowAddBankAccountButton ?: boolean ;
82
+
95
83
/** Whether the assigned cards should be shown on the list */
96
84
shouldShowAssignedCards ?: boolean ;
97
85
@@ -110,6 +98,9 @@ type PaymentMethodListProps = PaymentMethodListOnyxProps & {
110
98
isDefault ?: boolean ,
111
99
methodID ?: number ,
112
100
) => void ;
101
+
102
+ /** The policy invoice's transfer bank accountID */
103
+ invoiceTransferBankAccountID ?: number ;
113
104
} ;
114
105
115
106
type PaymentMethodItem = PaymentMethod & {
@@ -173,17 +164,13 @@ function keyExtractor(item: PaymentMethod) {
173
164
function PaymentMethodList ( {
174
165
actionPaymentMethodType = '' ,
175
166
activePaymentMethodID = '' ,
176
- bankAccountList = { } ,
177
167
buttonRef = ( ) => { } ,
178
- cardList = { } ,
179
- // Temporarily disabled because P2P debit cards are disabled.
180
- // fundList = {},
181
168
filterType = '' ,
182
169
listHeaderComponent,
183
- isLoadingPaymentMethods = true ,
184
170
onPress,
185
171
shouldShowSelectedState = false ,
186
172
shouldShowAddPaymentMethodButton = true ,
173
+ shouldShowAddBankAccountButton = false ,
187
174
shouldShowAddBankAccount = true ,
188
175
shouldShowEmptyListMessage = true ,
189
176
shouldShowAssignedCards = false ,
@@ -193,12 +180,18 @@ function PaymentMethodList({
193
180
style = { } ,
194
181
listItemStyle = { } ,
195
182
shouldShowRightIcon = true ,
183
+ invoiceTransferBankAccountID,
196
184
} : PaymentMethodListProps ) {
197
185
const styles = useThemeStyles ( ) ;
198
186
const StyleUtils = useStyleUtils ( ) ;
199
187
const { translate} = useLocalize ( ) ;
200
188
const { isOffline} = useNetwork ( ) ;
201
189
const [ isUserValidated ] = useOnyx ( ONYXKEYS . USER , { selector : ( user ) => ! ! user ?. validated } ) ;
190
+ const [ bankAccountList = { } ] = useOnyx ( ONYXKEYS . BANK_ACCOUNT_LIST ) ;
191
+ const [ cardList = { } ] = useOnyx ( ONYXKEYS . CARD_LIST ) ;
192
+ // Temporarily disabled because P2P debit cards are disabled.
193
+ // const [fundList = {}] = useOnyx(ONYXKEYS.FUND_LIST);
194
+ const [ isLoadingPaymentMethods = true ] = useOnyx ( ONYXKEYS . IS_LOADING_PAYMENT_METHODS ) ;
202
195
203
196
const getDescriptionForPolicyDomainCard = ( domainName : string ) : string => {
204
197
// A domain name containing a policyID indicates that this is a workspace feed
@@ -324,18 +317,29 @@ function PaymentMethodList({
324
317
const renderListEmptyComponent = ( ) => < Text style = { styles . popoverMenuItem } > { translate ( 'paymentMethodList.addFirstPaymentMethod' ) } </ Text > ;
325
318
326
319
const renderListFooterComponent = useCallback (
327
- ( ) => (
328
- < MenuItem
329
- onPress = { onPress }
330
- title = { translate ( 'walletPage.addBankAccount' ) }
331
- icon = { Expensicons . Plus }
332
- wrapperStyle = { [ styles . paymentMethod , listItemStyle ] }
333
- ref = { buttonRef }
334
- disabled = { ! isUserValidated }
335
- />
336
- ) ,
320
+ ( ) =>
321
+ shouldShowAddBankAccountButton ? (
322
+ < Button
323
+ ref = { buttonRef }
324
+ key = "addBankAccountButton"
325
+ text = { translate ( 'walletPage.addBankAccount' ) }
326
+ large
327
+ success
328
+ isDisabled = { ! isUserValidated }
329
+ onPress = { onPress }
330
+ />
331
+ ) : (
332
+ < MenuItem
333
+ onPress = { onPress }
334
+ title = { translate ( 'walletPage.addBankAccount' ) }
335
+ icon = { Expensicons . Plus }
336
+ wrapperStyle = { [ styles . paymentMethod , listItemStyle ] }
337
+ ref = { buttonRef }
338
+ disabled = { ! isUserValidated }
339
+ />
340
+ ) ,
337
341
338
- [ onPress , translate , styles . paymentMethod , listItemStyle , buttonRef , isUserValidated ] ,
342
+ [ shouldShowAddBankAccountButton , translate , onPress , buttonRef , styles . paymentMethod , listItemStyle , isUserValidated ] ,
339
343
) ;
340
344
341
345
/**
@@ -360,7 +364,11 @@ function PaymentMethodList({
360
364
iconHeight = { item . iconHeight ?? item . iconSize }
361
365
iconWidth = { item . iconWidth ?? item . iconSize }
362
366
iconStyles = { item . iconStyles }
363
- badgeText = { shouldShowDefaultBadge ( filteredPaymentMethods , item . isDefault ) ? translate ( 'paymentMethodList.defaultPaymentMethod' ) : undefined }
367
+ badgeText = {
368
+ shouldShowDefaultBadge ( filteredPaymentMethods , invoiceTransferBankAccountID ? invoiceTransferBankAccountID === item . methodID : item . isDefault )
369
+ ? translate ( 'paymentMethodList.defaultPaymentMethod' )
370
+ : undefined
371
+ }
364
372
wrapperStyle = { [ styles . paymentMethod , listItemStyle ] }
365
373
iconRight = { item . iconRight }
366
374
badgeStyle = { styles . badgeBordered }
@@ -374,7 +382,7 @@ function PaymentMethodList({
374
382
</ OfflineWithFeedback >
375
383
) ,
376
384
377
- [ styles . ph6 , styles . paymentMethod , styles . badgeBordered , filteredPaymentMethods , translate , listItemStyle , shouldShowSelectedState , selectedMethodID ] ,
385
+ [ styles . ph6 , styles . paymentMethod , styles . badgeBordered , filteredPaymentMethods , invoiceTransferBankAccountID , translate , listItemStyle , shouldShowSelectedState , selectedMethodID ] ,
378
386
) ;
379
387
380
388
return (
@@ -416,18 +424,4 @@ function PaymentMethodList({
416
424
417
425
PaymentMethodList . displayName = 'PaymentMethodList' ;
418
426
419
- export default withOnyx < PaymentMethodListProps , PaymentMethodListOnyxProps > ( {
420
- bankAccountList : {
421
- key : ONYXKEYS . BANK_ACCOUNT_LIST ,
422
- } ,
423
- cardList : {
424
- key : ONYXKEYS . CARD_LIST ,
425
- } ,
426
- // Temporarily disabled - used for P2P debit cards
427
- // fundList: {
428
- // key: ONYXKEYS.FUND_LIST,
429
- // },
430
- isLoadingPaymentMethods : {
431
- key : ONYXKEYS . IS_LOADING_PAYMENT_METHODS ,
432
- } ,
433
- } ) ( PaymentMethodList ) ;
427
+ export default PaymentMethodList ;
0 commit comments