跳至主要内容

OneForexPoolCard

OneForexPoolCard 是一个 React Native 组件,用于渲染一张卡片,显示单个外汇流动性池的关键统计信息 -- 总锁仓量 (TVL)、年化收益率 (APY) 和利用率。

仅限 React Native

OneForexPoolCard@one_deploy/sdk/react-native 导出。不适用于 Web 平台。

快速入门

import { OneForexPoolCard } from '@one_deploy/sdk/react-native';
import { useForexPools } from '@one_deploy/sdk';

function PoolCards() {
const { pools } = useForexPools();

return (
<>
{pools.map((pool) => (
<OneForexPoolCard
key={pool.id}
pool={pool}
onPress={() => console.log('Selected pool:', pool.id)}
/>
))}
</>
);
}

OneForexPoolCardProps

import type { OneForexPoolCardProps } from '@one_deploy/sdk';

interface OneForexPoolCardProps {
/** The forex pool data to display. */
pool: ForexPool;

/** Callback fired when the card is pressed. */
onPress?: (pool: ForexPool) => void;

/** Whether to show the utilization progress bar. Defaults to true. */
showUtilization?: boolean;

/** Whether to show the APY value. Defaults to true. */
showApy?: boolean;

/** Whether to show the TVL value. Defaults to true. */
showTvl?: boolean;

/** Format for displaying the TVL value. */
tvlFormat?: 'full' | 'abbreviated';

/** Number of decimal places for APY display. Defaults to 2. */
apyDecimals?: number;

/** Visual theme variant. */
theme?: 'dark' | 'light';

/** Custom styles applied to the card container. */
style?: import('react-native').ViewStyle;

/** Custom styles applied to the card title. */
titleStyle?: import('react-native').TextStyle;

/** Custom styles applied to metric values. */
valueStyle?: import('react-native').TextStyle;

/** Custom styles applied to metric labels. */
labelStyle?: import('react-native').TextStyle;

/** Test ID for testing frameworks. */
testID?: string;
}

属性参考

属性类型默认值说明
poolForexPool必填来自 useForexPools 的池数据对象。
onPress(pool: ForexPool) => voidundefined卡片被点击时的回调。
showUtilizationbooleantrue显示利用率进度条。
showApybooleantrue显示 APY 指标。
showTvlbooleantrue显示 TVL 指标。
tvlFormat'full' | 'abbreviated''abbreviated''full' = $2,500,000'abbreviated' = $2.5M
apyDecimalsnumber2APY 百分比显示的小数位数。
theme'dark' | 'light''dark'视觉主题。
styleViewStyleundefined自定义容器样式。
titleStyleTextStyleundefined自定义标题文本样式。
valueStyleTextStyleundefined自定义指标值样式。
labelStyleTextStyleundefined自定义指标标签样式。
testIDstringundefined用于测试框架的测试 ID。

使用示例

默认外观

import { OneForexPoolCard } from '@one_deploy/sdk/react-native';
import { useForexPools } from '@one_deploy/sdk';

function DefaultPoolCards() {
const { pools } = useForexPools();

return (
<View style={{ padding: 16, gap: 12 }}>
{pools.map((pool) => (
<OneForexPoolCard key={pool.id} pool={pool} />
))}
</View>
);
}

带导航的点击事件

import { OneForexPoolCard } from '@one_deploy/sdk/react-native';
import { useForexPools } from '@one_deploy/sdk';
import { useNavigation } from '@react-navigation/native';

function PoolListScreen() {
const { pools, isLoading } = useForexPools();
const navigation = useNavigation();

if (isLoading) return <ActivityIndicator />;

return (
<ScrollView style={{ padding: 16 }}>
{pools.map((pool) => (
<OneForexPoolCard
key={pool.id}
pool={pool}
tvlFormat="full"
apyDecimals={3}
onPress={(p) => {
navigation.navigate('PoolDetail', { poolId: p.id });
}}
style={{ marginBottom: 12 }}
/>
))}
</ScrollView>
);
}

仅显示 TVL 的卡片

import { OneForexPoolCard } from '@one_deploy/sdk/react-native';

function TvlOnlyCard({ pool }: { pool: ForexPool }) {
return (
<OneForexPoolCard
pool={pool}
showTvl={true}
showApy={false}
showUtilization={false}
tvlFormat="full"
/>
);
}

自定义样式卡片

import { OneForexPoolCard } from '@one_deploy/sdk/react-native';

function CustomStyledCard({ pool }: { pool: ForexPool }) {
return (
<OneForexPoolCard
pool={pool}
theme="dark"
style={{
backgroundColor: '#1e1e3a',
borderRadius: 16,
borderWidth: 1,
borderColor: '#3a3a6e',
padding: 20,
}}
titleStyle={{
fontSize: 18,
color: '#ffffff',
}}
valueStyle={{
fontSize: 22,
fontWeight: '800',
color: '#44cc88',
}}
labelStyle={{
fontSize: 11,
color: '#8888bb',
textTransform: 'uppercase',
letterSpacing: 1,
}}
/>
);
}

浅色主题

import { OneForexPoolCard } from '@one_deploy/sdk/react-native';

function LightPoolCard({ pool }: { pool: ForexPool }) {
return (
<OneForexPoolCard
pool={pool}
theme="light"
style={{
backgroundColor: '#ffffff',
shadowColor: '#000',
shadowOpacity: 0.08,
shadowRadius: 12,
elevation: 3,
}}
/>
);
}

下一步