Skip to content

Commit

Permalink
Merge pull request Expensify#37078 from cubuspl42/remove-toSorted-1
Browse files Browse the repository at this point in the history
Remove the usage of `Array.prototype.toSorted`
  • Loading branch information
Julesssss authored Feb 22, 2024
2 parents 0f63564 + ae4d202 commit e2496b0
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/pages/settings/Wallet/PaymentMethodList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {FlashList} from '@shopify/flash-list';
import lodashSortBy from 'lodash/sortBy';
import type {ReactElement, Ref} from 'react';
import React, {useCallback, useMemo} from 'react';
import type {GestureResponderEvent, StyleProp, ViewStyle} from 'react-native';
Expand Down Expand Up @@ -190,20 +191,13 @@ function PaymentMethodList({
if (shouldShowAssignedCards) {
const assignedCards = Object.values(cardList ?? {})
// Filter by physical, active cards associated with a domain
.filter((card) => !card.isVirtual && !!card.domainName && CONST.EXPENSIFY_CARD.ACTIVE_STATES.includes(card.state ?? 0))
.toSorted((card1, card2) => {
const isExpensifyCard1 = CardUtils.isExpensifyCard(card1.cardID);
const isExpensifyCard2 = CardUtils.isExpensifyCard(card2.cardID);
if (isExpensifyCard1 === isExpensifyCard2) {
return 0;
}

return isExpensifyCard1 ? -1 : 1;
});
.filter((card) => !card.isVirtual && !!card.domainName && CONST.EXPENSIFY_CARD.ACTIVE_STATES.includes(card.state ?? 0));

const numberPhysicalExpensifyCards = assignedCards.filter((card) => CardUtils.isExpensifyCard(card.cardID)).length;

return assignedCards.map((card) => {
const assignedCardsSorted = lodashSortBy(assignedCards, (card) => !CardUtils.isExpensifyCard(card.cardID));

return assignedCardsSorted.map((card) => {
const isExpensifyCard = CardUtils.isExpensifyCard(card.cardID);
const icon = getBankIcon({bankName: card.bank as BankName, isCard: true, styles});

Expand Down

0 comments on commit e2496b0

Please sign in to comment.