@exodus/market-history 7.1.0 → 7.3.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [7.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/market-history@7.2.0...@exodus/market-history@7.3.0) (2024-01-02)
7
+
8
+ ### Features
9
+
10
+ - **market-history:** stop callback to cancel interval repeat fetching ([#5001](https://github.com/ExodusMovement/exodus-hydra/issues/5001)) ([0be7744](https://github.com/ExodusMovement/exodus-hydra/commit/0be774435d110021f219baaf63a058bb06575539))
11
+
12
+ ## [7.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/market-history@7.1.0...@exodus/market-history@7.2.0) (2023-12-08)
13
+
14
+ ### Features
15
+
16
+ - **market-history:** update when coming back from background ([#4974](https://github.com/ExodusMovement/exodus-hydra/issues/4974)) ([7da86fd](https://github.com/ExodusMovement/exodus-hydra/commit/7da86fdd3d3627c9f89ae8b50adf24b5f77eb47b))
17
+
6
18
  ## [7.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/market-history@7.0.0...@exodus/market-history@7.1.0) (2023-08-29)
7
19
 
8
20
  ### Features
package/atoms/index.js CHANGED
@@ -3,7 +3,7 @@ import { createInMemoryAtom, createRemoteConfigAtomFactory } from '@exodus/atoms
3
3
  export const marketHistoryAtomDefinition = {
4
4
  id: 'marketHistoryAtom',
5
5
  type: 'atom',
6
- factory: () => createInMemoryAtom({}),
6
+ factory: () => createInMemoryAtom({}), // eslint-disable-line @exodus/hydra/in-memory-atom-default-value
7
7
  dependencies: [],
8
8
  }
9
9
 
package/index.js CHANGED
@@ -15,7 +15,7 @@ const marketHistory = () => {
15
15
  definitions: [
16
16
  {
17
17
  definition: { type: 'monitor', ...marketHistoryMonitorDefinition },
18
- writesAtoms: ['marketHistoryAtom'],
18
+
19
19
  storage: { namespace: 'marketHistory' },
20
20
  aliases: [
21
21
  {
package/module/index.js CHANGED
@@ -80,6 +80,7 @@ class MarketHistoryMonitor extends ExodusModule {
80
80
  #marketHistoryAtom = null
81
81
  #enabledAssetsAtom = null
82
82
  #logger = null
83
+ #abortController = new AbortController()
83
84
 
84
85
  constructor({
85
86
  assetsModule,
@@ -266,6 +267,7 @@ class MarketHistoryMonitor extends ExodusModule {
266
267
  )
267
268
  }
268
269
  }
270
+
269
271
  #updateNewAssets = async (assetNames) => {
270
272
  const currency = this.#currency
271
273
 
@@ -344,6 +346,7 @@ class MarketHistoryMonitor extends ExodusModule {
344
346
 
345
347
  fetchPricesInterval({
346
348
  func: updateDayPrices,
349
+ abortController: this.#abortController,
347
350
  granularity: 'day',
348
351
  getJitter: () => jitter,
349
352
  getCurrentTime,
@@ -351,6 +354,7 @@ class MarketHistoryMonitor extends ExodusModule {
351
354
 
352
355
  fetchPricesInterval({
353
356
  func: updateHourPrices,
357
+ abortController: this.#abortController,
354
358
  granularity: 'hour',
355
359
  getJitter: () => jitter,
356
360
  getCurrentTime,
@@ -363,6 +367,7 @@ class MarketHistoryMonitor extends ExodusModule {
363
367
  }
364
368
 
365
369
  this.#started = true
370
+ this.#abortController = new AbortController()
366
371
 
367
372
  const remoteConfigClearCacheVersion = await this.#remoteConfigClearCacheAtom.get()
368
373
  await this.#invalidateStorage({ remoteConfigClearCacheVersion })
@@ -397,6 +402,15 @@ class MarketHistoryMonitor extends ExodusModule {
397
402
  }
398
403
  })
399
404
  }
405
+
406
+ stop = () => {
407
+ if (!this.#started) {
408
+ return
409
+ }
410
+
411
+ this.#started = false
412
+ this.#abortController.abort()
413
+ }
400
414
  }
401
415
 
402
416
  const createMarketHistoryMonitor = (args = {}) => new MarketHistoryMonitor({ ...args })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/market-history",
3
- "version": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "description": "Fetches historical prices for assets",
5
5
  "author": "Exodus Movement Inc.",
6
6
  "license": "UNLICENSED",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@exodus/basic-utils": "^2.0.0",
26
26
  "@exodus/module": "^1.1.0",
27
- "@exodus/price-api": "^3.2.1",
27
+ "@exodus/price-api": "^3.3.3",
28
28
  "lodash": "^4.17.21",
29
29
  "ms": "^0.7.1",
30
30
  "reselect": "^3.0.1"
@@ -32,14 +32,14 @@
32
32
  "devDependencies": {
33
33
  "@exodus/assets": "^8.0.94",
34
34
  "@exodus/assets-base": "^8.1.6",
35
- "@exodus/assets-feature": "^1.4.0",
36
- "@exodus/atoms": "^5.5.0",
35
+ "@exodus/assets-feature": "^4.0.1",
36
+ "@exodus/atoms": "^7.0.0",
37
37
  "@exodus/bitcoin-meta": "^1.0.1",
38
38
  "@exodus/ethereum-meta": "^1.0.30",
39
- "@exodus/locale": "^2.0.0",
40
- "@exodus/rates-monitor": "^4.0.1",
41
- "@exodus/redux-dependency-injection": "^2.0.1",
42
- "@exodus/storage-memory": "^2.1.0",
39
+ "@exodus/locale": "^2.0.2",
40
+ "@exodus/rates-monitor": "^4.1.1",
41
+ "@exodus/redux-dependency-injection": "^3.0.0",
42
+ "@exodus/storage-memory": "^2.1.1",
43
43
  "eslint": "^8.44.0",
44
44
  "events": "^3.3.0",
45
45
  "jest": "^29.1.2",
@@ -56,5 +56,5 @@
56
56
  "type": "git",
57
57
  "url": "git+https://github.com/ExodusMovement/exodus-hydra.git"
58
58
  },
59
- "gitHead": "eee9fe0952865a3f6ab094c4c2205c75b4a37de7"
59
+ "gitHead": "e6f00b51f1aed94f0dd38992a29bed8da239a0b0"
60
60
  }
package/plugin/index.js CHANGED
@@ -1,8 +1,35 @@
1
1
  import { createAtomObserver } from '@exodus/atoms'
2
2
 
3
- const createMarketHistoryLifecyclePlugin = ({ marketHistoryMonitor, marketHistoryAtom, port }) => {
3
+ const createMarketHistoryLifecyclePlugin = ({
4
+ marketHistoryMonitor,
5
+ marketHistoryAtom,
6
+ appProcessAtom,
7
+ port,
8
+ }) => {
9
+ let unobserve
10
+
4
11
  const observer = createAtomObserver({ port, atom: marketHistoryAtom, event: 'marketHistory' })
5
- observer.register()
12
+
13
+ const onStart = () => {
14
+ if (!appProcessAtom) return
15
+
16
+ let previousMode
17
+
18
+ unobserve = appProcessAtom.observe(({ mode }) => {
19
+ const isBackFromBackground = previousMode === 'background' && mode === 'active'
20
+ const isGoingToBackground = previousMode === 'active' && mode === 'background'
21
+
22
+ if (isBackFromBackground) {
23
+ marketHistoryMonitor.start()
24
+ }
25
+
26
+ if (isGoingToBackground) {
27
+ marketHistoryMonitor.stop()
28
+ }
29
+
30
+ previousMode = mode
31
+ })
32
+ }
6
33
 
7
34
  const onLoad = () => {
8
35
  observer.start()
@@ -14,16 +41,17 @@ const createMarketHistoryLifecyclePlugin = ({ marketHistoryMonitor, marketHistor
14
41
 
15
42
  const onStop = () => {
16
43
  observer.unregister()
44
+ unobserve?.()
17
45
  }
18
46
 
19
- return { onUnlock, onLoad, onStop }
47
+ return { onStart, onUnlock, onLoad, onStop }
20
48
  }
21
49
 
22
50
  const marketHistoryLifecyclePluginDefinition = {
23
51
  id: 'marketHistoryLifecyclePlugin',
24
52
  type: 'plugin',
25
53
  factory: createMarketHistoryLifecyclePlugin,
26
- dependencies: ['marketHistoryMonitor', 'marketHistoryAtom', 'port'],
54
+ dependencies: ['marketHistoryMonitor', 'marketHistoryAtom', 'appProcessAtom?', 'port'],
27
55
  }
28
56
 
29
57
  export default marketHistoryLifecyclePluginDefinition
@@ -2,4 +2,5 @@ const marketHistoryInitialState = {
2
2
  loaded: false,
3
3
  data: {},
4
4
  }
5
+
5
6
  export default marketHistoryInitialState
@@ -13,4 +13,5 @@ const getFiatValueWithFallbackSelector = {
13
13
  { selector: 'getPriceWithFallback' },
14
14
  ],
15
15
  }
16
+
16
17
  export default getFiatValueWithFallbackSelector
@@ -47,4 +47,5 @@ const getPriceWithFallbackSelector = {
47
47
  { selector: 'getHourlyPrice' },
48
48
  ],
49
49
  }
50
+
50
51
  export default getPriceWithFallbackSelector