@exodus/ethereum-api 9.0.3 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,71 +0,0 @@
1
- import ms from 'ms'
2
-
3
- const subscribedToAddressNotificationsMap = new Map()
4
-
5
- const UPDATE_LOOP_INTERVAL = ms('5m')
6
-
7
- export function subscribeToWSNotifications({
8
- addressesByWalletAccount,
9
- tick,
10
- server,
11
- beforeStart = false,
12
- }) {
13
- Object.entries(addressesByWalletAccount).forEach(([walletAccount, addresses]) => {
14
- const address = String([...addresses][0]).toLowerCase() // Only check m/0/0
15
- const mapKey = `${server.getURL()}:${address}` // different chains might have the same addresses
16
- if (subscribedToAddressNotificationsMap.has(mapKey)) return
17
-
18
- server.ws.watch(address)
19
- server.ws.events.on(`address-${address}`, () => {
20
- tick({ refresh: false, walletAccount })
21
- })
22
- subscribedToAddressNotificationsMap.set(mapKey, true)
23
- if (!beforeStart) {
24
- // tick for a new wallet account
25
- tick({ refresh: false, walletAccount })
26
- }
27
- })
28
- }
29
-
30
- export function subscribeToGasPriceNotifications({
31
- server,
32
- updateGasPrice,
33
- subscribedToGasPriceMap,
34
- }) {
35
- const mapKey = server.getURL()
36
- if (subscribedToGasPriceMap.has(mapKey)) return
37
- server.ws.events.on('gasprice', updateGasPrice)
38
- subscribedToGasPriceMap.set(mapKey, true)
39
- }
40
-
41
- export function enableWSUpdates({
42
- interval,
43
- server,
44
- timer,
45
- tickWalletAccounts,
46
- tick,
47
- addressesByWalletAccount,
48
- beforeStart = false,
49
- }) {
50
- const defaultInterval = interval
51
-
52
- subscribeToWSNotifications({
53
- server,
54
- beforeStart,
55
- tick,
56
- addressesByWalletAccount,
57
- })
58
-
59
- server.ws.events.on('open', () => {
60
- if (timer.isRunning) {
61
- timer.setNewInterval(UPDATE_LOOP_INTERVAL)
62
- }
63
- })
64
- server.ws.events.on('close', async () => {
65
- if (timer.isRunning) {
66
- await timer.setNewInterval(defaultInterval)
67
- return tickWalletAccounts()
68
- }
69
- })
70
- server.ws.open()
71
- }