-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathindex.ts
43 lines (38 loc) · 1.66 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import GenericBank from '@assets/images/bankicons/generic-bank-account.svg';
import GenericBankCard from '@assets/images/cardicons/generic-bank-card.svg';
import type {BankIconParams} from '@components/Icon/BankIconsUtils';
import {getBankIconAsset, getBankNameKey} from '@components/Icon/BankIconsUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type {BankIcon} from '@src/types/onyx/Bank';
import type 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.cardIconHeight;
bankIcon.iconWidth = variables.cardIconWidth;
bankIcon.iconStyles = [styles.cardIcon];
}
return bankIcon;
}