@exodus/balances 6.0.1 → 7.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,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
+ ## [7.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@6.1.0...@exodus/balances@7.0.0) (2023-07-21)
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ - balances module (#2756)
11
+
12
+ ### Features
13
+
14
+ - **balances:** has balance atom ([#2761](https://github.com/ExodusMovement/exodus-hydra/issues/2761)) ([1b9e51e](https://github.com/ExodusMovement/exodus-hydra/commit/1b9e51e3074e368840832fedc7da45298d442347))
15
+ - move balances to feature dir ([#2757](https://github.com/ExodusMovement/exodus-hydra/issues/2757)) ([8d0729a](https://github.com/ExodusMovement/exodus-hydra/commit/8d0729a470e9f1329814cca7e1ceb01bbc5db4b6))
16
+
17
+ ## [6.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@6.0.1...@exodus/balances@6.1.0) (2023-07-19)
18
+
19
+ ### Features
20
+
21
+ - capture #setWalletAccounts ([#2723](https://github.com/ExodusMovement/exodus-hydra/issues/2723)) ([af8c52b](https://github.com/ExodusMovement/exodus-hydra/commit/af8c52b6f4623e490d470b6185fafb4b771d5bcc))
22
+ - emit errors from balances module ([#2718](https://github.com/ExodusMovement/exodus-hydra/issues/2718)) ([d150e55](https://github.com/ExodusMovement/exodus-hydra/commit/d150e555c76e9fedc3defb2023f8b161ce99c5f1))
23
+
6
24
  ## [6.0.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@6.0.0...@exodus/balances@6.0.1) (2023-06-21)
7
25
 
8
26
  **Note:** Version bump only for package @exodus/balances
@@ -0,0 +1,15 @@
1
+ import { compute } from '@exodus/atoms'
2
+ import { flatMap, map } from 'lodash'
3
+
4
+ // balancesAtom schema: { balances: { [walletAccount]: { [assetName]: { balance: NumberUnit } } } } }
5
+
6
+ const createHasBalanceAtom = ({ balancesAtom }) => {
7
+ const selector = ({ balances } = {}) => {
8
+ const numberUnits = flatMap(balances, (value) => map(value, 'balance'))
9
+ return numberUnits.some((numberUnit) => (numberUnit ? !numberUnit.isZero : false))
10
+ }
11
+
12
+ return compute({ atom: balancesAtom, selector })
13
+ }
14
+
15
+ export default createHasBalanceAtom
package/atoms/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import createBalancesAtom from './balances'
2
+ import createHasBalanceAtom from './has-balance'
2
3
 
3
4
  export const balancesAtomDefinition = {
4
5
  id: 'balancesAtom',
@@ -6,3 +7,10 @@ export const balancesAtomDefinition = {
6
7
  factory: createBalancesAtom,
7
8
  dependencies: [],
8
9
  }
10
+
11
+ export const hasBalanceAtomDefinition = {
12
+ id: 'hasBalanceAtom',
13
+ type: 'atom',
14
+ factory: createHasBalanceAtom,
15
+ dependencies: ['balancesAtom'],
16
+ }
package/index.js ADDED
@@ -0,0 +1,18 @@
1
+ import balancesDefinition from './module'
2
+ import { balancesAtomDefinition, hasBalanceAtomDefinition } from './atoms'
3
+
4
+ const balances = () => {
5
+ return {
6
+ id: 'balances',
7
+ definitions: [
8
+ {
9
+ definition: balancesDefinition,
10
+ writesAtoms: ['balancesAtom'],
11
+ },
12
+ { definition: balancesAtomDefinition },
13
+ { definition: hasBalanceAtomDefinition },
14
+ ],
15
+ }
16
+ }
17
+
18
+ export default balances
package/module/index.js CHANGED
@@ -53,10 +53,27 @@ class Balances extends ExodusModule {
53
53
  this.#pushIntoSharedQueue(() => fn.apply(this, args))
54
54
  }
55
55
 
56
+ const captureErrors =
57
+ (fn, name) =>
58
+ async (...args) => {
59
+ try {
60
+ return await fn(...args)
61
+ } catch (error) {
62
+ this.emit('error', { fn: name, error })
63
+ throw error
64
+ }
65
+ }
66
+
56
67
  // these share a queue
57
68
  this.#updateAssetSource = shareQueue(this.#updateAssetSource)
58
69
  this.#handleTxLogUpdate = shareQueue(this.#handleTxLogUpdate)
59
70
  this.#recompute = shareQueue(this.#recompute)
71
+ this.#getBalancesForAssetSource = captureErrors(
72
+ this.#getBalancesForAssetSource,
73
+ 'getBalancesForAssetSource'
74
+ )
75
+
76
+ this.#setWalletAccounts = captureErrors(this.#setWalletAccounts, 'setWalletAccounts')
60
77
 
61
78
  blockchainMetadata.once('load-wallet-accounts', () => {
62
79
  // eslint-disable-next-line hydra/module-side-effects
@@ -172,7 +189,7 @@ class Balances extends ExodusModule {
172
189
  this.#balances[walletAccount] = await this.#getBalancesForWalletAccount({ walletAccount })
173
190
  }
174
191
 
175
- #setWalletAccounts = (walletAccounts) => {
192
+ #setWalletAccounts = async (walletAccounts) => {
176
193
  const added = difference(walletAccounts, this.#walletAccounts)
177
194
  const removed = difference(this.#walletAccounts, walletAccounts)
178
195
  if (added.length === 0 && removed.length === 0) return
@@ -188,7 +205,7 @@ class Balances extends ExodusModule {
188
205
 
189
206
  if (added.length > 0) {
190
207
  this._logger.log('recomputing after adding walletAccounts', added)
191
- this.#recompute({ walletAccounts: added })
208
+ await this.#recompute({ walletAccounts: added })
192
209
  } else {
193
210
  this.#flush()
194
211
  }
@@ -317,7 +334,7 @@ class Balances extends ExodusModule {
317
334
 
318
335
  const createBalances = (opts) => new Balances(opts)
319
336
 
320
- export default {
337
+ const balancesDefinition = {
321
338
  id: MODULE_ID,
322
339
  type: 'module',
323
340
  factory: createBalances,
@@ -330,3 +347,5 @@ export default {
330
347
  'balancesAtom',
331
348
  ],
332
349
  }
350
+
351
+ export default balancesDefinition
package/package.json CHANGED
@@ -1,31 +1,33 @@
1
1
  {
2
2
  "name": "@exodus/balances",
3
- "version": "6.0.1",
4
- "description": "balances",
5
- "author": "Exodus Movement Inc",
3
+ "version": "7.0.0",
4
+ "description": "Tracks crypto balances across enabled wallet accounts.",
5
+ "author": "Exodus Movement Inc.",
6
6
  "license": "UNLICENSED",
7
7
  "scripts": {
8
8
  "test": "jest",
9
9
  "lint": "eslint . --ignore-path ../../.gitignore",
10
10
  "lint:fix": "yarn lint --fix"
11
11
  },
12
+ "main": "index.js",
12
13
  "files": [
14
+ "index.js",
13
15
  "module",
14
16
  "atoms",
15
17
  "README.md",
16
18
  "CHANGELOG.md",
17
- "!**/__tests__"
19
+ "!**/__tests__/**"
18
20
  ],
19
21
  "repository": {
20
22
  "type": "git",
21
23
  "url": "git+https://github.com/ExodusMovement/exodus-hydra.git"
22
24
  },
23
- "homepage": "https://github.com/ExodusMovement/exodus-hydra/tree/master/modules/balances",
25
+ "homepage": "https://github.com/ExodusMovement/exodus-hydra/tree/master/features/balances",
24
26
  "bugs": {
25
27
  "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abalances"
26
28
  },
27
29
  "dependencies": {
28
- "@exodus/atoms": "^5.0.0",
30
+ "@exodus/atoms": "^5.2.2",
29
31
  "@exodus/basic-utils": "^2.0.0",
30
32
  "@exodus/currency": "^2.1.2",
31
33
  "@exodus/module": "^1.1.0",
@@ -40,9 +42,9 @@
40
42
  "@exodus/models": "^8.9.0",
41
43
  "@exodus/storage-memory": "*",
42
44
  "@exodus/wallet-accounts": "^9.1.0",
43
- "eslint": "^8.33.0",
45
+ "eslint": "^8.44.0",
44
46
  "events": "^3.3.0",
45
47
  "jest": "^29.1.2"
46
48
  },
47
- "gitHead": "f0a3d249bf994a6d5c106a106b5e4b2b6c61a6e8"
49
+ "gitHead": "c85a6f44669c8d173606c3eb89fceaf650365df7"
48
50
  }