forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor BankIcons nad PaymentMethodList
- Loading branch information
1 parent
0deaafd
commit 3dc4373
Showing
4 changed files
with
118 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import GenericBank from '@assets/images/bankicons/generic-bank-account.svg'; | ||
import GenericBankCard from '@assets/images/cardicons/generic-bank-card.svg'; | ||
import {BankIconParams, getBankIconAsset, getBankNameKey} from '@components/Icon/BankIconsUtils'; | ||
import variables from '@styles/variables'; | ||
import CONST from '@src/CONST'; | ||
import {BankIcon} from '@src/types/onyx/Bank'; | ||
|
||
/** | ||
* Returns Bank Icon Object that matches to existing bank icons or default icons | ||
*/ | ||
export default function getBankIcon({styles, bankName, isCard = false}: BankIconParams): BankIcon { | ||
const bankIcon: BankIcon = { | ||
icon: isCard ? GenericBankCard : GenericBank, | ||
}; | ||
if (bankName) { | ||
const bankNameKey = getBankNameKey(bankName.toLowerCase()); | ||
|
||
if (bankNameKey && Object.keys(CONST.BANK_NAMES).includes(bankNameKey)) { | ||
bankIcon.icon = getBankIconAsset(bankNameKey, isCard); | ||
} | ||
} | ||
|
||
// For default Credit Card icon the icon size should not be set. | ||
if (!isCard) { | ||
bankIcon.iconSize = variables.iconSizeExtraLarge; | ||
bankIcon.iconStyles = [styles.bankIconContainer]; | ||
} else { | ||
bankIcon.iconHeight = variables.bankCardHeight; | ||
bankIcon.iconWidth = variables.bankCardWidth; | ||
bankIcon.iconStyles = [styles.assignedCardsIconContainer]; | ||
} | ||
|
||
return bankIcon; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import GenericBank from '@assets/images/bankicons/generic-bank-account.svg'; | ||
import GenericBankCard from '@assets/images/cardicons/generic-bank-card.svg'; | ||
import {BankIconParams, getBankIconAsset, getBankNameKey} from '@components/Icon/BankIconsUtils'; | ||
import variables from '@styles/variables'; | ||
import CONST from '@src/CONST'; | ||
import {BankIcon} from '@src/types/onyx/Bank'; | ||
import IconAsset from '@src/types/utils/IconAsset'; | ||
|
||
/** | ||
* It's a wrapper type for a bank icon asset. Bank icons are imported using require(), on the web platform after importing in this way it's necessary to use the property "default" | ||
*/ | ||
type BankIconAsset = { | ||
default: IconAsset; | ||
}; | ||
|
||
/** | ||
* Returns Bank Icon Object that matches to existing bank icons or default icons | ||
*/ | ||
export default function getBankIcon({styles, bankName, isCard = false}: BankIconParams): BankIcon { | ||
const bankIcon: BankIcon = { | ||
icon: isCard ? GenericBankCard : GenericBank, | ||
}; | ||
if (bankName) { | ||
const bankNameKey = getBankNameKey(bankName.toLowerCase()); | ||
|
||
if (bankNameKey && Object.keys(CONST.BANK_NAMES).includes(bankNameKey)) { | ||
bankIcon.icon = (getBankIconAsset(bankNameKey, isCard) as BankIconAsset).default; | ||
} | ||
} | ||
|
||
// For default Credit Card icon the icon size should not be set. | ||
if (!isCard) { | ||
bankIcon.iconSize = variables.iconSizeExtraLarge; | ||
bankIcon.iconStyles = [styles.bankIconContainer]; | ||
} else { | ||
bankIcon.iconHeight = variables.bankCardHeight; | ||
bankIcon.iconWidth = variables.bankCardWidth; | ||
bankIcon.iconStyles = [styles.assignedCardsIconContainer]; | ||
} | ||
|
||
return bankIcon; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters