@exodus/balances 13.0.1 → 13.1.1

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
+ ## [13.1.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.1.0...@exodus/balances@13.1.1) (2024-04-09)
7
+
8
+ ### Bug Fixes
9
+
10
+ - don't recompute if asset already exist in balances ([#6410](https://github.com/ExodusMovement/exodus-hydra/issues/6410)) ([f7160cc](https://github.com/ExodusMovement/exodus-hydra/commit/f7160ccf90deb046a12f23f9f42bd78e74bb2859))
11
+
12
+ ## [13.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.0.1...@exodus/balances@13.1.0) (2024-04-09)
13
+
14
+ ### Features
15
+
16
+ - asset-names-with-balance atom ([#6406](https://github.com/ExodusMovement/exodus-hydra/issues/6406)) ([f006357](https://github.com/ExodusMovement/exodus-hydra/commit/f006357b81478fcb443d478d626cec89196f57cf))
17
+
18
+ ### Bug Fixes
19
+
20
+ - use `assetNamesWithBalanceAtomDefinition` ([#6425](https://github.com/ExodusMovement/exodus-hydra/issues/6425)) ([9b65a23](https://github.com/ExodusMovement/exodus-hydra/commit/9b65a2367778d50c877a5c235784ee47938d101a))
21
+
6
22
  ## [13.0.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.0.0...@exodus/balances@13.0.1) (2024-04-05)
7
23
 
8
24
  ### Bug Fixes
@@ -0,0 +1,40 @@
1
+ import { compute, dedupe } from '@exodus/atoms'
2
+
3
+ const setsAreEqual = (setA, setB) => {
4
+ if (setA.size !== setB.size) {
5
+ return false
6
+ }
7
+
8
+ for (const item of setA) {
9
+ if (!setB.has(item)) {
10
+ return false
11
+ }
12
+ }
13
+
14
+ return true
15
+ }
16
+
17
+ const createAssetNamesWithBalanceAtom = ({ balancesAtom }) => {
18
+ let previousValue = new Set()
19
+ const selector = ({ balances }) => {
20
+ const assetsWithBalances = new Set()
21
+
22
+ Object.values(balances).forEach((accountBalances) => {
23
+ Object.keys(accountBalances).forEach((assetName) => {
24
+ if (!accountBalances[assetName]?.balance.isZero) {
25
+ assetsWithBalances.add(assetName)
26
+ }
27
+ })
28
+ })
29
+
30
+ if (!setsAreEqual(assetsWithBalances, previousValue)) {
31
+ previousValue = assetsWithBalances
32
+ }
33
+
34
+ return previousValue
35
+ }
36
+
37
+ return dedupe(compute({ atom: balancesAtom, selector }))
38
+ }
39
+
40
+ export default createAssetNamesWithBalanceAtom
@@ -1,21 +1,8 @@
1
1
  import { compute } from '@exodus/atoms'
2
2
 
3
- const createAssetsWithBalanceCountAtom = ({ balancesAtom }) => {
4
- const selector = ({ balances }) => {
5
- const assetsWithBalances = new Set()
6
-
7
- Object.values(balances).forEach((accountBalances) => {
8
- Object.keys(accountBalances).forEach((assetName) => {
9
- if (!accountBalances[assetName]?.balance.isZero) {
10
- assetsWithBalances.add(assetName)
11
- }
12
- })
13
- })
14
-
15
- return assetsWithBalances.size
16
- }
17
-
18
- return compute({ atom: balancesAtom, selector })
3
+ const createAssetsWithBalanceCountAtom = ({ assetNamesWithBalanceAtom }) => {
4
+ const selector = (assetNamesWithBalance) => assetNamesWithBalance.size
5
+ return compute({ atom: assetNamesWithBalanceAtom, selector })
19
6
  }
20
7
 
21
8
  export default createAssetsWithBalanceCountAtom
package/atoms/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import createAssetNamesWithBalanceAtom from './asset-names-with-balance'
1
2
  import createAssetsWithBalanceCountAtom from './assets-with-balance-count'
2
3
  import createBalancesAtom from './balances'
3
4
  import createFundedWalletAccountsAtom from './funded-wallet-accounts'
@@ -24,9 +25,16 @@ export const fundedWalletAccountsAtomDefinition = {
24
25
  dependencies: ['balancesAtom', 'enabledWalletAccountsAtom'],
25
26
  }
26
27
 
28
+ export const assetNamesWithBalanceAtomDefinition = {
29
+ id: 'assetNamesWithBalanceAtom',
30
+ type: 'atom',
31
+ factory: createAssetNamesWithBalanceAtom,
32
+ dependencies: ['balancesAtom'],
33
+ }
34
+
27
35
  export const assetsWithBalanceCountAtomDefinition = {
28
36
  id: 'assetsWithBalanceCountAtom',
29
37
  type: 'atom',
30
38
  factory: createAssetsWithBalanceCountAtom,
31
- dependencies: ['balancesAtom'],
39
+ dependencies: ['assetNamesWithBalanceAtom'],
32
40
  }
package/index.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  hasBalanceAtomDefinition,
5
5
  fundedWalletAccountsAtomDefinition,
6
6
  assetsWithBalanceCountAtomDefinition,
7
+ assetNamesWithBalanceAtomDefinition,
7
8
  } from './atoms'
8
9
  import balancesReportDefinition from './report'
9
10
  import { balancesLifecyclePluginDefinition, balancesAnalyticsPluginDefinition } from './plugins'
@@ -32,6 +33,7 @@ const balances = (walletConfig) => {
32
33
  config,
33
34
  },
34
35
  { definition: balancesAtomDefinition },
36
+ { definition: assetNamesWithBalanceAtomDefinition },
35
37
  { definition: assetsWithBalanceCountAtomDefinition },
36
38
  {
37
39
  definition: hasBalanceAtomDefinition,
package/module/index.js CHANGED
@@ -82,6 +82,7 @@ class Balances extends ExodusModule {
82
82
  this.#updateAssetSource = shareQueue(this.#updateAssetSource)
83
83
  this.#handleTxLogUpdate = shareQueue(this.#handleTxLogUpdate)
84
84
  this.#recompute = shareQueue(this.#recompute)
85
+ this.#onAssetsChanged = shareQueue(this.#onAssetsChanged)
85
86
  this.#getBalancesForAssetSource = captureErrors({
86
87
  fn: this.#getBalancesForAssetSource,
87
88
  name: 'getBalancesForAssetSource',
@@ -231,8 +232,15 @@ class Balances extends ExodusModule {
231
232
  }
232
233
  }
233
234
 
234
- #onAssetsChanged = async () => {
235
- // TODO: make this more efficient
235
+ #onAssetsChanged = async (added) => {
236
+ if (
237
+ added.every(({ name }) =>
238
+ this.#walletAccounts.every((walletAccount) => !!this.#balances?.[walletAccount]?.[name])
239
+ )
240
+ ) {
241
+ return
242
+ }
243
+
236
244
  this._logger.log('recomputing based on new assets list')
237
245
  this.#recompute()
238
246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/balances",
3
- "version": "13.0.1",
3
+ "version": "13.1.1",
4
4
  "description": "Tracks crypto balances across enabled wallet accounts.",
5
5
  "author": "Exodus Movement Inc.",
6
6
  "license": "UNLICENSED",
@@ -58,5 +58,5 @@
58
58
  "events": "^3.3.0",
59
59
  "redux": "^4.2.1"
60
60
  },
61
- "gitHead": "06d142f0b1d195bc7e0a13805becad04a1da5c52"
61
+ "gitHead": "09df4e0ee6f7185f8d715c6db5a64f1e5a8efd76"
62
62
  }
@@ -6,14 +6,14 @@ const createBalancesAnalyticsPlugin = ({
6
6
  let subscriptions = []
7
7
 
8
8
  const onStart = () => {
9
- analytics.requireDefaultProperties(['hasBalance', 'numberOfAssets'])
9
+ analytics.requireDefaultEventProperties(['hasBalance', 'numberOfAssets'])
10
10
 
11
11
  const unsubscribeBalanceAtom = hasBalanceAtom.observe((hasBalance) =>
12
- analytics.setDefaultProperties({ hasBalance })
12
+ analytics.setDefaultEventProperties({ hasBalance })
13
13
  )
14
14
 
15
15
  const unsubscribeBalanceCountAtom = assetsWithBalanceCountAtom.observe((numberOfAssets) =>
16
- analytics.setDefaultProperties({ numberOfAssets })
16
+ analytics.setDefaultEventProperties({ numberOfAssets })
17
17
  )
18
18
 
19
19
  subscriptions = [unsubscribeBalanceAtom, unsubscribeBalanceCountAtom]