Skip to content

Commit

Permalink
fix: Intermittent tradingview crash on setup
Browse files Browse the repository at this point in the history
  • Loading branch information
memoyil committed Feb 25, 2025
1 parent 6a6acdb commit e66106b
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions apps/web/src/components/TradingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,34 @@ const initializeTradingView = (TradingViewObj: any, theme: DefaultTheme, localeC
} catch (e) {
// noop
}
/* eslint-disable new-cap */
/* eslint-disable no-new */
// @ts-ignore
return new TradingViewObj.widget({
// Advanced Chart Widget uses the legacy embedding scheme,
// an id property should be specified in the settings object
id: opts.container_id,
autosize: true,
height: '100%',
symbol: 'BINANCE:BNBBUSD',
interval: '5',
timezone,
theme: theme.isDark ? 'dark' : 'light',
style: '1',
locale: localeCode,
toolbar_bg: '#f1f3f6',
enable_publishing: false,
allow_symbol_change: true,
hide_side_toolbar: false,
enabled_features: ['header_fullscreen_button'],
...opts,
})

try {
/* eslint-disable new-cap */
/* eslint-disable no-new */
// @ts-ignore
return new TradingViewObj.widget({
// Advanced Chart Widget uses the legacy embedding scheme,
// an id property should be specified in the settings object
id: opts.container_id,
autosize: true,
height: '100%',
symbol: 'BINANCE:BNBBUSD',
interval: '5',
timezone,
theme: theme.isDark ? 'dark' : 'light',
style: '1',
locale: localeCode,
toolbar_bg: '#f1f3f6',
enable_publishing: false,
allow_symbol_change: true,
hide_side_toolbar: false,
enabled_features: ['header_fullscreen_button'],
...opts,
})
} catch (e) {
console.error('Failed to initialize TradingView widget:', e)
return undefined
}
}

interface TradingViewProps {
Expand Down

0 comments on commit e66106b

Please sign in to comment.