Skip to content

Commit 52a905d

Browse files
authored
fix script detection after page refresh (#1856)
1 parent 0422232 commit 52a905d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/app/leverage/components/trading-view-chart.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Button } from '@headlessui/react'
22
import { useAppKit } from '@reown/appkit/react'
33
import Script from 'next/script'
4-
import { useState } from 'react'
4+
import { useEffect, useState } from 'react'
55

66
import { TradingViewChartContainer } from '@/app/leverage/components/trading-view-chart-container'
77
import { useWallet } from '@/lib/hooks/use-wallet'
@@ -10,6 +10,17 @@ export function TradingViewChart() {
1010
const [isScriptReady, setIsScriptReady] = useState(false)
1111
const { isConnected } = useWallet()
1212
const { open } = useAppKit()
13+
14+
useEffect(() => {
15+
const scriptAlreadyLoaded = document.querySelector(
16+
'script[src="/tradingview-chart/datafeeds/udf/dist/bundle.js"]',
17+
)
18+
19+
if (scriptAlreadyLoaded) {
20+
setIsScriptReady(true)
21+
}
22+
}, [])
23+
1324
return (
1425
<div className='xs:h-[422px] relative aspect-square w-full lg:aspect-auto'>
1526
<Script

0 commit comments

Comments
 (0)