Crypto Switcher
Bidirectional amount input
Edit either the pay or receive field; the opposite amount updates live from the current quote.
Spring-physics card swap
Pay/receive cards animate past each other with an in-flight guard plus a disabled swap button so rapid taps never corrupt state.
Live prices, injectable source
Fetches USD prices from the CoinGecko simple price API out of the box with a 15-minute cache, or skip the network by passing prices or a custom fetcher.
Animated light/dark theme
Every surface and text crossfades on the UI thread against one shared progress value, with USD valuations shown under each amount.
Installation
Copy the command directly into your project.
npx degit ManasCodeXart/ZAYX/components/crypto-switch components/crypto-switch
Install the needed dependencies
npx expo install react-native-reanimated react-native-worklets react-native-svg expo-image
Use in your app
Built to match the preview exactly — for the complete implementation, check the repo on GitHub.
import { CryptoSwitch } from "../../components/crypto-switch/components/CryptoSwitch";
export function index() {
return (
<CryptoSwitch
onCoinChange={(from, to) => console.log(from.symbol, '→', to.symbol)}
onSend={(details) => console.log('Send', details)}
/>
);
}
export default indexAPI
<CryptoSwitch>
| Prop | Type | Default | Description |
|---|---|---|---|
| coins | readonly Coin[] | built-in list | The coin list shown in both pickers. |
| defaultFromCoin | Coin | BTC | Coin shown in the pay card on first render. Falls back to coins[0]. |
| defaultToCoin | Coin | ETH | Coin shown in the receive card on first render. Falls back to coins[0]. |
| defaultSendAmount | string | "1" | Amount pre-filled in the pay field on first render. |
| spread | number | 0.003 | Fraction taken off the quote (0.003 = 0.3%). Applied to the effective rate and receive-side USD value. Same-coin pairs quote at 1 with no spread on the rate. |
| prices | Readonly<Record<string, number>> | — | Pass explicit USD prices keyed by symbol to skip the internal CoinGecko fetch for those symbols. |
| swapIcon | ReactNode | built-in ThemedSwapIcon | Replace the swap button icon with any node. Also forwarded into the picker. |
| style | StyleProp<ViewStyle> | — | Additional styles applied to the root container. |
| theme | "light" | "dark" | — | Controlled theme. Omit for uncontrolled (starts light, toggles internally). |
| onAmountChange | (amount: string) => void | — | Fires on every keystroke with the implied send-side amount as a string. |
| onCoinChange | (from: Coin, to: Coin) => void | — | Fires when either coin is changed or the cards are swapped. |
| onSend | (details: { amount: number; from: Coin; to: Coin }) => void | — | Fires on Send tap with the current send amount and both coins. |
| onThemeChange | (theme: ThemeName) => void | — | Fires on theme toggle with the next theme. |
<CoinPicker>
| Prop | Type | Default | Description |
|---|---|---|---|
| target | "from" | "to" | — | Which card opened the picker. Drives the header title when used inside the switcher. |
| title | string | — | Header title shown above the list. |
| bounds | CardBounds | — | Measured heights of the two cards, used to anchor the morph animation. |
| selectedSymbol | string | — | The currently selected coin symbol. Highlighted in the list. |
| coins | readonly Coin[] | — | The full list to render. |
| swapIcon | ReactNode | built-in icon | Icon rendered in the center during the morph. |
| veil | QuoteVeil | — | Preformatted quote strings shown greyed on the morph halves while they spring back. |
| themeProgress | SharedValue<number> | — | Shared 0 (light) → 1 (dark) progress driving the themed styles. |
| onSelect | (coin: Coin) => void | — | Fired once per selection; double-select is guarded internally. |
| onClose | () => void | — | Fired after the exit morph settles. |
useCryptoPrice
const { priceUsd, isLoading, error, refresh } = useCryptoPrice(symbol, options);| Option | Type | Default | Description |
|---|---|---|---|
| fetcher | CryptoPriceFetcher | CoinGecko | Any (symbol) => Promise<number> function. |
| cacheTtlMs | number | 900000 (15 min) | How long a cached price is considered fresh before the next mount triggers a refetch. |
| enabled | boolean | true | Set to false to skip fetching entirely — used internally when a prices override is provided. |
Types
interface Coin {
readonly symbol: string;
readonly name: string;
readonly coingeckoId: string; // CoinGecko id used for price lookup
}
type CryptoPriceFetcher = (symbol: string) => Promise<number>;
interface CardBounds {
readonly topHeight: number;
readonly bottomHeight: number;
readonly unionHeight: number;
}
interface QuoteVeil {
readonly sendAmount: string;
readonly receiveAmount: string;
readonly payUsd: string;
readonly receiveUsd: string;
}
type ThemeName = "light" | "dark";Project Structure
crypto-switch/
├── components/
│ ├── CryptoSwitch.tsx # Root component — pay/receive cards, swap, and theme orchestration
│ ├── CoinPicker.tsx # Morph-transition coin list
│ ├── CoinPill.tsx # Icon + symbol pill that opens the picker
│ ├── CoinRow.tsx # Icon + symbol + name selection row
│ ├── SwapIcon.tsx # Bidirectional swap arrow icon
│ └── ThemeToggleIcon.tsx # Light/dark toggle icon
├── hooks/
│ ├── useCryptoPrice.ts # Price fetch, cache, and stale-request cancellation
│ ├── useQuote.ts # Quote and USD valuation computation
│ ├── useCardSwap.ts # Spring-physics card swap
│ ├── useAnimatedTheme.ts # Shared light/dark theme progress
│ └── useAmountDisplay.ts # Amount display and adaptive sizing
├── constants/
│ ├── coins.ts # Built-in coin list
│ ├── types.ts # Coin, CardBounds, QuoteVeil, and switcher prop types
│ ├── theme.ts # Light/dark theme tokens
│ └── scaling.ts # verticalScale helpers
├── providers/
│ └── coingecko.ts # Default CoinGecko price fetcher
└── utils/
├── amount.ts # Amount formatting and locale handling
├── coins.ts # Coin list helpers
└── coinIcon.ts # Coin icon URL helpers