@exodus/assets-feature 3.0.0 → 3.1.1

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
+ ## [3.1.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@3.1.0...@exodus/assets-feature@3.1.1) (2023-09-20)
7
+
8
+ ### Bug Fixes
9
+
10
+ - not all assets have api.hasFeature ([#4161](https://github.com/ExodusMovement/exodus-hydra/issues/4161)) ([1b60147](https://github.com/ExodusMovement/exodus-hydra/commit/1b601478423b7d288593809f1046649dd3b265c6))
11
+
12
+ ## [3.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@3.0.0...@exodus/assets-feature@3.1.0) (2023-09-20)
13
+
14
+ ### Features
15
+
16
+ - add custom tokens monitor ([#4150](https://github.com/ExodusMovement/exodus-hydra/issues/4150)) ([f9d8bee](https://github.com/ExodusMovement/exodus-hydra/commit/f9d8bee4b0aecdf8c04bb03b960316ce64e24b91))
17
+ - support external asset registry ([#4138](https://github.com/ExodusMovement/exodus-hydra/issues/4138)) ([3100890](https://github.com/ExodusMovement/exodus-hydra/commit/3100890ed264cf670cad1c76290067f58bf8cd62))
18
+
19
+ ### Bug Fixes
20
+
21
+ - ensure tokens have display properties ([#4149](https://github.com/ExodusMovement/exodus-hydra/issues/4149)) ([4f39d42](https://github.com/ExodusMovement/exodus-hydra/commit/4f39d42b7446b89638791d1c01af1fe035898b2d))
22
+ - minor custom token bugs ([#13202](https://github.com/ExodusMovement/exodus-hydra/issues/13202)) ([876214a](https://github.com/ExodusMovement/exodus-hydra/commit/876214a8e04e4fb84b729cabd804b4345f03a51d))
23
+
6
24
  ## [3.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@2.0.2...@exodus/assets-feature@3.0.0) (2023-09-19)
7
25
 
8
26
  ### ⚠ BREAKING CHANGES
package/index.js CHANGED
@@ -4,6 +4,7 @@ import multiAddressModeAtomDefinition from './atoms/multi-address-mode'
4
4
  import disabledPurposesAtomDefinition from './atoms/disabled-purposes'
5
5
  import assetsApiDefinition from './api'
6
6
  import assetModuleDefinition from './module'
7
+ import customTokensMonitorDefinition from './monitor'
7
8
  import assetPreferencesDefinition from './module/asset-preferences'
8
9
 
9
10
  const assets = ({ config = {} } = {}) => {
@@ -34,6 +35,7 @@ const assets = ({ config = {} } = {}) => {
34
35
  definition: assetPreferencesDefinition,
35
36
  writesAtoms: ['multiAddressModeAtom', 'disabledPurposesAtom'],
36
37
  },
38
+ { definition: customTokensMonitorDefinition },
37
39
  ],
38
40
  }
39
41
  }
@@ -25,7 +25,31 @@ const getFetchCacheKey = (baseAssetName, assetId) => `${assetId}-${baseAssetName
25
25
 
26
26
  const _isDisabledCustomToken = (token) => token.lifecycleStatus === STATUS.DISABLED
27
27
 
28
- const normalizeToken = (token) => (token.name ? token : { ...token, name: token.assetName })
28
+ const normalizeToken = (token) => ({
29
+ ...token,
30
+ name: token.name || token.assetName,
31
+ displayName: token.displayName || token.properName,
32
+ displayTicker: token.displayTicker || token.properTicker,
33
+ })
34
+
35
+ const initialAssetRegistry = {
36
+ getAsset: (assetName) => {
37
+ try {
38
+ throw new Error(`accessing asset ${assetName} too early`)
39
+ } catch (e) {
40
+ console.warn(e.message, e.stack)
41
+ }
42
+ },
43
+ getAssets: () => {
44
+ try {
45
+ throw new Error(`accessing assets too early`)
46
+ } catch (e) {
47
+ console.warn(e.message, e.stack)
48
+ }
49
+
50
+ return {}
51
+ },
52
+ }
29
53
 
30
54
  export class AssetsModule extends ExodusModule {
31
55
  #registry
@@ -43,10 +67,12 @@ export class AssetsModule extends ExodusModule {
43
67
  #customTokenUpdateInterval
44
68
  #fetchCacheExpiry
45
69
  #globalAssetRegistry // temporary
70
+ #isExternalRegistry
46
71
 
47
72
  constructor({
48
73
  storage,
49
74
  iconsStorage,
75
+ assetRegistry, // temporary
50
76
  assetPlugins,
51
77
  combinedAssetsList,
52
78
  globalAssetRegistry, // temporary
@@ -55,24 +81,8 @@ export class AssetsModule extends ExodusModule {
55
81
  }) {
56
82
  super({ name: 'AssetsModule' })
57
83
  this.#storage = storage
58
- this.#registry = {
59
- getAsset: (assetName) => {
60
- try {
61
- throw new Error(`accessing asset ${assetName} too early`)
62
- } catch (e) {
63
- console.warn(e.message, e.stack)
64
- }
65
- },
66
- getAssets: () => {
67
- try {
68
- throw new Error(`accessing assets too early`)
69
- } catch (e) {
70
- console.warn(e.message, e.stack)
71
- }
72
-
73
- return {}
74
- },
75
- }
84
+ this.#isExternalRegistry = !!assetRegistry
85
+ this.#registry = this.#isExternalRegistry ? assetRegistry : initialAssetRegistry
76
86
  this.#assetPlugins = assetPlugins
77
87
  this.#combinedAssetsList = combinedAssetsList
78
88
  this.#fetchCache = {}
@@ -91,6 +101,10 @@ export class AssetsModule extends ExodusModule {
91
101
  // Assets Registry API
92
102
 
93
103
  initialize = ({ assetClientInterface }) => {
104
+ assert(
105
+ !this.#isExternalRegistry,
106
+ 'initialize(): cannot initialize when using external registry'
107
+ )
94
108
  // TODO: pass asset specific config to assets module in `config.assetsConfig`
95
109
  const { assetsConfig = {} } = this.#config
96
110
  const assetsList = Object.entries(this.#assetPlugins)
@@ -0,0 +1,22 @@
1
+ import { Timer } from '@exodus/timer'
2
+ import ms from 'ms'
3
+
4
+ const createCustomTokensMonitor = ({ assetsModule, appProcess }) => {
5
+ const timer = new Timer(ms('1m'))
6
+
7
+ timer.callback = async () => {
8
+ await appProcess?.awaitState('active')
9
+ assetsModule.updateTokens()
10
+ }
11
+
12
+ return timer
13
+ }
14
+
15
+ const customTokensMonitorDefinition = {
16
+ id: 'customTokensMonitor',
17
+ type: 'monitor',
18
+ factory: createCustomTokensMonitor,
19
+ dependencies: ['assetsModule', 'appProcess?'],
20
+ }
21
+
22
+ export default customTokensMonitorDefinition
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/assets-feature",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
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
+ "monitor",
16
17
  "plugin",
17
18
  "redux",
18
19
  "api",
@@ -32,6 +33,7 @@
32
33
  "dependencies": {
33
34
  "@exodus/basic-utils": "^2.1.0",
34
35
  "@exodus/fetch": "^1.2.1",
36
+ "@exodus/timer": "^1.0.0",
35
37
  "lodash": "^4.17.21",
36
38
  "minimalistic-assert": "^1.0.1",
37
39
  "ms": "^2.1.3",
@@ -60,5 +62,5 @@
60
62
  "jest": "^29.1.2",
61
63
  "redux": "^4.0.0"
62
64
  },
63
- "gitHead": "c69b2cf286e6134084a53e82b81e054c4fd9f38a"
65
+ "gitHead": "c934b363c277eab13913053034e3e68d15650de9"
64
66
  }
package/plugin/index.js CHANGED
@@ -7,8 +7,8 @@ const createAssetsPlugin = ({ port, assetsModule, disabledPurposesAtom, multiAdd
7
7
  port.emit('assets-load', {
8
8
  assets,
9
9
  defaultAccountStates: mapValues(
10
- pickBy(assets, (asset) => asset.api.hasFeature('accountState')),
11
- (asset) => asset?.api?.createAccountState?.()?.create?.()
10
+ pickBy(assets, (asset) => asset.api?.hasFeature?.('accountState')),
11
+ (asset) => asset.api.createAccountState().create()
12
12
  ),
13
13
  })
14
14
  }