@@ -17,11 +17,7 @@ import FixedFooter from './FixedFooter';
17
17
import ExpensiTextInput from './ExpensiTextInput' ;
18
18
import CONST from '../CONST' ;
19
19
import ButtonWithMenu from './ButtonWithMenu' ;
20
- import * as Expensicons from './Icon/Expensicons' ;
21
- import Permissions from '../libs/Permissions' ;
22
- import isAppInstalled from '../libs/isAppInstalled' ;
23
- import * as ValidationUtils from '../libs/ValidationUtils' ;
24
- import makeCancellablePromise from '../libs/MakeCancellablePromise' ;
20
+ import SettlementButton from './SettlementButton' ;
25
21
26
22
const propTypes = {
27
23
/** Callback to inform parent modal of success */
@@ -118,38 +114,20 @@ class IOUConfirmationList extends Component {
118
114
constructor ( props ) {
119
115
super ( props ) ;
120
116
121
- const formattedParticipants = _ . map ( this . getParticipantsWithAmount ( this . props . participants ) , participant => ( {
117
+ const formattedParticipants = _ . map ( this . getParticipantsWithAmount ( props . participants ) , participant => ( {
122
118
...participant , selected : true ,
123
119
} ) ) ;
124
120
125
- // Add the button options to payment menu
126
- const confirmationButtonOptions = [ ] ;
127
- let defaultButtonOption = {
128
- text : this . props . translate ( this . props . hasMultipleParticipants ? 'iou.split' : 'iou.request' , {
129
- amount : this . props . numberFormat (
130
- this . props . iouAmount ,
131
- { style : 'currency' , currency : this . props . iou . selectedCurrencyCode } ,
121
+ this . splitOrRequestOptions = [ {
122
+ text : props . translate ( props . hasMultipleParticipants ? 'iou.split' : 'iou.request' , {
123
+ amount : props . numberFormat (
124
+ props . iouAmount ,
125
+ { style : 'currency' , currency : props . iou . selectedCurrencyCode } ,
132
126
) ,
133
127
} ) ,
134
- } ;
135
- if ( this . props . iouType === CONST . IOU . IOU_TYPE . SEND && this . props . participants . length === 1 && Permissions . canUseIOUSend ( this . props . betas ) ) {
136
- // Add the Expensify Wallet option if available and make it the first option
137
- if ( this . props . localCurrencyCode === CONST . CURRENCY . USD && Permissions . canUsePayWithExpensify ( this . props . betas ) && Permissions . canUseWallet ( this . props . betas ) ) {
138
- confirmationButtonOptions . push ( { text : this . props . translate ( 'iou.settleExpensify' ) , icon : Expensicons . Wallet } ) ;
139
- }
140
-
141
- // Add PayPal option
142
- if ( this . props . participants [ 0 ] . payPalMeAddress ) {
143
- confirmationButtonOptions . push ( { text : this . props . translate ( 'iou.settlePaypalMe' ) , icon : Expensicons . PayPal } ) ;
144
- }
145
- defaultButtonOption = { text : this . props . translate ( 'iou.settleElsewhere' ) , icon : Expensicons . Cash } ;
146
- }
147
- confirmationButtonOptions . push ( defaultButtonOption ) ;
148
-
149
- this . checkVenmoAvailabilityPromise = null ;
128
+ } ] ;
150
129
151
130
this . state = {
152
- confirmationButtonOptions,
153
131
participants : formattedParticipants ,
154
132
} ;
155
133
@@ -161,22 +139,6 @@ class IOUConfirmationList extends Component {
161
139
// We need to wait for the transition animation to end before focusing the TextInput,
162
140
// otherwise the TextInput isn't animated correctly
163
141
setTimeout ( ( ) => this . textInput . focus ( ) , CONST . ANIMATED_TRANSITION ) ;
164
-
165
- // Only add the Venmo option if we're sending a payment
166
- if ( this . props . iouType !== CONST . IOU . IOU_TYPE . SEND ) {
167
- return ;
168
- }
169
-
170
- this . addVenmoPaymentOptionToMenu ( ) ;
171
- }
172
-
173
- componentWillUnmount ( ) {
174
- if ( ! this . checkVenmoAvailabilityPromise ) {
175
- return ;
176
- }
177
-
178
- this . checkVenmoAvailabilityPromise . cancel ( ) ;
179
- this . checkVenmoAvailabilityPromise = null ;
180
142
}
181
143
182
144
/**
@@ -329,31 +291,6 @@ class IOUConfirmationList extends Component {
329
291
] ;
330
292
}
331
293
332
- /**
333
- * Adds Venmo, if available, as the second option in the menu of payment options
334
- */
335
- addVenmoPaymentOptionToMenu ( ) {
336
- if ( this . props . localCurrencyCode !== CONST . CURRENCY . USD || ! this . state . participants [ 0 ] . phoneNumber || ! ValidationUtils . isValidUSPhone ( this . state . participants [ 0 ] . phoneNumber ) ) {
337
- return ;
338
- }
339
-
340
- this . checkVenmoAvailabilityPromise = makeCancellablePromise ( isAppInstalled ( 'venmo' ) ) ;
341
- this . checkVenmoAvailabilityPromise
342
- . promise
343
- . then ( ( isVenmoInstalled ) => {
344
- if ( ! isVenmoInstalled ) {
345
- return ;
346
- }
347
-
348
- this . setState ( prevState => ( {
349
- confirmationButtonOptions : [ ...prevState . confirmationButtonOptions . slice ( 0 , 1 ) ,
350
- { text : this . props . translate ( 'iou.settleVenmo' ) , icon : Expensicons . Venmo } ,
351
- ...prevState . confirmationButtonOptions . slice ( 1 ) ,
352
- ] ,
353
- } ) ) ;
354
- } ) ;
355
- }
356
-
357
294
/**
358
295
* Calculates the amount per user given a list of participants
359
296
* @param {Array } participants
@@ -403,6 +340,10 @@ class IOUConfirmationList extends Component {
403
340
const hoverStyle = this . props . hasMultipleParticipants ? styles . hoveredComponentBG : { } ;
404
341
const toggleOption = this . props . hasMultipleParticipants ? this . toggleOption : undefined ;
405
342
const selectedParticipants = this . getSelectedParticipants ( ) ;
343
+ const shouldShowSettlementButton = this . props . iouType === CONST . IOU . IOU_TYPE . SEND ;
344
+ const shouldDisableButton = selectedParticipants . length === 0 || this . props . network . isOffline ;
345
+ const isLoading = this . props . iou . loading && ! this . props . network . isOffline ;
346
+ const recipient = this . state . participants [ 0 ] ;
406
347
return (
407
348
< >
408
349
< ScrollView style = { [ styles . flexGrow0 , styles . flexShrink1 , styles . flexBasisAuto , styles . w100 ] } >
@@ -435,12 +376,23 @@ class IOUConfirmationList extends Component {
435
376
{ this . props . translate ( 'session.offlineMessage' ) }
436
377
</ ExpensifyText >
437
378
) }
438
- < ButtonWithMenu
439
- options = { this . state . confirmationButtonOptions }
440
- isDisabled = { selectedParticipants . length === 0 || this . props . network . isOffline }
441
- isLoading = { this . props . iou . loading && ! this . props . network . isOffline }
442
- onPress = { this . onPress }
443
- />
379
+ { shouldShowSettlementButton ? (
380
+ < SettlementButton
381
+ isDisabled = { shouldDisableButton }
382
+ isLoading = { this . props . iou . loading && ! this . props . network . isOffline }
383
+ onPress = { this . onPress }
384
+ shouldShowPaypal = { Boolean ( recipient . payPalMeAddress ) }
385
+ recipientPhoneNumber = { recipient . phoneNumber }
386
+ currency = { this . props . localCurrencyCode }
387
+ />
388
+ ) : (
389
+ < ButtonWithMenu
390
+ isDisabled = { shouldDisableButton }
391
+ isLoading = { isLoading }
392
+ onPress = { this . onPress }
393
+ options = { this . splitOrRequestOptions }
394
+ />
395
+ ) }
444
396
</ FixedFooter >
445
397
</ >
446
398
) ;
0 commit comments