@exodus/assets-feature 1.1.0 → 1.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
+ ## [1.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@1.2.0...@exodus/assets-feature@1.3.0) (2023-08-23)
7
+
8
+ ### Features
9
+
10
+ - use assets redux module for assets selectors ([#3558](https://github.com/ExodusMovement/exodus-hydra/issues/3558)) ([4723c81](https://github.com/ExodusMovement/exodus-hydra/commit/4723c81f16d5915748e61ab51570b42bc89764f7))
11
+
12
+ ## [1.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@1.1.0...@exodus/assets-feature@1.2.0) (2023-08-21)
13
+
14
+ ### Features
15
+
16
+ - assets redux module ([#3453](https://github.com/ExodusMovement/exodus-hydra/issues/3453)) ([5d6e73c](https://github.com/ExodusMovement/exodus-hydra/commit/5d6e73c667f5f8ce8f830028572efa935994f6cd))
17
+
6
18
  ## [1.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@1.0.0...@exodus/assets-feature@1.1.0) (2023-08-21)
7
19
 
8
20
  ### Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/assets-feature",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Assets module, clients and apis",
6
6
  "main": "index.js",
@@ -14,6 +14,7 @@
14
14
  "client",
15
15
  "module",
16
16
  "plugin",
17
+ "redux",
17
18
  "README.md",
18
19
  "CHANGELOG.md",
19
20
  "!**/__tests__/**"
@@ -29,15 +30,23 @@
29
30
  "dependencies": {
30
31
  "@exodus/basic-utils": "^2.1.0",
31
32
  "lodash": "^4.17.21",
32
- "minimalistic-assert": "^1.0.1"
33
+ "minimalistic-assert": "^1.0.1",
34
+ "reselect": "^3.0.1"
33
35
  },
34
36
  "devDependencies": {
35
- "@exodus/available-assets": "^4.0.0",
37
+ "@exodus/assets": "^8.0.94",
38
+ "@exodus/available-assets": "^4.1.0",
39
+ "@exodus/bitcoin-meta": "^1.0.1",
40
+ "@exodus/ethereum-meta": "^1.0.30",
36
41
  "@exodus/models": "^9.1.1",
42
+ "@exodus/redux-dependency-injection": "^1.0.2",
37
43
  "@exodus/storage-memory": "^2.1.0",
38
44
  "@exodus/wallet-accounts": "^12.0.2",
39
45
  "@exodus/wild-emitter": "^1.0.0",
40
- "events": "^3.3.0"
46
+ "eslint": "^8.44.0",
47
+ "events": "^3.3.0",
48
+ "jest": "^29.1.2",
49
+ "redux": "^4.0.0"
41
50
  },
42
- "gitHead": "380a3945fa45d14ad6fa13018700bd7e7adfcbe7"
51
+ "gitHead": "8e15dd15e20fe0e90927c2ddc3d045847453e217"
43
52
  }
package/redux/id.js ADDED
@@ -0,0 +1 @@
1
+ export default 'assets'
package/redux/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import { keyBy } from '@exodus/basic-utils'
2
+ import id from './id'
3
+ import initialState from './initial-state'
4
+ import selectorDefinitions from './selectors'
5
+
6
+ const mergeAssets = (state, payload) => ({
7
+ ...state,
8
+ data: {
9
+ ...state.data,
10
+ ...keyBy(payload, 'name'),
11
+ },
12
+ })
13
+
14
+ const assetsReduxDefinition = {
15
+ id,
16
+ type: 'redux-module',
17
+ initialState,
18
+ eventReducers: {
19
+ 'assets-load': (state, payload) => ({
20
+ error: null,
21
+ loaded: true,
22
+ data: keyBy(payload, 'name'),
23
+ }),
24
+ 'assets-add': mergeAssets,
25
+ 'assets-update': mergeAssets,
26
+ },
27
+ selectorDefinitions,
28
+ }
29
+
30
+ export default assetsReduxDefinition
@@ -0,0 +1,7 @@
1
+ const initialState = {
2
+ loaded: false,
3
+ data: {},
4
+ error: null,
5
+ }
6
+
7
+ export default initialState
@@ -0,0 +1,62 @@
1
+ import { keyBy } from '@exodus/basic-utils'
2
+ import { createSelector } from 'reselect'
3
+
4
+ import { memoize } from 'lodash'
5
+
6
+ // just a semantic alias for `data`
7
+ const allAssetsSelectorDefinition = {
8
+ id: 'all',
9
+ resultFunction: (data) => data,
10
+ dependencies: [{ selector: 'data' }],
11
+ }
12
+
13
+ const allByTickerSelectorDefinition = {
14
+ id: 'allByTicker',
15
+ resultFunction: (assets) => keyBy(Object.values(assets), (asset) => asset.ticker),
16
+ dependencies: [{ selector: 'all' }],
17
+ }
18
+
19
+ const createAssetSelectorDefinition = {
20
+ id: 'createAssetSelector',
21
+ selectorFactory: (dataSelector) =>
22
+ memoize((assetName) => createSelector(dataSelector, (data) => data[assetName])),
23
+ dependencies: [{ selector: 'data' }],
24
+ }
25
+
26
+ const createBaseAssetSelectorDefinition = {
27
+ id: 'createBaseAssetSelector',
28
+ selectorFactory: (dataSelector) =>
29
+ memoize((assetName) => createSelector(dataSelector, (data) => data[assetName].baseAsset)),
30
+ dependencies: [{ selector: 'data' }],
31
+ }
32
+
33
+ const createFeeAssetSelectorDefinition = {
34
+ id: 'createFeeAssetSelector',
35
+ selectorFactory: (dataSelector) =>
36
+ memoize((assetName) => createSelector(dataSelector, (data) => data[assetName].feeAsset)),
37
+ dependencies: [{ selector: 'data' }],
38
+ }
39
+
40
+ const getAssetSelectorDefinition = {
41
+ id: 'getAsset',
42
+ resultFunction: (assets) => memoize((assetName) => assets[assetName]),
43
+ dependencies: [{ selector: 'all' }],
44
+ }
45
+
46
+ const getAssetFromTickerSelectorDefinition = {
47
+ id: 'getAssetFromTicker',
48
+ resultFunction: (assets) => memoize((ticker) => assets[ticker]),
49
+ dependencies: [{ selector: 'allByTicker' }],
50
+ }
51
+
52
+ const assetSelectors = [
53
+ allAssetsSelectorDefinition,
54
+ allByTickerSelectorDefinition,
55
+ createAssetSelectorDefinition,
56
+ createBaseAssetSelectorDefinition,
57
+ createFeeAssetSelectorDefinition,
58
+ getAssetSelectorDefinition,
59
+ getAssetFromTickerSelectorDefinition,
60
+ ]
61
+
62
+ export default assetSelectors