-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter-observer.tsx
More file actions
52 lines (44 loc) · 1.88 KB
/
twitter-observer.tsx
File metadata and controls
52 lines (44 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { ActionConfig, isTokenScriptViewerUrl } from "@repo/tlinks"
import { setupTwitterObserver } from "@repo/tlinks/ext/twitter"
import "@repo/tlinks/index.css"
import { useEffect, useState } from "react"
import "~/assets/style.css"
import {AbstractActionComponent, TokenscriptCardMetadata} from "@repo/tlinks";
import {openTsPopupWindow} from "@/lib/open-ts-popup-window";
export const TwitterObserver = () => {
const [dAppUrl, setDAppUrl] = useState("")
const [tsMetadata, setTsMetadata] = useState<TokenscriptCardMetadata|undefined>(undefined)
const iframePopupRef = useRef<IframePopupRef>(null)
useEffect(() => {
const adapter = () =>
new ActionConfig({
signTransaction: (payload: any) =>
chrome.runtime.sendMessage({ type: "eth_sendTransaction", payload }),
connect: () => chrome.runtime.sendMessage({ type: "connect" }),
getConnectedAccount: () =>
chrome.runtime.sendMessage({ type: "getConnectedAccount" }),
interceptHandlePost: async (component: AbstractActionComponent) => {
if (isTokenScriptViewerUrl(component.href)) {
const options = await chrome.storage.sync.get({ use_popup_window: false });
if (options.use_popup_window){
openTsPopupWindow(component.href, component.tsMetadata);
} else {
setTsMetadata(component.tsMetadata as TokenscriptCardMetadata)
setDAppUrl(component.href)
iframePopupRef.current?.setOpen(true)
}
return true
} else {
return false
}
},
metadata: {},
tsIframeRenderer: RendererTokenScriptIframe
})
async function initTwitterObserver() {
setupTwitterObserver(adapter())
}
initTwitterObserver()
}, [])
return <IframePopup ref={iframePopupRef} dAppUrl={dAppUrl} tsMetadata={tsMetadata} />
}