Skip to content

Commit

Permalink
Added Trading View Top Stories Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Sep 25, 2024
1 parent 50da540 commit 1fb81fd
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 6 deletions.
40 changes: 38 additions & 2 deletions directory/sail.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"description": "Displays a chart of a given stock, using the TradingView applications",
"type": "web",
"details": {
"url": "/static/example-apps/tradingview/chart.html"
"url": "/static/example-apps/tradingview/chart/chart.html"
},
"screenshots": [
{
"src": "/static/example-apps/tradingview/chart.png",
"src": "/static/example-apps/tradingview/chart/chart.png",
"label": "Demo Screenshot"
}
],
Expand All @@ -36,6 +36,42 @@
}
}
},
{
"appId": "trading-view-news-1",
"name": "Top Stories",
"title": "Top Stories",
"description": "Help your audience keep track of what's happening in the crypto and stock markets with our daily news briefs – designed to be read in 20 seconds or less.",
"type": "web",
"details": {
"url": "/static/example-apps/tradingview/top-stories/top-stories.html"
},
"screenshots": [
{
"src": "/static/example-apps/tradingview/top-stories/top-stories.png",
"label": "Demo Screenshot"
}
],
"hostManifests": {},
"version": "1.0.0",
"publisher": "FINOS",
"icons": [
{
"src": "/static/example-apps/tradingview/tradingview-icon.png"
}
],
"interop": {
"intents": {
"listensFor": {
"ViewNews": {
"contexts": [
"fdc3.instrument"
],
"displayName": "View News"
}
}
}
}
},
{
"appId": "workbench",
"name": "FDC3 Workbench",
Expand Down
6 changes: 3 additions & 3 deletions fdc3-workbench/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
73 changes: 73 additions & 0 deletions src/example-apps/tradingview/top-stories/TradingViewWidget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// TradingViewWidget.jsx
import { getAgent } from "@kite9/fdc3"
import { useEffect, useRef, memo, useState } from "react"

export const TradingViewWidget = () => {
const container: any = useRef()

const [state, setState] = useState("MSFT")

useEffect(() => {
getAgent().then((fdc3) => {
fdc3.addIntentListener("ViewChart", async (context) => {
setState(context?.id?.ticker)
})

fdc3.addContextListener("fdc3.instrument", async (context) => {
setState(context?.id?.ticker)
})
})
}, [])

useEffect(() => {
var script: HTMLScriptElement | null = null

script = document.getElementById(
"tradingview-widget-script",
) as HTMLScriptElement

if (script) {
container.current.removeChild(script)
}

script = document.createElement("script")
container.current.appendChild(script)

script!!.id = "tradingview-widget-script"
script.src =
"https://s3.tradingview.com/external-embedding/embed-widget-timeline.js"
script.type = "text/javascript"
script.async = true
script.innerHTML = `
{
"feedMode": "all_symbols",
"isTransparent": false,
"displayMode": "regular",
"colorTheme": "light",
"locale": "en"
}`
}, [state])
return (
<div
className="tradingview-widget-container"
ref={container}
style={{ height: "100%", width: "100%" }}
>
<div
className="tradingview-widget-container__widget"
style={{ height: "calc(100% - 32px)", width: "100%" }}
></div>
<div className="tradingview-widget-copyright">
<a
href="https://www.tradingview.com/"
rel="noopener nofollow"
target="_blank"
>
<span className="blue-text"> Track all markets on TradingView </span>
</a>
</div>
</div>
)
}

export default memo(TradingViewWidget)
7 changes: 7 additions & 0 deletions src/example-apps/tradingview/top-stories/top-stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createRoot } from "react-dom/client";
import TradingViewWidget from "./TradingViewWidget";

const container = document.getElementById("app");
const root = createRoot(container!);

root.render(<TradingViewWidget />);
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<script
type="module"
src="/src/example-apps/tradingview/chart.tsx"
src="/src/example-apps/tradingview/chart/chart.tsx"
></script>
</head>

Expand Down
File renamed without changes
14 changes: 14 additions & 0 deletions static/example-apps/tradingview/top-stories/top-stories.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html lang="en">
<head>
<title>FDC3 TradingView Chart</title>
<meta charset="UTF-8" />
<script
type="module"
src="/src/example-apps/tradingview/top-stories/top-stories.tsx"
></script>
</head>

<body>
<div id="app">Content loads here</div>
</body>
</html>

0 comments on commit 1fb81fd

Please sign in to comment.