UNPKG

react-native-wagmi-charts

Version:

A sweet candlestick chart for React Native

48 lines (46 loc) 1.34 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true, }); exports.useLineChartPrice = useLineChartPrice; var _reactNativeReanimated = require('react-native-reanimated'); var _utils = require('../../utils'); var _useLineChart = require('./useLineChart'); function useLineChartPrice({ format, precision = 2, index } = {}) { const { currentIndex, data } = (0, _useLineChart.useLineChart)(); const float = (0, _reactNativeReanimated.useDerivedValue)(() => { if (!data) { return ''; } if ( (typeof currentIndex.value === 'undefined' || currentIndex.value === -1) && index == null ) { return ''; } const dataPoint = data[Math.min(index ?? currentIndex.value, data.length - 1)]; const price = dataPoint?.value ?? 0; return price.toFixed(precision).toString(); }, [currentIndex, data, precision]); const formatted = (0, _reactNativeReanimated.useDerivedValue)(() => { const value = float.value || ''; const formattedPrice = value ? (0, _utils.formatPrice)({ value, }) : ''; return format ? format({ value, formatted: formattedPrice, }) : formattedPrice; }, [float, format]); return { value: float, formatted, }; } //# sourceMappingURL=usePrice.js.map