|
| 1 | +import React from 'react' |
| 2 | +import { Icons, Image, useTheme, View } from '@avalabs/k2-alpine' |
| 3 | +import { SvgProps } from 'react-native-svg' |
| 4 | +import { PaymentMethods } from '../consts' |
| 5 | +import { SearchPaymentMethods } from '../types' |
| 6 | + |
| 7 | +const DEFAULT_SIZE = 24 |
| 8 | + |
| 9 | +export const PaymentMethodIcon = ({ |
| 10 | + paymentMethod, |
| 11 | + size = DEFAULT_SIZE |
| 12 | +}: { |
| 13 | + paymentMethod: SearchPaymentMethods |
| 14 | + size?: number |
| 15 | +}): React.JSX.Element | undefined => { |
| 16 | + const { |
| 17 | + theme: { colors, isDark } |
| 18 | + } = useTheme() |
| 19 | + const Icon = paymentMethod.paymentMethod |
| 20 | + ? PAYMENT_METHOD_TO_ICON[paymentMethod.paymentMethod] |
| 21 | + : undefined |
| 22 | + return Icon ? ( |
| 23 | + <View |
| 24 | + sx={{ |
| 25 | + width: size, |
| 26 | + height: size, |
| 27 | + justifyContent: 'center', |
| 28 | + alignItems: 'center' |
| 29 | + }}> |
| 30 | + <Icon |
| 31 | + testID={`icon__${paymentMethod.paymentMethod}`} |
| 32 | + width={size} |
| 33 | + height={size} |
| 34 | + color={colors.$textPrimary} |
| 35 | + /> |
| 36 | + </View> |
| 37 | + ) : ( |
| 38 | + <Image |
| 39 | + accessibilityRole="image" |
| 40 | + sx={{ width: size, height: size }} |
| 41 | + source={{ |
| 42 | + uri: isDark |
| 43 | + ? paymentMethod?.logos?.dark ?? '' |
| 44 | + : paymentMethod?.logos?.light ?? '' |
| 45 | + }} |
| 46 | + /> |
| 47 | + ) |
| 48 | +} |
| 49 | + |
| 50 | +const PAYMENT_METHOD_TO_ICON: Record< |
| 51 | + PaymentMethods, |
| 52 | + React.FC<SvgProps> | undefined |
| 53 | +> = { |
| 54 | + [PaymentMethods.APPLEPAY_EU]: Icons.Custom.ApplePay, |
| 55 | + [PaymentMethods.APPLE_PAY]: Icons.Custom.ApplePay, |
| 56 | + [PaymentMethods.PAYPAL]: Icons.Custom.PayPal, |
| 57 | + [PaymentMethods.CREDIT_DEBIT_CARD]: Icons.Custom.CreditCard, |
| 58 | + [PaymentMethods.GOOGLE_PAY]: Icons.Custom.GooglePay, |
| 59 | + [PaymentMethods.BINANCE_CASH_BALANCE]: Icons.Custom.Binance, |
| 60 | + [PaymentMethods.BINANCE_P2P]: Icons.Custom.Binance, |
| 61 | + [PaymentMethods.COINBASE_CASH_BALANCE]: Icons.Custom.Coinbase, |
| 62 | + [PaymentMethods.REVOLUT_PAY]: Icons.Custom.Revolut, |
| 63 | + |
| 64 | + [PaymentMethods.BR_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 65 | + [PaymentMethods.UAE_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 66 | + [PaymentMethods.VN_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 67 | + [PaymentMethods.NG_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 68 | + [PaymentMethods.TH_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 69 | + [PaymentMethods.PH_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 70 | + [PaymentMethods.PE_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 71 | + [PaymentMethods.MY_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 72 | + [PaymentMethods.MX_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 73 | + [PaymentMethods.LOCAL_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 74 | + [PaymentMethods.ID_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 75 | + [PaymentMethods.IN_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 76 | + [PaymentMethods.CO_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 77 | + [PaymentMethods.CL_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 78 | + [PaymentMethods.AR_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 79 | + [PaymentMethods.CH_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 80 | + [PaymentMethods.DE_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 81 | + [PaymentMethods.ES_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 82 | + [PaymentMethods.FR_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 83 | + [PaymentMethods.IT_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 84 | + [PaymentMethods.NL_BANK_TRANSFER]: Icons.Custom.BankTransfer, |
| 85 | + |
| 86 | + [PaymentMethods.TODITO_CASH]: Icons.Custom.Cash, |
| 87 | + [PaymentMethods.PE_CASH]: Icons.Custom.Cash, |
| 88 | + [PaymentMethods.MX_CASH]: Icons.Custom.Cash, |
| 89 | + [PaymentMethods.EC_CASH]: Icons.Custom.Cash, |
| 90 | + [PaymentMethods.CR_CASH]: Icons.Custom.Cash, |
| 91 | + [PaymentMethods.CO_CASH]: Icons.Custom.Cash, |
| 92 | + [PaymentMethods.DO_CASH]: Icons.Custom.Cash, |
| 93 | + [PaymentMethods.GT_CASH]: Icons.Custom.Cash, |
| 94 | + [PaymentMethods.HN_CASH]: Icons.Custom.Cash, |
| 95 | + [PaymentMethods.NI_CASH]: Icons.Custom.Cash, |
| 96 | + [PaymentMethods.PA_CASH]: Icons.Custom.Cash, |
| 97 | + [PaymentMethods.PH_CASH]: Icons.Custom.Cash, |
| 98 | + [PaymentMethods.PY_CASH]: Icons.Custom.Cash, |
| 99 | + |
| 100 | + // if there is no custom logo for the payment method, show the default logo provided by Meld |
| 101 | + [PaymentMethods.SPEI]: undefined, |
| 102 | + [PaymentMethods.PAYMAYA]: undefined, |
| 103 | + [PaymentMethods.GCASH]: undefined, |
| 104 | + [PaymentMethods.GRABPAY]: undefined, |
| 105 | + [PaymentMethods.THAI_QR]: undefined, |
| 106 | + [PaymentMethods.FAST]: undefined, |
| 107 | + [PaymentMethods.ROBINHOOD_BUYING_POWER]: undefined, |
| 108 | + [PaymentMethods.QRIS]: undefined, |
| 109 | + [PaymentMethods.OVO]: undefined, |
| 110 | + [PaymentMethods.UPI]: undefined, |
| 111 | + [PaymentMethods.IMPS]: undefined, |
| 112 | + [PaymentMethods.MOBILE_MONEY]: undefined, |
| 113 | + [PaymentMethods.SEPA]: undefined, |
| 114 | + [PaymentMethods.PIX]: undefined, |
| 115 | + [PaymentMethods.ACH]: undefined, |
| 116 | + [PaymentMethods.KHIPU]: undefined, |
| 117 | + [PaymentMethods.PSE]: undefined, |
| 118 | + [PaymentMethods.VIETQR]: undefined, |
| 119 | + [PaymentMethods.VIETTELPAY]: undefined, |
| 120 | + [PaymentMethods.OPEN_BANKING]: undefined, |
| 121 | + [PaymentMethods.INSTAPAY]: undefined, |
| 122 | + [PaymentMethods.ASTROPAY]: undefined, |
| 123 | + [PaymentMethods.IDEAL]: undefined, |
| 124 | + [PaymentMethods.DUITNOW]: undefined, |
| 125 | + [PaymentMethods.DANA]: undefined, |
| 126 | + [PaymentMethods.SKRILL]: undefined, |
| 127 | + [PaymentMethods.SHOPEEPAY]: undefined, |
| 128 | + [PaymentMethods.PICPAY]: undefined, |
| 129 | + [PaymentMethods.PAYID]: undefined, |
| 130 | + [PaymentMethods.BANCONTACT]: undefined, |
| 131 | + [PaymentMethods.BRIVA]: undefined, |
| 132 | + [PaymentMethods.EPS]: undefined, |
| 133 | + [PaymentMethods.COINS_PH]: undefined, |
| 134 | + [PaymentMethods.FPX]: undefined, |
| 135 | + [PaymentMethods.NETELLER]: undefined, |
| 136 | + [PaymentMethods.PAY_NOW]: undefined, |
| 137 | + [PaymentMethods.NEFT]: undefined, |
| 138 | + [PaymentMethods.MULTIBANCO]: undefined, |
| 139 | + [PaymentMethods.MOMO]: undefined, |
| 140 | + [PaymentMethods.MPESA]: undefined, |
| 141 | + [PaymentMethods.MANDIRIVA]: undefined, |
| 142 | + [PaymentMethods.SAME_DAY_ACH]: undefined, |
| 143 | + [PaymentMethods.STP]: undefined, |
| 144 | + [PaymentMethods.SOFORT]: undefined, |
| 145 | + [PaymentMethods.SWIFT]: undefined, |
| 146 | + [PaymentMethods.TOUCH_N_GO]: undefined, |
| 147 | + [PaymentMethods.UK_FASTER_PAYMENTS]: undefined, |
| 148 | + [PaymentMethods.QRPH]: undefined, |
| 149 | + [PaymentMethods.INTERAC]: undefined, |
| 150 | + [PaymentMethods.ZALOPAY]: undefined, |
| 151 | + [PaymentMethods.PROMPTPAY]: undefined, |
| 152 | + [PaymentMethods.BLIK]: undefined |
| 153 | +} |
0 commit comments