@exodus/assets-feature 1.0.0 → 1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
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.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
+
8
+ ### Features
9
+
10
+ - assets-feature lifecycle plugin ([#3461](https://github.com/ExodusMovement/exodus-hydra/issues/3461)) ([43da5c7](https://github.com/ExodusMovement/exodus-hydra/commit/43da5c737c7d53b58f64a74f6fcaedf8557134ff))
11
+ - 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: [{ definition: assetsClientInterfaceDefinition }],
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.0.0",
3
+ "version": "1.1.0",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Assets module, clients and apis",
6
6
  "main": "index.js",
@@ -13,6 +13,7 @@
13
13
  "files": [
14
14
  "client",
15
15
  "module",
16
+ "plugin",
16
17
  "README.md",
17
18
  "CHANGELOG.md",
18
19
  "!**/__tests__/**"
@@ -34,7 +35,9 @@
34
35
  "@exodus/available-assets": "^4.0.0",
35
36
  "@exodus/models": "^9.1.1",
36
37
  "@exodus/storage-memory": "^2.1.0",
37
- "@exodus/wallet-accounts": "^12.0.2"
38
+ "@exodus/wallet-accounts": "^12.0.2",
39
+ "@exodus/wild-emitter": "^1.0.0",
40
+ "events": "^3.3.0"
38
41
  },
39
- "gitHead": "69a96e03f6c96d7284d98abb832a7b59b58f718b"
42
+ "gitHead": "380a3945fa45d14ad6fa13018700bd7e7adfcbe7"
40
43
  }
@@ -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