@exodus/assets-feature 3.8.0 → 4.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
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
+ ## [4.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@3.8.0...@exodus/assets-feature@4.0.0) (2023-11-23)
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ - remove legacy asset events (#4826)
11
+
12
+ ### Features
13
+
14
+ - remove legacy asset events ([#4826](https://github.com/ExodusMovement/exodus-hydra/issues/4826)) ([6f27e5f](https://github.com/ExodusMovement/exodus-hydra/commit/6f27e5fa2294cb82db2651069eba4964b37f8e5e))
15
+
6
16
  ## [3.8.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@3.7.0...@exodus/assets-feature@3.8.0) (2023-11-21)
7
17
 
8
18
  ### Features
@@ -6,7 +6,6 @@ import {
6
6
  CT_UPDATEABLE_PROPERTIES,
7
7
  } from '@exodus/assets'
8
8
  import { mapValues, pick, pickBy } from '@exodus/basic-utils'
9
- import ExodusModule from '@exodus/module'
10
9
  // eslint-disable-next-line @exodus/restricted-imports/prefer-basic-utils
11
10
  import { get, isEmpty, keyBy, once } from 'lodash'
12
11
  import assert from 'minimalistic-assert'
@@ -70,7 +69,7 @@ const initialAssetRegistry = {
70
69
  },
71
70
  }
72
71
 
73
- export class AssetsModule extends ExodusModule {
72
+ export class AssetsModule {
74
73
  #registry
75
74
  #storage
76
75
  #fetchCache
@@ -88,6 +87,7 @@ export class AssetsModule extends ExodusModule {
88
87
  #isExternalRegistry
89
88
  #assetsAtom
90
89
  #fetchival
90
+ #logger
91
91
 
92
92
  constructor({
93
93
  storage,
@@ -99,9 +99,8 @@ export class AssetsModule extends ExodusModule {
99
99
  validateCustomToken = () => true,
100
100
  config = {},
101
101
  fetch,
102
+ logger,
102
103
  }) {
103
- super({ name: 'AssetsModule' })
104
-
105
104
  this.#assetsAtom = assetsAtom
106
105
  this.#storage = storage
107
106
  this.#isExternalRegistry = !!assetRegistry
@@ -119,6 +118,7 @@ export class AssetsModule extends ExodusModule {
119
118
  this.#customTokenUpdateInterval = config.customTokenUpdateInterval || CT_UPDATE_INTERVAL
120
119
  this.#fetchCacheExpiry = config.fetchCacheExpiry ?? CT_FETCH_CACHE_EXPIRY
121
120
  this.#fetchival = createFetchival({ fetch })
121
+ this.#logger = logger
122
122
  }
123
123
 
124
124
  #setRegistry = (registry) => {
@@ -176,8 +176,6 @@ export class AssetsModule extends ExodusModule {
176
176
  getBaseAssetNames = () => this.#getAssetNamesBy((asset) => asset.baseAsset.name === asset.name)
177
177
 
178
178
  load = once(async () => {
179
- this.emit('assets-load', { importedTokens: {} })
180
-
181
179
  try {
182
180
  const storedTokens = await this.#readCustomTokens()
183
181
  const tokens = pickBy(storedTokens, ({ baseAssetName }) => {
@@ -193,7 +191,7 @@ export class AssetsModule extends ExodusModule {
193
191
  const { added, updated } = this.#handleFetchedTokens(Object.values(tokens))
194
192
  this.#flushChanges({ added, updated })
195
193
  } catch (e) {
196
- this._logger.log('error reading custom tokens from storage:', e)
194
+ this.#logger.log('error reading custom tokens from storage:', e)
197
195
  }
198
196
  })
199
197
 
@@ -214,7 +212,7 @@ export class AssetsModule extends ExodusModule {
214
212
 
215
213
  const _token = await this.#fetch(`networks/${baseAssetName}`, { assetId }, 'token')
216
214
  if (!this.#validateCustomToken(_token)) {
217
- this._logger.warn('Invalid Custom Token schema')
215
+ this.#logger.warn('Invalid Custom Token schema')
218
216
  throw new Error('Token did not pass validation')
219
217
  }
220
218
 
@@ -223,7 +221,7 @@ export class AssetsModule extends ExodusModule {
223
221
  try {
224
222
  await this.#iconsStorage.storeIcons([token])
225
223
  } catch (err) {
226
- this._logger.warn(`An error occurred while decoding icon for ${assetId}`, err.message)
224
+ this.#logger.warn(`An error occurred while decoding icon for ${assetId}`, err.message)
227
225
  }
228
226
 
229
227
  this.#setCache(key, token)
@@ -246,7 +244,7 @@ export class AssetsModule extends ExodusModule {
246
244
 
247
245
  return asset
248
246
  } catch (err) {
249
- this._logger.warn(`Add custom token ${assetId} error on ${baseAssetName}`, err.message)
247
+ this.#logger.warn(`Add custom token ${assetId} error on ${baseAssetName}`, err.message)
250
248
  throw err
251
249
  }
252
250
  }
@@ -263,7 +261,7 @@ export class AssetsModule extends ExodusModule {
263
261
  try {
264
262
  return await this.fetchToken(assetId, baseAssetName)
265
263
  } catch (err) {
266
- this._logger.warn('fetch custom tokens error:', err.message)
264
+ this.#logger.warn('fetch custom tokens error:', err.message)
267
265
  }
268
266
  })
269
267
  )
@@ -306,7 +304,7 @@ export class AssetsModule extends ExodusModule {
306
304
  if (isEmpty(tokens)) return
307
305
 
308
306
  const validTokens = tokensToAdd.filter(this.#validateCustomToken).map(normalizeToken)
309
- if (validTokens.length !== tokensToAdd.length) this._logger.warn('Invalid Custom Token schema')
307
+ if (validTokens.length !== tokensToAdd.length) this.#logger.warn('Invalid Custom Token schema')
310
308
 
311
309
  const { fetchedAndHandledTokens, added, updated } = this.#handleFetchedTokens(validTokens)
312
310
 
@@ -368,7 +366,7 @@ export class AssetsModule extends ExodusModule {
368
366
  )
369
367
  const validTokens = tokens.filter(this.#validateCustomToken)
370
368
 
371
- if (validTokens.length !== tokens.length) this._logger.warn('Invalid Custom Token schema')
369
+ if (validTokens.length !== tokens.length) this.#logger.warn('Invalid Custom Token schema')
372
370
 
373
371
  return validTokens.map((token) => {
374
372
  const asset = this.#getAssetFromAssetId(token.assetId, token.baseAssetName)
@@ -385,7 +383,7 @@ export class AssetsModule extends ExodusModule {
385
383
  const updatedTokens = await this.#fetch('updates', assetVersions, 'tokens')
386
384
  const validatedTokens = updatedTokens.filter(this.#validateCustomToken).map(normalizeToken)
387
385
  if (validatedTokens.length !== updatedTokens.length) {
388
- this._logger.warn('Invalid Custom Token schema')
386
+ this.#logger.warn('Invalid Custom Token schema')
389
387
  }
390
388
 
391
389
  await this.#iconsStorage.storeIcons(validatedTokens)
@@ -408,11 +406,6 @@ export class AssetsModule extends ExodusModule {
408
406
  }
409
407
 
410
408
  #flushChanges = ({ added = [], updated = [], disabled = [] } = {}) => {
411
- // TODO: remove these once all consumers are refactored
412
- if (added.length > 0) this.emit('assets-add', added)
413
- if (updated.length > 0) this.emit('assets-update', updated)
414
- if (disabled.length > 0) this.emit('assets-disable', disabled)
415
-
416
409
  if (added.length + updated.length + disabled.length === 0) {
417
410
  return
418
411
  }
@@ -446,7 +439,7 @@ export class AssetsModule extends ExodusModule {
446
439
  if (asset) return { asset, isAdded: false }
447
440
 
448
441
  const { name } = this.#registry.addCustomToken(token) // add to `#/assets`
449
- this._logger.log('Custom token added:', name)
442
+ this.#logger.log('Custom token added:', name)
450
443
  return { asset: this.getAsset(name), isAdded: true }
451
444
  }
452
445
 
@@ -464,7 +457,7 @@ export class AssetsModule extends ExodusModule {
464
457
  updated.push(asset)
465
458
  }
466
459
  } catch (err) {
467
- this._logger.warn('Handle fetched custom tokens error:', err.message)
460
+ this.#logger.warn('Handle fetched custom tokens error:', err.message)
468
461
  }
469
462
  }
470
463
 
@@ -475,7 +468,7 @@ export class AssetsModule extends ExodusModule {
475
468
  const baseAsset = this.getAsset(baseAssetName)
476
469
  if (!baseAsset.api.hasFeature('customTokens')) {
477
470
  const reason = `BUG: network ${baseAsset.name} does not support custom tokens.`
478
- this._logger.warn(reason)
471
+ this.#logger.warn(reason)
479
472
  throw new Error(reason)
480
473
  }
481
474
  }
package/module/index.js CHANGED
@@ -15,6 +15,8 @@ const assetsModuleDefinition = {
15
15
  'validateCustomToken?',
16
16
  'config',
17
17
  'fetch',
18
+ 'logger',
19
+ 'assetRegistry?', // temporary
18
20
  ],
19
21
  }
20
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/assets-feature",
3
- "version": "3.8.0",
3
+ "version": "4.0.0",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Assets module, clients and apis",
6
6
  "main": "index.js",
@@ -42,7 +42,7 @@
42
42
  "devDependencies": {
43
43
  "@exodus/assets": "^8.0.95",
44
44
  "@exodus/atoms": "^6.0.1",
45
- "@exodus/available-assets": "^7.0.0",
45
+ "@exodus/available-assets": "^8.0.0",
46
46
  "@exodus/bitcoin-meta": "^1.0.1",
47
47
  "@exodus/bitcoin-plugin": "^1.0.3",
48
48
  "@exodus/bitcoinregtest-plugin": "^1.0.3",
@@ -63,5 +63,5 @@
63
63
  "msw": "^2.0.0",
64
64
  "redux": "^4.0.0"
65
65
  },
66
- "gitHead": "4480f8501a837520fd19403ea1cffb1e3d7ac9d8"
66
+ "gitHead": "6fe52cd3aa2ffc3fa76d2334228a0dcd02dc9e2e"
67
67
  }
package/plugin/index.js CHANGED
@@ -20,7 +20,6 @@ const createAssetsPlugin = ({
20
20
  }
21
21
 
22
22
  port.emit('assets', payload)
23
- port.emit('assets-load', payload) // legacy to be removed
24
23
  }
25
24
 
26
25
  const observers = [