@exodus/assets-feature 1.0.0 → 1.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 +17 -0
- package/index.js +5 -1
- package/package.json +16 -4
- package/plugin/index.js +34 -0
- package/redux/id.js +1 -0
- package/redux/index.js +30 -0
- package/redux/initial-state.js +7 -0
- package/redux/selectors/index.js +48 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [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)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- assets redux module ([#3453](https://github.com/ExodusMovement/exodus-hydra/issues/3453)) ([5d6e73c](https://github.com/ExodusMovement/exodus-hydra/commit/5d6e73c667f5f8ce8f830028572efa935994f6cd))
|
|
11
|
+
|
|
12
|
+
## [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)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- assets-feature lifecycle plugin ([#3461](https://github.com/ExodusMovement/exodus-hydra/issues/3461)) ([43da5c7](https://github.com/ExodusMovement/exodus-hydra/commit/43da5c737c7d53b58f64a74f6fcaedf8557134ff))
|
|
17
|
+
- cleanup subscriptions `onStop` ([#3468](https://github.com/ExodusMovement/exodus-hydra/issues/3468)) ([b58e8da](https://github.com/ExodusMovement/exodus-hydra/commit/b58e8daa38288256500b109af0f3927023cff8b9))
|
package/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import assetsClientInterfaceDefinition from './client'
|
|
2
|
+
import assetsPluginDefinition from './plugin'
|
|
2
3
|
|
|
3
4
|
const assets = () => {
|
|
4
5
|
return {
|
|
5
6
|
id: 'assets',
|
|
6
|
-
definitions: [
|
|
7
|
+
definitions: [
|
|
8
|
+
{ definition: assetsClientInterfaceDefinition },
|
|
9
|
+
{ definition: assetsPluginDefinition },
|
|
10
|
+
],
|
|
7
11
|
}
|
|
8
12
|
}
|
|
9
13
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/assets-feature",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"description": "Assets module, clients and apis",
|
|
6
6
|
"main": "index.js",
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"client",
|
|
15
15
|
"module",
|
|
16
|
+
"plugin",
|
|
17
|
+
"redux",
|
|
16
18
|
"README.md",
|
|
17
19
|
"CHANGELOG.md",
|
|
18
20
|
"!**/__tests__/**"
|
|
@@ -28,13 +30,23 @@
|
|
|
28
30
|
"dependencies": {
|
|
29
31
|
"@exodus/basic-utils": "^2.1.0",
|
|
30
32
|
"lodash": "^4.17.21",
|
|
31
|
-
"minimalistic-assert": "^1.0.1"
|
|
33
|
+
"minimalistic-assert": "^1.0.1",
|
|
34
|
+
"reselect": "^3.0.1"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
37
|
+
"@exodus/assets": "^8.0.94",
|
|
34
38
|
"@exodus/available-assets": "^4.0.0",
|
|
39
|
+
"@exodus/bitcoin-meta": "^1.0.1",
|
|
40
|
+
"@exodus/ethereum-meta": "^1.0.30",
|
|
35
41
|
"@exodus/models": "^9.1.1",
|
|
42
|
+
"@exodus/redux-dependency-injection": "^1.0.2",
|
|
36
43
|
"@exodus/storage-memory": "^2.1.0",
|
|
37
|
-
"@exodus/wallet-accounts": "^12.0.2"
|
|
44
|
+
"@exodus/wallet-accounts": "^12.0.2",
|
|
45
|
+
"@exodus/wild-emitter": "^1.0.0",
|
|
46
|
+
"eslint": "^8.44.0",
|
|
47
|
+
"events": "^3.3.0",
|
|
48
|
+
"jest": "^29.1.2",
|
|
49
|
+
"redux": "^4.0.0"
|
|
38
50
|
},
|
|
39
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "ae415ad730407a51764a46179dd88cc1b1c4c734"
|
|
40
52
|
}
|
package/plugin/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const createAssetsPlugin = ({ port, assetsModule }) => {
|
|
2
|
+
const listeners = [
|
|
3
|
+
['assets-load', () => port.emit('assets-load', Object.values(assetsModule.getAssets()))],
|
|
4
|
+
['assets-add', (data) => port.emit('assets-add', data)],
|
|
5
|
+
['assets-update', (data) => port.emit('assets-update', data)],
|
|
6
|
+
]
|
|
7
|
+
|
|
8
|
+
listeners.forEach(([event, callback]) => {
|
|
9
|
+
assetsModule.on(event, callback)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const onLoad = async ({ isLocked }) => {
|
|
13
|
+
if (!isLocked) {
|
|
14
|
+
await assetsModule.load()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const onStop = () => {
|
|
19
|
+
listeners.forEach(([event, callback]) => {
|
|
20
|
+
assetsModule.removeListener(event, callback)
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { onLoad, onStop }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const assetsPluginDefinition = {
|
|
28
|
+
id: 'assetsPlugin',
|
|
29
|
+
type: 'plugin',
|
|
30
|
+
factory: createAssetsPlugin,
|
|
31
|
+
dependencies: ['port', 'assetsModule'],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default assetsPluginDefinition
|
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,48 @@
|
|
|
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 assetSelectors = [
|
|
41
|
+
allAssetsSelectorDefinition,
|
|
42
|
+
allByTickerSelectorDefinition,
|
|
43
|
+
createAssetSelectorDefinition,
|
|
44
|
+
createBaseAssetSelectorDefinition,
|
|
45
|
+
createFeeAssetSelectorDefinition,
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
export default assetSelectors
|