Skip to content

Commit 0f3b0b4

Browse files
committed
fix: build
1 parent 9ee63a8 commit 0f3b0b4

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

install_charting_library.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,20 @@ cp -r "$LATEST_HASH/charting_library" src/utils/
2424
cp -r "$LATEST_HASH/datafeeds" public/
2525
cp -r "$LATEST_HASH/datafeeds" src/utils/
2626

27+
# Create index.js to export widget for Next.js compatibility
28+
cat > "src/utils/charting_library/index.js" << 'JSEOF'
29+
// The charting library is loaded via a UMD bundle that attaches to window.TradingView
30+
// We provide a stub that resolves to the actual widget at runtime
31+
export const widget = (typeof window !== 'undefined' && typeof window.TradingView !== 'undefined')
32+
? window.TradingView.widget
33+
: class MockWidget {}
34+
JSEOF
35+
36+
# Create index.d.ts to re-export types
37+
cat > "src/utils/charting_library/index.d.ts" << 'DTSEOF'
38+
// Re-export all types from the charting library
39+
export * from './charting_library.d'
40+
export * from './datafeed-api.d'
41+
DTSEOF
42+
2743
remove_if_directory_exists "$LATEST_HASH"

next.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ const nextConfig = {
105105
use: ['@svgr/webpack'],
106106
})
107107

108+
// Handle charting library - it's a UMD bundle that needs special treatment
109+
config.resolve.alias = {
110+
...config.resolve.alias,
111+
// Ensure the charting library is resolved correctly
112+
'utils/charting_library': require.resolve('./src/utils/charting_library/index.js'),
113+
}
114+
108115
return config
109116
},
110117
}

src/pages/TradePage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { useEffect, useMemo } from 'react'
22
import { useLocation } from 'react-router-dom'
3+
import dynamic from 'next/dynamic'
34

45
import GridWithSplitters from 'components/common/Grid/GridWithSplitters'
56
import AccountDetailsCard from 'components/trade/AccountDetailsCard'
6-
import TradeChart from 'components/trade/TradeChart'
77
import TradeModule from 'components/trade/TradeModule'
8+
9+
// TradeChart uses the charting library which is browser-only, so we load it dynamically
10+
const TradeChart = dynamic(() => import('components/trade/TradeChart'), { ssr: false })
811
import { getDefaultChainSettings } from 'constants/defaultSettings'
912
import { LocalStorageKeys } from 'constants/localStorageKeys'
1013
import useTradeEnabledAssets from 'hooks/assets/useTradeEnabledAssets'

0 commit comments

Comments
 (0)