From d0c78b407fd8f5edfb7825bb657066818f4f7770 Mon Sep 17 00:00:00 2001 From: phivh Date: Fri, 1 Apr 2022 01:08:02 +0700 Subject: [PATCH 1/5] Fix make default payment --- src/pages/settings/Payments/PaymentMethodList.js | 2 +- .../settings/Payments/PaymentsPage/BasePaymentsPage.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/settings/Payments/PaymentMethodList.js b/src/pages/settings/Payments/PaymentMethodList.js index 9d01deefe9a6..f37ee134390c 100644 --- a/src/pages/settings/Payments/PaymentMethodList.js +++ b/src/pages/settings/Payments/PaymentMethodList.js @@ -130,7 +130,7 @@ class PaymentMethodList extends Component { combinedPaymentMethods = _.map(combinedPaymentMethods, paymentMethod => ({ ...paymentMethod, type: MENU_ITEM, - onPress: e => this.props.onPress(e, paymentMethod.accountType, paymentMethod.accountData), + onPress: e => this.props.onPress(e, paymentMethod.accountType, paymentMethod.accountData, paymentMethod.isDefault), iconFill: this.isPaymentMethodActive(paymentMethod) ? StyleUtils.getIconFillColor(CONST.BUTTON_STATES.PRESSED) : null, wrapperStyle: this.isPaymentMethodActive(paymentMethod) ? [StyleUtils.getButtonBackgroundColorStyle(CONST.BUTTON_STATES.PRESSED)] : null, })); diff --git a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js index 3afb26623110..c4028ded0917 100644 --- a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js +++ b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js @@ -40,6 +40,7 @@ class BasePaymentsPage extends React.Component { shouldShowDefaultDeleteMenu: false, shouldShowPasswordPrompt: false, shouldShowConfirmPopover: false, + isSelectedPaymentMethodDefault: true, selectedPaymentMethod: {}, formattedSelectedPaymentMethod: {}, anchorPositionTop: 0, @@ -112,8 +113,9 @@ class BasePaymentsPage extends React.Component { * @param {Object} nativeEvent * @param {String} accountType * @param {String} account + * @param {Boolean} accountDefault */ - paymentMethodPressed(nativeEvent, accountType, account) { + paymentMethodPressed(nativeEvent, accountType, account, accountDefault) { const position = getClickedElementLocation(nativeEvent); this.setState({ addPaymentMethodButton: nativeEvent, @@ -143,6 +145,7 @@ class BasePaymentsPage extends React.Component { }; } this.setState({ + isSelectedPaymentMethodDefault: !accountDefault, shouldShowDefaultDeleteMenu: true, selectedPaymentMethod: account, selectedPaymentMethodType: accountType, @@ -318,7 +321,7 @@ class BasePaymentsPage extends React.Component { interactive={false} /> )} - {Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected && ( + {this.state.isSelectedPaymentMethodDefault && Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected && ( { this.setState({ From 354bf1b054a9a22c2eb4ac7ed6fa2895ed430741 Mon Sep 17 00:00:00 2001 From: phivh Date: Sun, 3 Apr 2022 20:44:12 +0700 Subject: [PATCH 2/5] Cleanup --- .../settings/Payments/PaymentsPage/BasePaymentsPage.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js index c4028ded0917..b5693165361f 100644 --- a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js +++ b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js @@ -40,7 +40,7 @@ class BasePaymentsPage extends React.Component { shouldShowDefaultDeleteMenu: false, shouldShowPasswordPrompt: false, shouldShowConfirmPopover: false, - isSelectedPaymentMethodDefault: true, + isSelectedPaymentMethodDefault: false, selectedPaymentMethod: {}, formattedSelectedPaymentMethod: {}, anchorPositionTop: 0, @@ -113,9 +113,9 @@ class BasePaymentsPage extends React.Component { * @param {Object} nativeEvent * @param {String} accountType * @param {String} account - * @param {Boolean} accountDefault + * @param {Boolean} isDefault */ - paymentMethodPressed(nativeEvent, accountType, account, accountDefault) { + paymentMethodPressed(nativeEvent, accountType, account, isDefault) { const position = getClickedElementLocation(nativeEvent); this.setState({ addPaymentMethodButton: nativeEvent, @@ -145,7 +145,7 @@ class BasePaymentsPage extends React.Component { }; } this.setState({ - isSelectedPaymentMethodDefault: !accountDefault, + isSelectedPaymentMethodDefault: isDefault, shouldShowDefaultDeleteMenu: true, selectedPaymentMethod: account, selectedPaymentMethodType: accountType, @@ -321,7 +321,7 @@ class BasePaymentsPage extends React.Component { interactive={false} /> )} - {this.state.isSelectedPaymentMethodDefault && Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected && ( + {!this.state.isSelectedPaymentMethodDefault && Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected && ( { this.setState({ From c88e95c34086e096ba56d89be0b2d34ca5f59762 Mon Sep 17 00:00:00 2001 From: phivh Date: Tue, 5 Apr 2022 23:52:39 +0700 Subject: [PATCH 3/5] Fix spacing --- src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js index b5693165361f..3f28b1092647 100644 --- a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js +++ b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js @@ -232,6 +232,7 @@ class BasePaymentsPage extends React.Component { render() { const isPayPalMeSelected = this.state.formattedSelectedPaymentMethod.type === CONST.PAYMENT_METHODS.PAYPAL; + const isShowButtonMakeDefaultPayment = !this.state.isSelectedPaymentMethodDefault && Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected; // Determines whether or not the modal popup is mounted from the bottom of the screen instead of the side mount on Web or Desktop screens const isPopoverBottomMount = this.state.anchorPositionTop === 0 || this.props.isSmallScreenWidth; @@ -321,7 +322,7 @@ class BasePaymentsPage extends React.Component { interactive={false} /> )} - {!this.state.isSelectedPaymentMethodDefault && Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected && ( + {isShowButtonMakeDefaultPayment && ( { this.setState({ @@ -359,7 +360,7 @@ class BasePaymentsPage extends React.Component { style={[ styles.button, styles.buttonDanger, - Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected && styles.mt4, + isShowButtonMakeDefaultPayment && styles.mt4, styles.alignSelfCenter, styles.w100, ]} From 4e46f273befac3bf2752cf4d1b8fb3f8023468c5 Mon Sep 17 00:00:00 2001 From: phivh Date: Wed, 6 Apr 2022 01:06:15 +0700 Subject: [PATCH 4/5] Cleanup --- .../settings/Payments/PaymentsPage/BasePaymentsPage.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js index 3f28b1092647..c2eabd786c63 100644 --- a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js +++ b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js @@ -232,7 +232,7 @@ class BasePaymentsPage extends React.Component { render() { const isPayPalMeSelected = this.state.formattedSelectedPaymentMethod.type === CONST.PAYMENT_METHODS.PAYPAL; - const isShowButtonMakeDefaultPayment = !this.state.isSelectedPaymentMethodDefault && Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected; + const shouldShowButtonMakeDefaultPayment = !this.state.isSelectedPaymentMethodDefault && Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected; // Determines whether or not the modal popup is mounted from the bottom of the screen instead of the side mount on Web or Desktop screens const isPopoverBottomMount = this.state.anchorPositionTop === 0 || this.props.isSmallScreenWidth; @@ -322,7 +322,7 @@ class BasePaymentsPage extends React.Component { interactive={false} /> )} - {isShowButtonMakeDefaultPayment && ( + {shouldShowButtonMakeDefaultPayment && ( { this.setState({ @@ -360,7 +360,7 @@ class BasePaymentsPage extends React.Component { style={[ styles.button, styles.buttonDanger, - isShowButtonMakeDefaultPayment && styles.mt4, + shouldShowButtonMakeDefaultPayment && styles.mt4, styles.alignSelfCenter, styles.w100, ]} From e97b620ed4814d26ab2b9f1f3e64b34c7275ab6e Mon Sep 17 00:00:00 2001 From: phivh Date: Wed, 6 Apr 2022 10:02:14 +0700 Subject: [PATCH 5/5] Change naming --- .../settings/Payments/PaymentsPage/BasePaymentsPage.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js index c2eabd786c63..3417b989392b 100644 --- a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js +++ b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js @@ -232,7 +232,7 @@ class BasePaymentsPage extends React.Component { render() { const isPayPalMeSelected = this.state.formattedSelectedPaymentMethod.type === CONST.PAYMENT_METHODS.PAYPAL; - const shouldShowButtonMakeDefaultPayment = !this.state.isSelectedPaymentMethodDefault && Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected; + const shouldShowMakeDefaultButton = !this.state.isSelectedPaymentMethodDefault && Permissions.canUseWallet(this.props.betas) && !isPayPalMeSelected; // Determines whether or not the modal popup is mounted from the bottom of the screen instead of the side mount on Web or Desktop screens const isPopoverBottomMount = this.state.anchorPositionTop === 0 || this.props.isSmallScreenWidth; @@ -322,7 +322,7 @@ class BasePaymentsPage extends React.Component { interactive={false} /> )} - {shouldShowButtonMakeDefaultPayment && ( + {shouldShowMakeDefaultButton && ( { this.setState({ @@ -360,7 +360,7 @@ class BasePaymentsPage extends React.Component { style={[ styles.button, styles.buttonDanger, - shouldShowButtonMakeDefaultPayment && styles.mt4, + shouldShowMakeDefaultButton && styles.mt4, styles.alignSelfCenter, styles.w100, ]}