-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathoffscreen.ts
More file actions
62 lines (51 loc) · 1.71 KB
/
offscreen.ts
File metadata and controls
62 lines (51 loc) · 1.71 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
53
54
55
56
57
58
59
60
61
62
import { logger as utilsLogger } from 'utils/logger'
import { OffscreenMessageHandler } from 'chrome/offscreen/message-handler'
import { MessageClient } from 'chrome/messages/message-client'
import { Message } from 'chrome/messages/_types'
import { LogsClient } from './logs-client'
import { WalletConnectionClient } from './wallet-connection/wallet-connection-client'
import { walletConnectionClientFactory } from './wallet-connection/factory'
import { OffscreenInitializationMessages } from './helpers/offscreen-initialization-messages'
import { createChromeHandler } from 'trpc-chrome/adapter'
import { offscreenRouter } from './router/router'
import { backgroundClient } from './router/clients/background'
const logsClient = LogsClient()
utilsLogger.attachTransport((logObj) => {
logsClient.add(logObj)
})
const logger = utilsLogger.getSubLogger({ name: 'offScreen' })
const connections = new Map<string, WalletConnectionClient>()
const messageClient = MessageClient(
OffscreenMessageHandler({
connectionsMap: connections,
logger,
walletConnectionClientFactory,
logsClient,
}),
'offScreen',
{ logger },
)
chrome.runtime.onMessage.addListener((message: Message, sender) => {
messageClient.onMessage(message, sender.tab?.id)
})
const messages = OffscreenInitializationMessages(messageClient)
messages.options()
messages.sessionRouterData()
messages.connections()
declare global {
interface Window {
radix: {
messageClient: MessageClient
connections: Map<string, WalletConnectionClient>
backgroundClient: typeof backgroundClient
}
}
}
window.radix = {
messageClient,
connections,
backgroundClient: backgroundClient,
}
createChromeHandler({
router: offscreenRouter,
})