OnePairSelector
OnePairSelector 组件渲染一个可选择的交易对列表,按策略和链进行筛选。每个交易对都显示其图标(通过 PAIR_ICONS)、符号和订单大小限制。
仅限 React Native
OnePairSelector 从 @one_deploy/sdk 的 React Native 入口导出。不适用于 Web 平台。
快速入门
import { useState } from 'react';
import { OnePairSelector } from '@one_deploy/sdk';
import type { TradingPair } from '@one_deploy/sdk';
function PairStep() {
const [selectedPair, setSelectedPair] = useState<TradingPair | null>(null);
return (
<OnePairSelector
strategyId="strat_abc123"
chainId={8453}
onSelect={(pair) => {
setSelectedPair(pair);
console.log('Selected:', pair.symbol);
}}
/>
);
}
OnePairSelectorProps
interface OnePairSelectorProps {
/** Strategy ID to filter pairs by the strategy's supported pairs. */
strategyId: string;
/** Chain ID to filter pairs available on this network. */
chainId: number;
/** Currently selected pair symbol. */
selectedPair?: string;
/** Callback fired when the user selects a pair. */
onSelect: (pair: TradingPair) => void;
/** Whether to show pair icons from PAIR_ICONS. Defaults to true. */
showIcons?: boolean;
/** Whether to show inactive pairs (greyed out, not selectable). Defaults to false. */
showInactive?: boolean;
/** Additional style applied to the container. */
style?: ViewStyle;
/** Style applied to each pair item. */
itemStyle?: ViewStyle;
/** Test ID for testing frameworks. */
testID?: string;
}
属性表
| 属性 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
strategyId | string | 是 | -- | 用于筛选支持交易对的策略 ID |
chainId | number | 是 | -- | 用于筛选链上可用交易对的链 ID |
selectedPair | string | 否 | -- | 当前选中的交易对符号 |
onSelect | (pair: TradingPair) => void | 是 | -- | 选择回调 |
showIcons | boolean | 否 | true | 显示来自 PAIR_ICONS 的图标 |
showInactive | boolean | 否 | false | 显示灰色的非 活跃交易对 |
style | ViewStyle | 否 | -- | 容器样式 |
itemStyle | ViewStyle | 否 | -- | 单个项目样式 |
testID | string | 否 | -- | 测试 ID |
PAIR_ICONS 常量
PAIR_ICONS 常量将资产符号映射到其图标 URI。
import { PAIR_ICONS } from '@one_deploy/sdk';
// PAIR_ICONS: Record<string, string>
console.log(PAIR_ICONS['BTC']);
// 'https://assets.one23.io/icons/btc.png'
console.log(PAIR_ICONS['ETH']);
// 'https://assets.one23.io/icons/eth.png'
console.log(PAIR_ICONS['USDT']);
// 'https://assets.one23.io/icons/usdt.png'
console.log(PAIR_ICONS['SOL']);
// 'https://assets.one23.io/icons/sol.png'
可用图标:
| 资产 | 键名 | 说明 |
|---|---|---|
| Bitcoin | BTC | Bitcoin 图标 |
| Ethereum | ETH | Ethereum 图标 |
| Tether | USDT | Tether USD 图标 |
| USD Coin | USDC | USDC 图标 |
| Solana | SOL | Solana 图标 |
| BNB | BNB | BNB 图标 |
| Avalanche | AVAX | Avalanche 图标 |
| Polygon | MATIC | Polygon 图标 |
| Chainlink | LINK | Chainlink 图标 |
| Uniswap | UNI | Uniswap 图标 |