Overview
TheCryptoCard component renders a touchable card that displays key information about a cryptocurrency, including its name, symbol, price, 24-hour percentage change, and market rank. When tapped, it navigates to the detailed view of that cryptocurrency.
This component is typically used within a list to display multiple cryptocurrencies, and provides visual feedback for price changes through color-coded percentage indicators.
Props
An object containing the cryptocurrency data to display. The
CryptoApiResponse interface includes:id(string): Unique identifier for the cryptocurrencyname(string): Full name of the cryptocurrency (e.g., “Bitcoin”)symbol(string): Trading symbol (e.g., “BTC”)rank(number): Market cap ranking positionprice_usd(string): Current price in USDpercent_change_24h(string): 24-hour percentage change- Additional fields:
percent_change_1h,percent_change_7d,market_cap_usd,volume24, etc.
Usage Example
Usage in a List
The component is commonly used withFlatList to render multiple cryptocurrencies:
Component Behavior
Navigation
When a user taps on the card, it navigates to the cryptocurrency detail page using the crypto’s ID:Price Change Indicator
The 24-hour percentage change is displayed with conditional styling:- Positive changes (≥ 0%): Displayed in green (
#4caf50) - Negative changes (< 0%): Displayed in red (
#ef5350) - Positive values include a
+prefix
Price Formatting
Prices are formatted using theformatToUSD utility function, which converts numeric values to US currency format:
Styling Details
Card Container
- Background: Deep blue (
#1c1c7e) - Border radius: 12px for rounded corners
- Padding: 16px on all sides
- Margin: 10px vertical spacing between cards
- Shadow: Elevated appearance with shadow and elevation properties
Text Styles
- Name & Symbol
- Price & Change
- Rank
- Name: 20px bold white text
- Symbol: 14px gray text (
#aaa) displayed in parentheses
Layout Structure
The card uses a two-row layout:- Top row: Flexbox with space-between alignment (name/symbol on left, rank on right)
- Bottom row: Flexbox with space-between alignment (price on left, change on right)
Related Components
- CryptoList: List container that renders multiple CryptoCards
- SearchBar: Search and filter cryptocurrencies
- HomeHeader: Header component that includes the SearchBar
Source Code Location
~/workspace/source/src/components/CryptoCard.tsx:21