@@ -17,11 +17,8 @@ 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' ;
21
+ import Log from '../libs/Log' ;
25
22
26
23
const propTypes = {
27
24
/** Callback to inform parent modal of success */
@@ -118,38 +115,21 @@ class IOUConfirmationList extends Component {
118
115
constructor ( props ) {
119
116
super ( props ) ;
120
117
121
- const formattedParticipants = _ . map ( this . getParticipantsWithAmount ( this . props . participants ) , participant => ( {
118
+ const formattedParticipants = _ . map ( this . getParticipantsWithAmount ( props . participants ) , participant => ( {
122
119
...participant , selected : true ,
123
120
} ) ) ;
124
121
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 } ,
122
+ this . splitOrRequestOptions = [ {
123
+ text : props . translate ( props . hasMultipleParticipants ? 'iou.split' : 'iou.request' , {
124
+ amount : props . numberFormat (
125
+ props . iouAmount ,
126
+ { style : 'currency' , currency : props . iou . selectedCurrencyCode } ,
132
127
) ,
133
128
} ) ,
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 ;
129
+ value : props . hasMultipleParticipants ? CONST . IOU . IOU_TYPE . SPLIT : CONST . IOU . IOU_TYPE . REQUEST ,
130
+ } ] ;
150
131
151
132
this . state = {
152
- confirmationButtonOptions,
153
133
participants : formattedParticipants ,
154
134
} ;
155
135
@@ -161,31 +141,17 @@ class IOUConfirmationList extends Component {
161
141
// We need to wait for the transition animation to end before focusing the TextInput,
162
142
// otherwise the TextInput isn't animated correctly
163
143
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
144
}
181
145
182
146
/**
183
- * When confirmation button is clicked
147
+ * @param { String } value
184
148
*/
185
- onPress ( ) {
149
+ onPress ( value ) {
186
150
if ( this . props . iouType === CONST . IOU . IOU_TYPE . SEND ) {
151
+ Log . info ( `[IOU] Sending money via: ${ value } ` ) ;
187
152
this . props . onConfirm ( ) ;
188
153
} else {
154
+ Log . info ( `[IOU] Requesting money via: ${ value } ` ) ;
189
155
this . props . onConfirm ( this . getSplits ( ) ) ;
190
156
}
191
157
}
@@ -329,31 +295,6 @@ class IOUConfirmationList extends Component {
329
295
] ;
330
296
}
331
297
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
298
/**
358
299
* Calculates the amount per user given a list of participants
359
300
* @param {Array } participants
@@ -403,6 +344,10 @@ class IOUConfirmationList extends Component {
403
344
const hoverStyle = this . props . hasMultipleParticipants ? styles . hoveredComponentBG : { } ;
404
345
const toggleOption = this . props . hasMultipleParticipants ? this . toggleOption : undefined ;
405
346
const selectedParticipants = this . getSelectedParticipants ( ) ;
347
+ const shouldShowSettlementButton = this . props . iouType === CONST . IOU . IOU_TYPE . SEND ;
348
+ const shouldDisableButton = selectedParticipants . length === 0 || this . props . network . isOffline ;
349
+ const isLoading = this . props . iou . loading && ! this . props . network . isOffline ;
350
+ const recipient = this . state . participants [ 0 ] ;
406
351
return (
407
352
< >
408
353
< ScrollView style = { [ styles . flexGrow0 , styles . flexShrink1 , styles . flexBasisAuto , styles . w100 ] } >
@@ -435,12 +380,23 @@ class IOUConfirmationList extends Component {
435
380
{ this . props . translate ( 'session.offlineMessage' ) }
436
381
</ ExpensifyText >
437
382
) }
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
- />
383
+ { shouldShowSettlementButton ? (
384
+ < SettlementButton
385
+ isDisabled = { shouldDisableButton }
386
+ isLoading = { this . props . iou . loading && ! this . props . network . isOffline }
387
+ onPress = { this . onPress }
388
+ shouldShowPaypal = { Boolean ( recipient . payPalMeAddress ) }
389
+ recipientPhoneNumber = { recipient . phoneNumber }
390
+ currency = { this . props . localCurrencyCode }
391
+ />
392
+ ) : (
393
+ < ButtonWithMenu
394
+ isDisabled = { shouldDisableButton }
395
+ isLoading = { isLoading }
396
+ onPress = { this . onPress }
397
+ options = { this . splitOrRequestOptions }
398
+ />
399
+ ) }
444
400
</ FixedFooter >
445
401
</ >
446
402
) ;
0 commit comments