|
1 | | -import { useEffect, useState, Children, cloneElement } from 'react'; |
| 1 | +import { useEffect, useState } from 'react'; |
2 | 2 |
|
3 | 3 | // Constants - defined inside component for Mintlify compatibility |
4 | 4 | const NAGA_PROD_PRICE_FEED_ADDRESS = '0x88F5535Fa6dA5C225a3C06489fE4e3405b87608C'; |
@@ -189,7 +189,7 @@ export const formatPrice = (priceInTokens, priceInUSD) => { |
189 | 189 | return `${priceInTokens.toFixed(6)} LITKEY ($${priceInUSD.toFixed(6)})`; |
190 | 190 | }; |
191 | 191 |
|
192 | | -export const PriceProvider = ({ children }) => { |
| 192 | +export const PriceProvider = ({ children, component: Component }) => { |
193 | 193 | const [loading, setLoading] = useState(true); |
194 | 194 | const [error, setError] = useState(null); |
195 | 195 | const [basePrices, setBasePrices] = useState([]); |
@@ -293,17 +293,20 @@ export const PriceProvider = ({ children }) => { |
293 | 293 | ethers: window.ethers, |
294 | 294 | }; |
295 | 295 |
|
296 | | - // Clone children and pass price data as props |
297 | | - // Handle both single child and multiple children |
298 | | - if (!children) { |
| 296 | + // Render the component with price data as a prop |
| 297 | + // Prefer component prop, fall back to children if provided |
| 298 | + const ComponentToRender = Component || (children && typeof children === 'function' ? children : null); |
| 299 | + |
| 300 | + if (!ComponentToRender) { |
299 | 301 | return null; |
300 | 302 | } |
301 | 303 |
|
302 | | - return Children.map(children, (child) => { |
303 | | - if (child && typeof child === 'object' && 'type' in child && typeof child.type !== 'string') { |
304 | | - return cloneElement(child, { priceData }); |
305 | | - } |
306 | | - return child; |
307 | | - }); |
| 304 | + // Render the component with priceData prop |
| 305 | + if (typeof ComponentToRender === 'function') { |
| 306 | + return <ComponentToRender priceData={priceData} />; |
| 307 | + } |
| 308 | + |
| 309 | + // If children is a React element, try to render it (shouldn't happen with our usage pattern) |
| 310 | + return children; |
308 | 311 | }; |
309 | 312 |
|
0 commit comments