@exodus/balances 5.0.0 → 6.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,17 @@
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
+ ## [6.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@5.0.0...@exodus/balances@6.0.0) (2023-04-25)
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ - replace emit with atom in balances module (#1349)
11
+
12
+ ### Features
13
+
14
+ - add balancesAtom definition ([#1362](https://github.com/ExodusMovement/exodus-hydra/issues/1362)) ([4d126ef](https://github.com/ExodusMovement/exodus-hydra/commit/4d126efef79655178ec1e1faf65b347497ad8647))
15
+ - replace emit with atom in balances module ([#1349](https://github.com/ExodusMovement/exodus-hydra/issues/1349)) ([f9110f8](https://github.com/ExodusMovement/exodus-hydra/commit/f9110f8e9e76b8b199bc4d40461cb1bed3a5be1e))
16
+
6
17
  ## [5.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@4.0.0...@exodus/balances@5.0.0) (2023-03-14)
7
18
 
8
19
  ### ⚠ BREAKING CHANGES
@@ -0,0 +1,5 @@
1
+ import { createInMemoryAtom } from '@exodus/atoms'
2
+
3
+ const createBalancesAtom = () => createInMemoryAtom()
4
+
5
+ export default createBalancesAtom
package/atoms/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import createBalancesAtom from './balances'
2
+
3
+ export const balancesAtomDefinition = {
4
+ id: 'balancesAtom',
5
+ type: 'atom',
6
+ factory: createBalancesAtom,
7
+ dependencies: [],
8
+ }
package/module/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { isNumberUnit } from '@exodus/currency'
2
2
  import { TxSet } from '@exodus/models'
3
3
  import ExodusModule from '@exodus/module'
4
- import { cloneDeepWith, difference, isEmpty, merge, set, zipObject } from 'lodash'
4
+ import { cloneDeepWith, isEmpty, merge, set, zipObject } from 'lodash'
5
+ import { difference, flattenToPaths } from '@exodus/basic-utils'
5
6
  import makeConcurrent from 'make-concurrent'
6
7
  import getConfirmedBalance from './confirmed-balance'
7
- import { flattenToPaths } from '@exodus/basic-utils'
8
8
 
9
9
  const cloneBalances = (balances) =>
10
10
  cloneDeepWith(balances, (val) => {
@@ -23,11 +23,12 @@ class Balances extends ExodusModule {
23
23
  #assetsModule
24
24
  #blockchainMetadata
25
25
  #balanceFields
26
- #walletAccounts = null // string[]
26
+ #walletAccounts = [] // string[]
27
27
  #ready = false
28
28
 
29
29
  #oldBalances = Object.create(null)
30
30
  #balances = Object.create(null)
31
+ #balancesAtom
31
32
 
32
33
  constructor({
33
34
  assetsModule,
@@ -35,12 +36,14 @@ class Balances extends ExodusModule {
35
36
  walletAccountsAtom,
36
37
  config: { balanceFields },
37
38
  logger,
39
+ balancesAtom,
38
40
  }) {
39
41
  super({ name: MODULE_ID, logger })
40
42
 
41
43
  this.#assetsModule = assetsModule
42
44
  this.#blockchainMetadata = blockchainMetadata
43
45
  this.#balanceFields = balanceFields
46
+ this.#balancesAtom = balancesAtom
44
47
 
45
48
  const shareQueue =
46
49
  (fn) =>
@@ -189,7 +192,7 @@ class Balances extends ExodusModule {
189
192
  this._logger.log('recomputing after adding walletAccounts', added)
190
193
  this.#recompute({ walletAccounts: added })
191
194
  } else {
192
- this.sync()
195
+ this.#flush()
193
196
  }
194
197
  }
195
198
 
@@ -268,7 +271,7 @@ class Balances extends ExodusModule {
268
271
  })
269
272
 
270
273
  const changes = Object.create(null)
271
- for (let subAssetName in newBalances) {
274
+ for (const subAssetName in newBalances) {
272
275
  const { currency } = this.#getAsset(subAssetName)
273
276
  const newAssetBalances = newBalances?.[subAssetName]
274
277
  // e.g. totalBalance or spendableBalance
@@ -288,23 +291,23 @@ class Balances extends ExodusModule {
288
291
  }
289
292
  }
290
293
 
291
- if (!isEmpty(changes)) this.sync({ changes })
294
+ if (!isEmpty(changes)) this.#flush({ changes })
292
295
  }
293
296
 
294
297
  #recompute = async ({ walletAccounts = this.#walletAccounts } = {}) => {
295
298
  this.#reset({ walletAccounts })
296
299
  await Promise.all(walletAccounts.map((walletAccount) => this.#load({ walletAccount })))
297
- this.sync()
300
+ this.#flush()
298
301
  }
299
302
 
300
- sync = ({ changes } = {}) => {
303
+ #flush = ({ changes } = {}) => {
301
304
  const oldBalances = this.#oldBalances
302
305
  const balances = cloneBalances(this.#balances)
303
306
 
304
307
  if (Object.keys(balances).length === 0) return // wait till `load` finished
305
308
 
306
309
  this._logger.log('balances updated')
307
- this.emit('balances', {
310
+ this.#balancesAtom.set({
308
311
  balances,
309
312
  oldBalances,
310
313
  changes,
@@ -320,5 +323,12 @@ export default {
320
323
  id: MODULE_ID,
321
324
  type: 'module',
322
325
  factory: createBalances,
323
- dependencies: ['assetsModule', 'blockchainMetadata', 'walletAccountsAtom', 'config', 'logger'],
326
+ dependencies: [
327
+ 'assetsModule',
328
+ 'blockchainMetadata',
329
+ 'walletAccountsAtom',
330
+ 'config',
331
+ 'logger',
332
+ 'balancesAtom',
333
+ ],
324
334
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/balances",
3
- "version": "5.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "balances",
5
5
  "author": "Exodus Movement Inc",
6
6
  "license": "UNLICENSED",
@@ -25,7 +25,8 @@
25
25
  "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abalances"
26
26
  },
27
27
  "dependencies": {
28
- "@exodus/basic-utils": "^1.3.0",
28
+ "@exodus/atoms": "^3.5.0",
29
+ "@exodus/basic-utils": "^2.0.0",
29
30
  "@exodus/currency": "^2.1.2",
30
31
  "@exodus/module": "^1.1.0",
31
32
  "lodash": "^4.17.21",
@@ -35,7 +36,6 @@
35
36
  "@exodus/blockchain-metadata": "^6.0.0"
36
37
  },
37
38
  "devDependencies": {
38
- "@exodus/atoms": "^3.0.0",
39
39
  "@exodus/blockchain-metadata": "^8.0.0",
40
40
  "@exodus/models": "^8.9.0",
41
41
  "@exodus/storage-memory": "*",
@@ -44,5 +44,5 @@
44
44
  "events": "^3.3.0",
45
45
  "jest": "^29.1.2"
46
46
  },
47
- "gitHead": "4f1bec27b7ea7e32681ef928a4f7149175817560"
47
+ "gitHead": "6ecd3fa19c39610e7147b2d060ea64709f6c8c6e"
48
48
  }