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

Display 'Make default payment method' option for the first bank account without requiring a refresh after adding the second account #52971

Merged
merged 1 commit into from
Nov 26, 2024
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
15 changes: 14 additions & 1 deletion src/pages/settings/Wallet/WalletPage/WalletPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,22 @@ function WalletPage({shouldListenForResize = false}: WalletPageProps) {
}
}
}, [hideDefaultDeleteMenu, paymentMethod.methodID, paymentMethod.selectedPaymentMethodType, bankAccountList, fundList, shouldShowDefaultDeleteMenu]);
// Don't show "Make default payment method" button if it's the only payment method or if it's already the default
const isCurrentPaymentMethodDefault = () => {
const hasMultiplePaymentMethods = PaymentUtils.formatPaymentMethods(bankAccountList ?? {}, fundList ?? {}, styles).length > 1;
if (hasMultiplePaymentMethods) {
if (paymentMethod.formattedSelectedPaymentMethod.type === CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT) {
return paymentMethod.selectedPaymentMethod.bankAccountID === userWallet?.walletLinkedAccountID;
}
if (paymentMethod.formattedSelectedPaymentMethod.type === CONST.PAYMENT_METHODS.DEBIT_CARD) {
return paymentMethod.selectedPaymentMethod.fundID === userWallet?.walletLinkedAccountID;
}
}
return true;
};

const shouldShowMakeDefaultButton =
!paymentMethod.isSelectedPaymentMethodDefault &&
!isCurrentPaymentMethodDefault() &&
!(paymentMethod.formattedSelectedPaymentMethod.type === CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT && paymentMethod.selectedPaymentMethod.type === CONST.BANK_ACCOUNT.TYPE.BUSINESS);

// 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
Expand Down
Loading