|
| 1 | +# Payment Type Icons |
| 2 | + |
| 3 | +This document explains how to use the payment type icon mapping system for displaying appropriate icons for different payment methods in the fiat plugin system. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The payment type icon system provides a consistent way to map `FiatPaymentType` values to their corresponding theme icon keys. This ensures that payment methods are displayed with the correct visual representation across the application. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +### Basic Usage |
| 12 | + |
| 13 | +```typescript |
| 14 | +import { getPaymentTypeIcon } from '../util/paymentTypeIcons' |
| 15 | +import { useTheme } from '../services/ThemeContext' |
| 16 | + |
| 17 | +const MyComponent = () => { |
| 18 | + const theme = useTheme() |
| 19 | + const paymentType = 'applepay' // FiatPaymentType |
| 20 | + |
| 21 | + const icon = getPaymentTypeIcon(paymentType, theme) |
| 22 | + // Returns: { uri: 'path/to/apple-pay-icon.png' } |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +### Integration with PaymentOptionCard |
| 27 | + |
| 28 | +When rendering payment options from quotes, use the first payment type to determine the icon: |
| 29 | + |
| 30 | +```typescript |
| 31 | +const QuoteResult = ({ quote }) => { |
| 32 | + const theme = useTheme() |
| 33 | + |
| 34 | + // Get icon for the first payment type, fallback to partner icon |
| 35 | + const paymentTypeIcon = quote.paymentTypes[0] |
| 36 | + ? getPaymentTypeIcon(quote.paymentTypes[0], theme) |
| 37 | + : undefined |
| 38 | + const icon = paymentTypeIcon ?? { uri: quote.partnerIcon } |
| 39 | + |
| 40 | + return ( |
| 41 | + <PaymentOptionCard |
| 42 | + title={quote.paymentTypes.join(', ')} |
| 43 | + icon={icon} |
| 44 | + // ... other props |
| 45 | + /> |
| 46 | + ) |
| 47 | +} |
| 48 | +``` |
| 49 | +
|
| 50 | +## Payment Type Mappings |
| 51 | +
|
| 52 | +### Direct Mappings |
| 53 | +
|
| 54 | +These payment types have dedicated icons in the theme: |
| 55 | +
|
| 56 | +- `applepay` → `paymentTypeLogoApplePay` |
| 57 | +- `credit` → `paymentTypeLogoCreditCard` |
| 58 | +- `fasterpayments` → `paymentTypeLogoFasterPayments` |
| 59 | +- `googlepay` → `paymentTypeLogoGooglePay` |
| 60 | +- `ideal` → `paymentTypeLogoIdeal` |
| 61 | +- `interac` → `paymentTypeLogoInterac` |
| 62 | +- `payid` → `paymentTypeLogoPayid` |
| 63 | +- `paypal` → `paymentTypeLogoPaypal` |
| 64 | +- `pix` → `paymentTypeLogoPix` |
| 65 | +- `revolut` → `paymentTypeLogoRevolut` |
| 66 | +- `venmo` → `paymentTypeLogoVenmo` |
| 67 | +
|
| 68 | +### Fallback Mappings |
| 69 | +
|
| 70 | +These payment types use the generic bank transfer icon as a fallback: |
| 71 | +
|
| 72 | +- `ach` → `paymentTypeLogoBankTransfer` |
| 73 | +- `colombiabank` → `paymentTypeLogoBankTransfer` |
| 74 | +- `directtobank` → `paymentTypeLogoBankTransfer` |
| 75 | +- `iach` → `paymentTypeLogoBankTransfer` |
| 76 | +- `iobank` → `paymentTypeLogoBankTransfer` |
| 77 | +- `mexicobank` → `paymentTypeLogoBankTransfer` |
| 78 | +- `pse` → `paymentTypeLogoBankTransfer` |
| 79 | +- `sepa` → `paymentTypeLogoBankTransfer` |
| 80 | +- `spei` → `paymentTypeLogoBankTransfer` |
| 81 | +- `turkishbank` → `paymentTypeLogoBankTransfer` |
| 82 | +- `wire` → `paymentTypeLogoBankTransfer` |
| 83 | +
|
| 84 | +## API Reference |
| 85 | +
|
| 86 | +### `getPaymentTypeIcon(paymentType: FiatPaymentType, theme: Theme): ImageProp | undefined` |
| 87 | +
|
| 88 | +Returns the theme icon for a given payment type. |
| 89 | +
|
| 90 | +**Parameters:** |
| 91 | +- `paymentType`: The payment type to get the icon for |
| 92 | +- `theme`: The theme object containing the icon images |
| 93 | +
|
| 94 | +**Returns:** |
| 95 | +- `ImageProp`: The icon image object (`{ uri: string } | number`) |
| 96 | +- `undefined`: If the payment type doesn't have a corresponding icon |
| 97 | +
|
| 98 | +### `getPaymentTypeThemeKey(paymentType: FiatPaymentType): keyof Theme | null` |
| 99 | +
|
| 100 | +Returns just the theme key for a payment type without requiring the theme object. |
| 101 | +
|
| 102 | +**Parameters:** |
| 103 | +- `paymentType`: The payment type to get the theme key for |
| 104 | +
|
| 105 | +**Returns:** |
| 106 | +- `keyof Theme`: The theme key string |
| 107 | +- `null`: If the payment type doesn't have a corresponding theme key |
| 108 | +
|
| 109 | +## Adding New Payment Types |
| 110 | +
|
| 111 | +To add support for a new payment type: |
| 112 | +
|
| 113 | +1. Add the payment type to the `FiatPaymentType` union in `fiatPluginTypes.ts` |
| 114 | +2. Add the corresponding icon to the theme in `types/Theme.ts` |
| 115 | +3. Update the `paymentTypeToThemeKey` mapping in `util/paymentTypeIcons.ts` |
| 116 | +4. Add the icon assets to all theme variations (edgeLight, edgeDark, etc.) |
| 117 | +
|
| 118 | +## Notes |
| 119 | +
|
| 120 | +- Payment types that are primarily bank-based use the generic bank transfer icon as a reasonable fallback |
| 121 | +- The system is designed to be extensible - new payment types can be added without breaking existing functionality |
| 122 | +- Always provide a fallback (like the partner icon) when using payment type icons in case the mapping returns undefined |
0 commit comments