@exodus/assets-feature 5.11.1 → 5.11.2

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,12 @@
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
+ ## [5.11.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@5.11.1...@exodus/assets-feature@5.11.2) (2024-09-05)
7
+
8
+ ### Bug Fixes
9
+
10
+ - addRemoteTokens can add builtIn token as CT ([#8879](https://github.com/ExodusMovement/exodus-hydra/issues/8879)) ([2597011](https://github.com/ExodusMovement/exodus-hydra/commit/2597011ed1cd88755d174953e90afe467ecaa689))
11
+
6
12
  ## [5.11.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@5.11.0...@exodus/assets-feature@5.11.1) (2024-08-26)
7
13
 
8
14
  ### Bug Fixes
@@ -5,7 +5,7 @@ import {
5
5
  CT_STATUS as STATUS,
6
6
  CT_UPDATEABLE_PROPERTIES,
7
7
  } from '@exodus/assets'
8
- import { mapValues, pick, pickBy } from '@exodus/basic-utils'
8
+ import { keyBy, mapValues, partition, pick, pickBy } from '@exodus/basic-utils'
9
9
  // eslint-disable-next-line @exodus/restricted-imports/prefer-basic-utils
10
10
  import lodash from 'lodash'
11
11
  import assert from 'minimalistic-assert'
@@ -19,7 +19,7 @@ import {
19
19
  import { getAssetFromAssetId, getFetchErrorMessage, isDisabledCustomToken } from './utils.js'
20
20
  import createFetchival from '@exodus/fetch/create-fetchival'
21
21
 
22
- const { get, isEmpty, keyBy, once } = lodash
22
+ const { get, isEmpty, once } = lodash
23
23
 
24
24
  const FILTERED_FIELDS = [
25
25
  'assetId',
@@ -304,20 +304,27 @@ export class AssetsModule {
304
304
  this.#assertCustomTokensStorageSupported()
305
305
 
306
306
  const assets = this.getAssets()
307
- const tokenNamesToFetch = tokenNames.filter((tokenName) => !assets[tokenName])
307
+ const [tokenNamesToUpdate, tokenNamesToFetch] = partition(
308
+ tokenNames,
309
+ (tokenName) => !!assets[tokenName]
310
+ )
308
311
 
309
- const tokensToAdd =
312
+ const fetchedTokens =
310
313
  tokenNamesToFetch.length > 0
311
314
  ? await this.#fetch('tokens', { tokenNames: tokenNamesToFetch }, 'tokens')
312
315
  : []
313
- const validTokensToAdd = tokensToAdd.filter(this.#validateCustomToken).map(normalizeToken)
314
- if (validTokensToAdd.length !== tokensToAdd.length)
316
+
317
+ const validTokens = fetchedTokens.filter(this.#validateCustomToken).map(normalizeToken)
318
+ if (validTokens.length !== fetchedTokens.length)
315
319
  this.#logger.warn('Invalid Custom Token schema')
316
320
 
317
- const tokensToUpdate = tokenNames
318
- .map((tokenName) => assets[tokenName])
319
- .filter((token) => !!token)
320
- const tokens = [...validTokensToAdd, ...tokensToUpdate]
321
+ const tokens = tokenNamesToUpdate.map((tokenName) => assets[tokenName])
322
+
323
+ validTokens.forEach((token) => {
324
+ // replace fetched CT with existing built-in token if found by assetId
325
+ const asset = token.assetId && this.#getAssetFromAssetId(token.assetId, token.baseAssetName)
326
+ tokens.push(asset ?? token)
327
+ })
321
328
 
322
329
  if (isEmpty(tokens)) return
323
330
 
@@ -455,7 +462,7 @@ export class AssetsModule {
455
462
  const asset = this.getAsset(token.name)
456
463
  if (asset) return { asset, isAdded: false }
457
464
 
458
- const { name } = this.#registry.addCustomToken(token) // add to `#/assets`
465
+ const { name } = this.#registry.addCustomToken(token) // add to registry
459
466
  this.#logger.log('Custom token added:', name)
460
467
  return { asset: this.getAsset(name), isAdded: true }
461
468
  }
package/module/utils.js CHANGED
@@ -1,13 +1,16 @@
1
1
  import { CT_STATUS as STATUS } from '@exodus/assets'
2
2
  import lodash from 'lodash'
3
+ import assert from 'minimalistic-assert'
3
4
 
4
5
  const { get } = lodash
5
6
 
6
7
  const BLACKLISTED_ERRORS = [/Cannot destructure property 'owner'/]
7
8
 
8
9
  export const getAssetFromAssetId = (assets, assetId, baseAssetName) => {
10
+ assert(assetId, 'getAssetFromAssetId(): assetId is required')
11
+ assert(baseAssetName, 'getAssetFromAssetId(): baseAssetName is required')
9
12
  // ignore letter-case for assets that support checksummed addresses
10
- assetId = assetId?.toLowerCase()
13
+ assetId = assetId.toLowerCase()
11
14
  return Object.values(assets).find(
12
15
  (asset) => assetId === asset.assetId?.toLowerCase() && baseAssetName === asset.baseAsset.name
13
16
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/assets-feature",
3
- "version": "5.11.1",
3
+ "version": "5.11.2",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Assets module, clients and apis",
6
6
  "type": "module",
@@ -62,14 +62,14 @@
62
62
  "@exodus/osmosis-plugin": "^1.0.0",
63
63
  "@exodus/public-key-provider": "^2.5.0",
64
64
  "@exodus/public-key-store": "^1.2.2",
65
- "@exodus/redux-dependency-injection": "^4.0.1",
65
+ "@exodus/redux-dependency-injection": "^4.0.2",
66
66
  "@exodus/storage-memory": "^2.2.0",
67
- "@exodus/wallet-accounts": "^16.10.0",
67
+ "@exodus/wallet-accounts": "^16.10.1",
68
68
  "@exodus/wild-emitter": "^1.0.0",
69
69
  "bip39": "^3.1.0",
70
70
  "events": "^3.3.0",
71
71
  "msw": "^2.0.0",
72
72
  "redux": "^4.0.0"
73
73
  },
74
- "gitHead": "08a439da808ec039338b0ca1b448b39267d131fb"
74
+ "gitHead": "a758fd2522b6a4b638f10a340cf87a6d64c814de"
75
75
  }