@exodus/assets-feature 3.1.1 → 3.2.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,22 @@
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.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@3.1.2...@exodus/assets-feature@3.2.0) (2023-10-03)
7
+
8
+ ### Features
9
+
10
+ - enhance ACI with features from mobile ([#4299](https://github.com/ExodusMovement/exodus-hydra/issues/4299)) ([dcdf2ea](https://github.com/ExodusMovement/exodus-hydra/commit/dcdf2eadd85104460d31837b9300728a85c1c0b8))
11
+
12
+ ### Bug Fixes
13
+
14
+ - only search supported networks by default ([#4241](https://github.com/ExodusMovement/exodus-hydra/issues/4241)) ([17d2f86](https://github.com/ExodusMovement/exodus-hydra/commit/17d2f8681016c7d260d8905f2d5d8271815486f1))
15
+
16
+ ## [3.1.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/assets-feature@3.1.1...@exodus/assets-feature@3.1.2) (2023-09-28)
17
+
18
+ ### Bug Fixes
19
+
20
+ - factory does not pass all parameters to module ([#4264](https://github.com/ExodusMovement/exodus-hydra/issues/4264)) ([9267fdd](https://github.com/ExodusMovement/exodus-hydra/commit/9267fddeb6e0e53ba519273c6c7d48fb2d574305))
21
+
6
22
  ## [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
23
 
8
24
  ### Bug Fixes
@@ -32,6 +32,8 @@ class AssetClientInterface {
32
32
  }
33
33
  }
34
34
 
35
+ // txHistory interface
36
+
35
37
  getTxHistory = async ({ assetName, walletAccount }) => {
36
38
  return this.blockchainMetadata.getTxLog({ assetName, walletAccount })
37
39
  }
@@ -45,47 +47,70 @@ class AssetClientInterface {
45
47
  }
46
48
 
47
49
  updateTxLogAndNotifyBatch = ({
50
+ assetName,
51
+ walletAccount,
52
+ txs,
53
+ refresh = false,
54
+ batch = this.blockchainMetadata.batch(),
55
+ }) => {
56
+ return refresh
57
+ ? batch.overwriteTxs({ assetName, walletAccount, txs })
58
+ : batch.updateTxs({ assetName, walletAccount, txs })
59
+ }
60
+
61
+ removeTxLog = async (params) => {
62
+ return this.removeTxLogBatch(params).commit()
63
+ }
64
+
65
+ removeTxLogBatch = ({
48
66
  assetName,
49
67
  walletAccount,
50
68
  txs,
51
69
  batch = this.blockchainMetadata.batch(),
52
70
  }) => {
53
- return batch.updateTxs({ assetName, walletAccount, txs })
71
+ return batch.removeTxs({ assetName, walletAccount, txs })
54
72
  }
55
73
 
74
+ // accountState interface
75
+
56
76
  async getAccountState({ assetName, walletAccount }) {
57
77
  return this.blockchainMetadata.getAccountState({ assetName, walletAccount })
58
78
  }
59
79
 
60
- async updateAccountState(params) {
61
- return this.updateAccountStateBatch(params).commit()
80
+ async updateAccountState({ assetName, walletAccount, ...params }) {
81
+ let { accountState } = params
82
+ if (!accountState) {
83
+ accountState = await this.getAccountState({ assetName, walletAccount })
84
+ }
85
+
86
+ return this.updateAccountStateBatch({
87
+ ...params,
88
+ assetName,
89
+ walletAccount,
90
+ accountState,
91
+ }).commit()
62
92
  }
63
93
 
64
94
  updateAccountStateBatch = ({
65
95
  assetName,
66
96
  walletAccount,
67
97
  newData,
98
+ accountState,
68
99
  batch = this.blockchainMetadata.batch(),
69
100
  }) => {
70
101
  if (!isEmpty(newData)) {
71
102
  return batch.updateAccountState({ assetName, walletAccount, newData })
72
103
  }
73
104
 
74
- return batch
75
- }
105
+ // merge mem to keep the previous accountMem behavior
106
+ if (newData.mem && (!accountState || accountState.mem)) {
107
+ newData = { ...newData, mem: { ...accountState?.mem, ...newData.mem } }
108
+ }
76
109
 
77
- removeTxLog = async (params) => {
78
- return this.removeTxLogBatch(params).commit()
110
+ return batch
79
111
  }
80
112
 
81
- removeTxLogBatch = ({
82
- assetName,
83
- walletAccount,
84
- txs,
85
- batch = this.blockchainMetadata.batch(),
86
- }) => {
87
- return batch.removeTxs({ assetName, walletAccount, txs })
88
- }
113
+ // walletAccounts interface
89
114
 
90
115
  async getWalletAccounts({ assetName }) {
91
116
  // In the future, the list of wallets may be different based on the provided assets
@@ -94,6 +119,8 @@ class AssetClientInterface {
94
119
  return Object.keys(await this.#enabledWalletAccountsAtom.get())
95
120
  }
96
121
 
122
+ // assets interface
123
+
97
124
  async getAssetsForNetwork({ baseAssetName }) {
98
125
  const availableAssetNames = new Set(await this.#availableAssetNamesAtom.get())
99
126
  return pickBy(
@@ -102,6 +129,8 @@ class AssetClientInterface {
102
129
  )
103
130
  }
104
131
 
132
+ // configParams interface
133
+
105
134
  async getConfirmationsNumber({ assetName }) {
106
135
  const baseAsset = this.assetsModule.getAsset(assetName).baseAsset
107
136
  return baseAsset.api?.getConfirmationsNumber ? baseAsset.api.getConfirmationsNumber() : 1
@@ -116,12 +145,20 @@ class AssetClientInterface {
116
145
  return this.feeMonitors.getFeeData({ assetName: baseAssetName })
117
146
  }
118
147
 
148
+ getFeeConfig = async ({ assetName }) => {
149
+ return this.feeMonitors.getFeeData({ assetName })
150
+ }
151
+
152
+ // batch interface
153
+
119
154
  // The interface consumer does not need to know the structure of the returned batch object, just
120
155
  // that it needs to be passed along wherever operations need to be batched.
121
156
  createOperationsBatch = () => this.blockchainMetadata.batch()
122
157
 
123
158
  executeOperationsBatch = async (batch) => batch.commit()
124
159
 
160
+ // addresses interface
161
+
125
162
  getPublicKey = async ({ assetName, walletAccount, addressIndex = 0, chainIndex = 0 }) => {
126
163
  const walletAccountInstance = await this.#getWalletAccount(walletAccount)
127
164
  return this.wallet.getPublicKey({
@@ -159,6 +196,7 @@ class AssetClientInterface {
159
196
 
160
197
  return [...addresses].map((address) => address.toString())
161
198
  }
199
+
162
200
  getChangeAddresses = async (opts) => {
163
201
  const addresses = await this.addressProvider.getChangeAddresses({
164
202
  ...opts,
@@ -191,13 +229,6 @@ class AssetClientInterface {
191
229
  // no op!! getUnusedAddressIndexes loads from tx log, not from storage
192
230
  }
193
231
 
194
- signTransaction = async ({ assetName, unsignedTx, walletAccount }) => {
195
- // eslint-disable-next-line unicorn/no-await-expression-member
196
- const accountIndex = (await this.#getWalletAccount(walletAccount)).index
197
- const baseAssetName = this.assetsModule.getAsset(assetName).baseAsset.name
198
- return this.wallet.signTransaction({ baseAssetName, unsignedTx, accountIndex })
199
- }
200
-
201
232
  getNextChangeAddress = async ({ assetName, walletAccount }) => {
202
233
  return this.addressProvider.getUnusedAddress({
203
234
  assetName,
@@ -206,8 +237,13 @@ class AssetClientInterface {
206
237
  })
207
238
  }
208
239
 
209
- getFeeConfig = async ({ assetName }) => {
210
- return this.feeMonitors.getFeeData({ assetName })
240
+ // wallet interface
241
+
242
+ signTransaction = async ({ assetName, unsignedTx, walletAccount }) => {
243
+ // eslint-disable-next-line unicorn/no-await-expression-member
244
+ const accountIndex = (await this.#getWalletAccount(walletAccount)).index
245
+ const baseAssetName = this.assetsModule.getAsset(assetName).baseAsset.name
246
+ return this.wallet.signTransaction({ baseAssetName, unsignedTx, accountIndex })
211
247
  }
212
248
  }
213
249
 
@@ -74,12 +74,13 @@ export class AssetsModule extends ExodusModule {
74
74
  iconsStorage,
75
75
  assetRegistry, // temporary
76
76
  assetPlugins,
77
- combinedAssetsList,
77
+ combinedAssetsList = [],
78
78
  globalAssetRegistry, // temporary
79
79
  validateCustomToken = () => true,
80
80
  config = {},
81
81
  }) {
82
82
  super({ name: 'AssetsModule' })
83
+
83
84
  this.#storage = storage
84
85
  this.#isExternalRegistry = !!assetRegistry
85
86
  this.#registry = this.#isExternalRegistry ? assetRegistry : initialAssetRegistry
@@ -329,11 +330,16 @@ export class AssetsModule extends ExodusModule {
329
330
  }
330
331
 
331
332
  searchTokens = async ({ baseAssetName, lifecycleStatus, query, excludeTags = ['offensive'] }) => {
333
+ assert(
334
+ !baseAssetName || typeof baseAssetName === 'string',
335
+ 'searchTokens(): baseAssetName must be a string if supplied'
336
+ )
332
337
  baseAssetName && this.#assertSupportsCustomTokens(baseAssetName)
333
338
 
339
+ const baseAssetNames = baseAssetName ? [baseAssetName] : this.#getCustomTokensNetworkNames()
334
340
  const tokens = await this.#fetch(
335
341
  'search',
336
- { baseAssetName, lifecycleStatus, query, excludeTags },
342
+ { baseAssetName: baseAssetNames, lifecycleStatus, query, excludeTags },
337
343
  'tokens'
338
344
  )
339
345
  const validTokens = tokens.filter(this.#validateCustomToken).map(normalizeToken)
@@ -343,6 +349,11 @@ export class AssetsModule extends ExodusModule {
343
349
  return validTokens
344
350
  }
345
351
 
352
+ #getCustomTokensNetworkNames = () =>
353
+ this.getBaseAssetNames().filter((assetName) =>
354
+ this.getAsset(assetName).api?.hasFeature?.('customTokens')
355
+ )
356
+
346
357
  #fetchUpdates = async (assetVersions) => {
347
358
  const updatedTokens = await this.#fetch('updates', assetVersions, 'tokens')
348
359
  const validatedTokens = updatedTokens.filter(this.#validateCustomToken).map(normalizeToken)
package/module/index.js CHANGED
@@ -2,23 +2,7 @@
2
2
  import globalAssetRegistry from '@exodus/assets' // this is deprecated, do not use for any other purpose. Remove when we have @exodus/models v10.
3
3
  import AssetsModule from './assets-module'
4
4
 
5
- const createAssetsModule = ({
6
- storage,
7
- iconsStorage,
8
- assetPlugins,
9
- combinedAssetsList = [],
10
- validateCustomToken,
11
- config,
12
- }) =>
13
- new AssetsModule({
14
- storage,
15
- iconsStorage,
16
- globalAssetRegistry,
17
- assetPlugins,
18
- combinedAssetsList,
19
- validateCustomToken,
20
- config,
21
- })
5
+ const createAssetsModule = (props) => new AssetsModule({ ...props, globalAssetRegistry })
22
6
 
23
7
  const assetsModuleDefinition = {
24
8
  id: 'assetsModule',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/assets-feature",
3
- "version": "3.1.1",
3
+ "version": "3.2.0",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Assets module, clients and apis",
6
6
  "main": "index.js",
@@ -41,8 +41,8 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@exodus/assets": "^8.0.95",
44
- "@exodus/atoms": "^5.7.0",
45
- "@exodus/available-assets": "^5.1.1",
44
+ "@exodus/atoms": "^5.7.1",
45
+ "@exodus/available-assets": "^6.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",
@@ -55,12 +55,12 @@
55
55
  "@exodus/osmosis-plugin": "^1.0.0",
56
56
  "@exodus/redux-dependency-injection": "^3.0.0",
57
57
  "@exodus/storage-memory": "^2.1.1",
58
- "@exodus/wallet-accounts": "^14.0.0",
58
+ "@exodus/wallet-accounts": "^14.1.0",
59
59
  "@exodus/wild-emitter": "^1.0.0",
60
60
  "eslint": "^8.44.0",
61
61
  "events": "^3.3.0",
62
62
  "jest": "^29.1.2",
63
63
  "redux": "^4.0.0"
64
64
  },
65
- "gitHead": "c934b363c277eab13913053034e3e68d15650de9"
65
+ "gitHead": "423c1e963708c681fe11ad396afe65f9f956336f"
66
66
  }