@exodus/available-assets 1.0.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.
Files changed (3) hide show
  1. package/README.md +27 -0
  2. package/index.js +41 -0
  3. package/package.json +31 -0
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @exodus/balances
2
+
3
+ This module tracks available assets.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ yarn add @exodus/available-assets
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Note: this module does not export a public API aside from its constructor/factory function. It monitors the assetsModule and makes built-in assets/tokens and custom tokens available by writing to the `availableAssetNamesAtom`.
14
+
15
+ ```js
16
+ import createAvailableAssets from '@exodus/available-assets'
17
+
18
+ createAvailableAssets({
19
+ // see #/assets-module in exodus-browser or tests for the API
20
+ assetsModule,
21
+ // atom that this module will write available assets to as they change
22
+ availableAssetNamesAtom,
23
+ // @exodus/blockchain-metadata instance
24
+ // see ../modules/module/src/logger.js for API
25
+ logger,
26
+ })
27
+ ```
package/index.js ADDED
@@ -0,0 +1,41 @@
1
+ import ExodusModule from '@exodus/module'
2
+ import { difference } from 'lodash'
3
+ import restrictConcurrency from 'make-concurrent'
4
+
5
+ class AvailableAssets extends ExodusModule {
6
+ #assetsModule
7
+ #availableAssetNamesAtom
8
+ #availableAssetNamesSet
9
+ constructor({ assetsModule, availableAssetNamesAtom, logger }) {
10
+ super({ name: 'AvailableAssets', logger })
11
+
12
+ this.#assetsModule = assetsModule
13
+ this.#availableAssetNamesAtom = availableAssetNamesAtom
14
+ assetsModule.once('assets-load', ({ importedTokens }) => {
15
+ const toMakeAvailable = Object.keys(importedTokens)
16
+ if (toMakeAvailable.length > 0) {
17
+ this.#makeAssetsAvailable(toMakeAvailable)
18
+ }
19
+
20
+ ;['assets-add', 'assets-update'].forEach((event) =>
21
+ assetsModule.on(event, (assetList) =>
22
+ this.#makeAssetsAvailable(assetList.map((asset) => asset.name))
23
+ )
24
+ )
25
+ })
26
+ }
27
+
28
+ #makeAssetsAvailable = restrictConcurrency(async (assetNames) => {
29
+ const availableAssetNames = await this.#availableAssetNamesAtom.get()
30
+ const toMakeAvailable = difference(assetNames, availableAssetNames)
31
+ if (toMakeAvailable.length === 0) return
32
+
33
+ this._logger.log('making assets available:', toMakeAvailable)
34
+ const update = [...availableAssetNames, ...toMakeAvailable]
35
+ await this.#availableAssetNamesAtom.set(update)
36
+ })
37
+ }
38
+
39
+ const createAvailableAssetsModule = (opts) => new AvailableAssets(opts)
40
+
41
+ export default createAvailableAssetsModule
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@exodus/available-assets",
3
+ "version": "1.0.0",
4
+ "license": "UNLICENSED",
5
+ "main": "index.js",
6
+ "author": "Exodus Movement Inc.",
7
+ "scripts": {
8
+ "test": "jest",
9
+ "lint": "eslint .",
10
+ "lint:fix": "yarn lint --fix"
11
+ },
12
+ "files": [
13
+ "index.js"
14
+ ],
15
+ "homepage": "https://github.com/ExodusMovement/exodus-hydra/tree/master/modules/available-assets",
16
+ "bugs": {
17
+ "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Aavailable-assets"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/ExodusMovement/exodus-hydra.git"
22
+ },
23
+ "dependencies": {
24
+ "@exodus/module": "^1.0.0",
25
+ "lodash": "^4.17.21",
26
+ "make-concurrent": "^5.3.0"
27
+ },
28
+ "devDependencies": {
29
+ "@exodus/atoms": "*"
30
+ }
31
+ }