@exodus/market-history 5.0.1 → 5.2.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,24 @@
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
+ ## [5.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/market-history@5.1.0...@exodus/market-history@5.2.0) (2023-08-21)
7
+
8
+ ### Features
9
+
10
+ - **@exodus/market-history:** add api definition ([#3488](https://github.com/ExodusMovement/exodus-hydra/issues/3488)) ([b9b1e8b](https://github.com/ExodusMovement/exodus-hydra/commit/b9b1e8b9cb61d94ad21274883b18f2f08dc7db53))
11
+
12
+ ## [5.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/market-history@5.0.1...@exodus/market-history@5.1.0) (2023-08-17)
13
+
14
+ ### Features
15
+
16
+ - market-history-redux ([#3344](https://github.com/ExodusMovement/exodus-hydra/issues/3344)) ([3624808](https://github.com/ExodusMovement/exodus-hydra/commit/36248086e4cb61710ada6715289f6554b5e02c6e))
17
+ - more market-history selectors ([#3362](https://github.com/ExodusMovement/exodus-hydra/issues/3362)) ([7e1a3fb](https://github.com/ExodusMovement/exodus-hydra/commit/7e1a3fbb80df454867f8a47a08215f1d17a005f9))
18
+
19
+ ### Bug Fixes
20
+
21
+ - add redux folder ([#3425](https://github.com/ExodusMovement/exodus-hydra/issues/3425)) ([84a42a7](https://github.com/ExodusMovement/exodus-hydra/commit/84a42a78d364f463c0d3cdb434bad079c3b38fa3))
22
+ - auto-fix lint issues ([#2443](https://github.com/ExodusMovement/exodus-hydra/issues/2443)) ([e280366](https://github.com/ExodusMovement/exodus-hydra/commit/e280366b53dabc25280fd16c9e44f812a10f3e65))
23
+
6
24
  ## [5.0.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/market-history@5.0.0...@exodus/market-history@5.0.1) (2023-07-07)
7
25
 
8
26
  ### Bug Fixes
package/api/index.js ADDED
@@ -0,0 +1,15 @@
1
+ const createMarketHistoryApi = ({ marketHistoryMonitor }) => {
2
+ return {
3
+ marketHistory: {
4
+ update: marketHistoryMonitor.update,
5
+ },
6
+ }
7
+ }
8
+
9
+ // eslint-disable-next-line @exodus/export-default/named
10
+ export default {
11
+ id: 'marketHistoryApi',
12
+ type: 'api',
13
+ factory: createMarketHistoryApi,
14
+ dependencies: ['marketHistoryMonitor'],
15
+ }
package/index.js CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  import marketHistoryMonitorDefinition from './module'
8
8
 
9
9
  import marketHistoryPluginDefinition from './plugin'
10
+ import marketHistoryApiDefinition from './api'
10
11
 
11
12
  const marketHistory = () => {
12
13
  return {
@@ -46,6 +47,7 @@ const marketHistory = () => {
46
47
  },
47
48
  { definition: marketHistoryPluginDefinition },
48
49
  { definition: marketHistoryAtomDefinition },
50
+ { definition: marketHistoryApiDefinition },
49
51
  ],
50
52
  }
51
53
  }
package/module/index.js CHANGED
@@ -121,6 +121,7 @@ class MarketHistoryMonitor extends ExodusModule {
121
121
  acc[key] = values
122
122
  this.#runtimeCache.set(key, values)
123
123
  }
124
+
124
125
  return acc
125
126
  }, {})
126
127
 
@@ -134,6 +135,7 @@ class MarketHistoryMonitor extends ExodusModule {
134
135
  if (cachedValue) {
135
136
  return cachedValue
136
137
  }
138
+
137
139
  const cache = (await this.storage.get(key)) || []
138
140
  this.#runtimeCache.set(key, cache)
139
141
 
@@ -399,8 +401,10 @@ class MarketHistoryMonitor extends ExodusModule {
399
401
 
400
402
  const createMarketHistoryMonitor = (args = {}) => new MarketHistoryMonitor({ ...args })
401
403
 
404
+ // eslint-disable-next-line @exodus/export-default/named
402
405
  export default {
403
406
  id: MODULE_ID,
407
+ type: 'module',
404
408
  factory: createMarketHistoryMonitor,
405
409
  dependencies: [
406
410
  'pricingClient',
@@ -413,5 +417,6 @@ export default {
413
417
  'enabledAssetsAtom',
414
418
  'marketHistoryAtom',
415
419
  'logger',
420
+ 'getCacheKey?',
416
421
  ],
417
422
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/market-history",
3
- "version": "5.0.1",
3
+ "version": "5.2.0",
4
4
  "description": "Fetches historical prices for assets",
5
5
  "author": "Exodus Movement Inc.",
6
6
  "license": "UNLICENSED",
@@ -11,40 +11,45 @@
11
11
  },
12
12
  "main": "index.js",
13
13
  "files": [
14
+ "api",
14
15
  "module",
15
16
  "atoms",
16
17
  "plugin",
18
+ "redux",
17
19
  "utils.js",
18
20
  "CHANGELOG.md",
19
21
  "README.md",
20
- "index.js",
21
22
  "!**/__tests__/**"
22
23
  ],
23
24
  "dependencies": {
24
25
  "@exodus/basic-utils": "^2.0.0",
25
26
  "@exodus/module": "^1.1.0",
26
27
  "@exodus/price-api": "^3.2.1",
27
- "ms": "^0.7.1"
28
+ "ms": "^0.7.1",
29
+ "reselect": "^3.0.1"
28
30
  },
29
31
  "devDependencies": {
30
32
  "@exodus/assets": "^8.0.88",
31
33
  "@exodus/assets-base": "^8.1.6",
32
- "@exodus/atoms": "^5.2.1",
34
+ "@exodus/atoms": "^5.5.0",
35
+ "@exodus/locale": "^1.2.1",
36
+ "@exodus/redux-dependency-injection": "^1.0.2",
33
37
  "@exodus/storage-memory": "^2.1.0",
34
- "eslint": "^8.33.0",
38
+ "eslint": "^8.44.0",
35
39
  "events": "^3.3.0",
36
- "jest": "^29.1.2"
40
+ "jest": "^29.1.2",
41
+ "redux": "^4.0.0"
37
42
  },
38
43
  "peerDependencies": {
39
44
  "debug": ">= 3.0.0"
40
45
  },
41
- "homepage": "https://github.com/ExodusMovement/exodus-hydra/tree/master/modules/crypto-news-monitor",
46
+ "homepage": "https://github.com/ExodusMovement/exodus-hydra/tree/master/features/market-history",
42
47
  "bugs": {
43
- "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Crypto-news-monitor"
48
+ "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Amarket-history"
44
49
  },
45
50
  "repository": {
46
51
  "type": "git",
47
52
  "url": "git+https://github.com/ExodusMovement/exodus-hydra.git"
48
53
  },
49
- "gitHead": "44aa4c35fca60884894a86a46c8cbfa3c5810540"
54
+ "gitHead": "81c9577ce20053b1ed645fdcf12ea3c0c824f29a"
50
55
  }
package/plugin/index.js CHANGED
@@ -1,11 +1,4 @@
1
- const createMarketHistoryLifecyclePlugin = ({ marketHistoryMonitor, marketHistoryAtom, port }) => {
2
- marketHistoryAtom.observe(({ data, changes }) =>
3
- port.emit('market-history', {
4
- data,
5
- changes,
6
- })
7
- )
8
-
1
+ const createMarketHistoryLifecyclePlugin = ({ marketHistoryMonitor }) => {
9
2
  const onUnlock = () => {
10
3
  marketHistoryMonitor.start()
11
4
  }
@@ -13,9 +6,11 @@ const createMarketHistoryLifecyclePlugin = ({ marketHistoryMonitor, marketHistor
13
6
  return { onUnlock }
14
7
  }
15
8
 
16
- export default {
9
+ const marketHistoryLifecyclePluginDefinition = {
17
10
  id: 'marketHistoryLifecyclePlugin',
18
11
  type: 'plugin',
19
12
  factory: createMarketHistoryLifecyclePlugin,
20
- dependencies: ['marketHistoryMonitor', 'port', 'marketHistoryAtom'],
13
+ dependencies: ['marketHistoryMonitor'],
21
14
  }
15
+
16
+ export default marketHistoryLifecyclePluginDefinition
package/redux/id.js ADDED
@@ -0,0 +1 @@
1
+ export default 'marketHistory'
package/redux/index.js ADDED
@@ -0,0 +1,19 @@
1
+ import id from './id'
2
+ import initialState from './initial-state'
3
+ import selectorDefinitions from './selectors'
4
+
5
+ const marketHistoryReduxDefinition = {
6
+ id,
7
+ type: 'redux-module',
8
+ initialState,
9
+ eventReducers: {
10
+ marketHistoryAtom: (state, marketHistory) => ({
11
+ ...state,
12
+ loaded: true,
13
+ data: marketHistory.data,
14
+ }),
15
+ },
16
+ selectorDefinitions,
17
+ }
18
+
19
+ export default marketHistoryReduxDefinition
@@ -0,0 +1,5 @@
1
+ const marketHistoryInitialState = {
2
+ loaded: false,
3
+ data: {},
4
+ }
5
+ export default marketHistoryInitialState
@@ -0,0 +1,13 @@
1
+ const DEFAULT = {}
2
+ const resultFunction = (fiatMarketHistory) => fiatMarketHistory?.daily ?? DEFAULT
3
+
4
+ const dailyPricesSelector = {
5
+ id: 'dailyPrices',
6
+ resultFunction,
7
+ dependencies: [
8
+ //
9
+ { selector: 'fiatMarketHistory' },
10
+ ],
11
+ }
12
+
13
+ export default dailyPricesSelector
@@ -0,0 +1,15 @@
1
+ const DEFAULT = {}
2
+ const resultFunction = (marketHistory, fiat) =>
3
+ marketHistory?.[fiat.defaultUnit.unitName] ?? DEFAULT
4
+
5
+ const fiatMarketHistorySelector = {
6
+ id: 'fiatMarketHistory',
7
+ resultFunction,
8
+ dependencies: [
9
+ //
10
+ { selector: 'data' },
11
+ { module: 'locale', selector: 'currencyUnitType' },
12
+ ],
13
+ }
14
+
15
+ export default fiatMarketHistorySelector
@@ -0,0 +1,12 @@
1
+ const resultFunction = (dailyPrices) => (assetName) => dailyPrices[assetName]
2
+
3
+ const getAssetDailyPricesSelector = {
4
+ id: 'getAssetDailyPrices',
5
+ resultFunction,
6
+ dependencies: [
7
+ //
8
+ { selector: 'dailyPrices' },
9
+ ],
10
+ }
11
+
12
+ export default getAssetDailyPricesSelector
@@ -0,0 +1,12 @@
1
+ const resultFunction = (prices) => (assetName) => prices[assetName]
2
+
3
+ const getAssetHourlyPricesSelector = {
4
+ id: 'getAssetHourlyPrices',
5
+ resultFunction,
6
+ dependencies: [
7
+ //
8
+ { selector: 'hourlyPrices' },
9
+ ],
10
+ }
11
+
12
+ export default getAssetHourlyPricesSelector
@@ -0,0 +1,13 @@
1
+ const DEFAULT = {}
2
+ const resultFunction = (fiatMarketHistory) => fiatMarketHistory?.hourly ?? DEFAULT
3
+
4
+ const hourlyPricesSelector = {
5
+ id: 'hourlyPrices',
6
+ resultFunction,
7
+ dependencies: [
8
+ //
9
+ { selector: 'fiatMarketHistory' },
10
+ ],
11
+ }
12
+
13
+ export default hourlyPricesSelector
@@ -0,0 +1,20 @@
1
+ import marketHistoryLoadingSelector, {
2
+ dailyMarketHistoryIsLoadingSelector,
3
+ hourlyMarketHistoryIsLoadingSelector,
4
+ } from './loading'
5
+ import fiatMarketHistorySelector from './fiat-market-history'
6
+ import dailyPricesSelector from './daily-prices'
7
+ import hourlyPricesSelector from './hourly-prices'
8
+ import getAssetDailyPricesSelector from './get-asset-daily-prices'
9
+ import getAssetHourlyPricesSelector from './get-asset-hourly-prices'
10
+
11
+ export default [
12
+ marketHistoryLoadingSelector,
13
+ hourlyMarketHistoryIsLoadingSelector,
14
+ dailyMarketHistoryIsLoadingSelector,
15
+ fiatMarketHistorySelector,
16
+ dailyPricesSelector,
17
+ hourlyPricesSelector,
18
+ getAssetDailyPricesSelector,
19
+ getAssetHourlyPricesSelector,
20
+ ]
@@ -0,0 +1,53 @@
1
+ import { createSelector } from 'reselect'
2
+
3
+ export const dailyMarketHistoryIsLoadingSelector = {
4
+ id: 'dailyLoading',
5
+ selectorFactory: (dataSelector, loadedSelector) =>
6
+ createSelector(
7
+ dataSelector,
8
+ loadedSelector,
9
+ (data, loaded) => !loaded || Object.values(data).some((prices) => !prices.daily)
10
+ ),
11
+ dependencies: [
12
+ //
13
+ { selector: 'data' },
14
+ { selector: 'loaded' },
15
+ ],
16
+ }
17
+
18
+ export const hourlyMarketHistoryIsLoadingSelector = {
19
+ id: 'hourlyLoading',
20
+ selectorFactory: (dataSelector, loadedSelector) =>
21
+ createSelector(
22
+ dataSelector,
23
+ loadedSelector,
24
+ (data, loaded) => !loaded || Object.values(data).some((prices) => !prices.hourly)
25
+ ),
26
+ dependencies: [
27
+ //
28
+ { selector: 'data' },
29
+ { selector: 'loaded' },
30
+ ],
31
+ }
32
+
33
+ const marketHistoryLoadingSelector = {
34
+ id: 'loadingMap',
35
+ selectorFactory: (dailyMarketHistoryIsLoadingSelector, hourlyMarketHistoryIsLoadingSelector) =>
36
+ createSelector(
37
+ dailyMarketHistoryIsLoadingSelector,
38
+ hourlyMarketHistoryIsLoadingSelector,
39
+ (dailyLoading, hourlyLoading) => {
40
+ return {
41
+ dailyLoading,
42
+ hourlyLoading,
43
+ }
44
+ }
45
+ ),
46
+ dependencies: [
47
+ //
48
+ { selector: 'dailyLoading' },
49
+ { selector: 'hourlyLoading' },
50
+ ],
51
+ }
52
+
53
+ export default marketHistoryLoadingSelector
package/utils.js CHANGED
@@ -6,6 +6,7 @@ export const getAssetFromTicker = (assets, ticker) => {
6
6
  assetFromTickerCache[ticker] = asset
7
7
  return true
8
8
  }
9
+
9
10
  return false
10
11
  })
11
12
  }