-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathoffscreen-initialization-messages.ts
More file actions
57 lines (56 loc) · 1.96 KB
/
offscreen-initialization-messages.ts
File metadata and controls
57 lines (56 loc) · 1.96 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
import { createMessage } from 'chrome/messages/create-message'
import { MessageClient } from 'chrome/messages/message-client'
import { ConnectorExtensionOptions } from 'options'
import { SessionId, WalletPublicKey } from '../session-router'
import { Connections } from 'pairing/state/connections'
/**
* This section of code handles the retrieval of important data from the background page
* in order to provide necessary information to the offscreen page.
*
* The offscreen page does not have direct access to chrome.storage, so it relies on sending messages
* to the background page to obtain the following data:
* - Connector Extension Options
* - Session Router Data
* - Wallet Connections
*
* Each function within this code block is responsible for retrieving one specific key from the chrome storage.
*/
export const OffscreenInitializationMessages = (
messageClient: MessageClient,
) => {
return {
options: () => {
messageClient
.sendMessageAndWaitForConfirmation<{
options: ConnectorExtensionOptions
}>(createMessage.getExtensionOptions('offScreen'))
.andThen(({ options }) =>
messageClient.handleMessage(
createMessage.setConnectorExtensionOptions('offScreen', options),
),
)
},
sessionRouterData: () => {
messageClient
.sendMessageAndWaitForConfirmation<Record<SessionId, WalletPublicKey>>(
createMessage.getSessionRouterData(),
)
.andThen((sessionRouter) =>
messageClient.handleMessage(
createMessage.setSessionRouterData(sessionRouter, 'offScreen'),
),
)
},
connections: () => {
messageClient
.sendMessageAndWaitForConfirmation<Connections>(
createMessage.getConnections('offScreen'),
)
.andThen((connections) =>
messageClient.handleMessage(
createMessage.setConnections('offScreen', connections),
),
)
},
}
}