Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set default badge when only one defaultable payment method is available #7767

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions src/pages/settings/Payments/PaymentMethodList.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,30 @@ class PaymentMethodList extends Component {
}

/**
* Take all of the different payment methods and create a list that can be easily digested by renderItem
*
* @param {Boolean} isDefault
* @returns {*}
*/
getDefaultBadgeText(isDefault = false) {
if (!isDefault) {
return null;
}

const defaultablePaymentMethodCount = _.reduce(this.getFilteredPaymentMethods(), (count, method) => (
(method.accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT || method.accountType === CONST.PAYMENT_METHODS.DEBIT_CARD)
? count + 1
: count
), 0);
if (defaultablePaymentMethodCount <= 1) {
return null;
}

return this.props.translate('paymentMethodList.defaultPaymentMethod');
}

/**
* @returns {Array}
*/
createPaymentMethodList() {
getFilteredPaymentMethods() {
let combinedPaymentMethods = PaymentUtils.formatPaymentMethods(this.props.bankAccountList, this.props.cardList, this.props.payPalMeUsername, this.props.userWallet);

if (!_.isEmpty(this.props.filterType)) {
Expand All @@ -116,6 +135,17 @@ class PaymentMethodList extends Component {
wrapperStyle: this.isPaymentMethodActive(paymentMethod) ? [StyleUtils.getButtonBackgroundColorStyle(CONST.BUTTON_STATES.PRESSED)] : null,
}));

return combinedPaymentMethods;
}

/**
* Take all of the different payment methods and create a list that can be easily digested by renderItem
*
* @returns {Array}
*/
createPaymentMethodList() {
const combinedPaymentMethods = this.getFilteredPaymentMethods();

// If we have not added any payment methods, show a default empty state
if (_.isEmpty(combinedPaymentMethods)) {
combinedPaymentMethods.push({
Expand Down Expand Up @@ -172,7 +202,7 @@ class PaymentMethodList extends Component {
iconFill={item.iconFill}
iconHeight={item.iconSize}
iconWidth={item.iconSize}
badgeText={item.isDefault ? this.props.translate('paymentMethodList.defaultPaymentMethod') : null}
badgeText={this.getDefaultBadgeText(item.isDefault)}
wrapperStyle={item.wrapperStyle}
shouldShowSelectedState={this.props.shouldShowSelectedState}
isSelected={this.props.selectedMethodID === item.methodID}
Expand Down