@exodus/balances 12.0.0 → 12.1.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,19 @@
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
+ ## [12.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@12.0.1...@exodus/balances@12.1.0) (2023-12-14)
7
+
8
+ ### Features
9
+
10
+ - **balances:** funded wallet accounts atom ([#5074](https://github.com/ExodusMovement/exodus-hydra/issues/5074)) ([dc98436](https://github.com/ExodusMovement/exodus-hydra/commit/dc98436d5f8bbade4ceab85af60455ac3b4efa49))
11
+ - remove storing oldBalances in balances atoms ([#5073](https://github.com/ExodusMovement/exodus-hydra/issues/5073)) ([414db86](https://github.com/ExodusMovement/exodus-hydra/commit/414db866a86aaf3242e68698596af187da6927c3))
12
+
13
+ ## [12.0.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@12.0.0...@exodus/balances@12.0.1) (2023-12-12)
14
+
15
+ ### Bug Fixes
16
+
17
+ - **balances:** reducer changes computation when balances not loaded ([#5008](https://github.com/ExodusMovement/exodus-hydra/issues/5008))08) ([01e50c9](https://github.com/ExodusMovement/exodus-hydra/commit/01e50c9ef852b542855aad8abf25db3eaeca76a0))
18
+
6
19
  ## [12.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@11.2.2...@exodus/balances@12.0.0) (2023-11-23)
7
20
 
8
21
  ### ⚠ BREAKING CHANGES
package/README.md CHANGED
@@ -30,8 +30,8 @@ const balances = createBalances({
30
30
  logger,
31
31
  })
32
32
 
33
- balances.on('balances', ({ balances, oldBalances, changes }) => {
34
- // `balances`, `oldBalances`
33
+ balances.on('balances', ({ balances, changes }) => {
34
+ // `balances`
35
35
  // {
36
36
  // [walletAccount]: {
37
37
  // [assetName]: {
package/atoms/balances.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createInMemoryAtom } from '@exodus/atoms'
2
2
 
3
+ // eslint-disable-next-line @exodus/hydra/in-memory-atom-default-value
3
4
  const createBalancesAtom = () => createInMemoryAtom()
4
5
 
5
6
  export default createBalancesAtom
@@ -0,0 +1,23 @@
1
+ import { combine, compute } from '@exodus/atoms'
2
+ import { mapValues } from '@exodus/basic-utils'
3
+
4
+ const computeFundedWalletAccounts = ({ walletAccounts, balances }) => {
5
+ return mapValues(walletAccounts, (_, key) => {
6
+ const walletAccountBalaces = balances.balances[key] || {}
7
+ return Object.values(walletAccountBalaces).some(({ balance }) => !balance.isZero)
8
+ })
9
+ }
10
+
11
+ const createFundedWalletAccountsAtom = ({ balancesAtom, enabledWalletAccountsAtom }) => {
12
+ const walletAccountsBalanceAtom = combine({
13
+ walletAccounts: enabledWalletAccountsAtom,
14
+ balances: balancesAtom,
15
+ })
16
+
17
+ return compute({
18
+ atom: walletAccountsBalanceAtom,
19
+ selector: computeFundedWalletAccounts,
20
+ })
21
+ }
22
+
23
+ export default createFundedWalletAccountsAtom
package/atoms/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import createBalancesAtom from './balances'
2
+ import createFundedWalletAccountsAtom from './funded-wallet-accounts'
2
3
  import createHasBalanceAtom from './has-balance'
3
4
 
4
5
  export const balancesAtomDefinition = {
@@ -14,3 +15,10 @@ export const hasBalanceAtomDefinition = {
14
15
  factory: createHasBalanceAtom,
15
16
  dependencies: ['balancesAtom', 'storage'],
16
17
  }
18
+
19
+ export const fundedWalletAccountsAtomDefinition = {
20
+ id: 'fundedWalletAccountsAtom',
21
+ type: 'atom',
22
+ factory: createFundedWalletAccountsAtom,
23
+ dependencies: ['balancesAtom', 'enabledWalletAccountsAtom'],
24
+ }
package/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import balancesDefinition from './module'
2
- import { balancesAtomDefinition, hasBalanceAtomDefinition } from './atoms'
2
+ import {
3
+ balancesAtomDefinition,
4
+ hasBalanceAtomDefinition,
5
+ fundedWalletAccountsAtomDefinition,
6
+ } from './atoms'
3
7
  import balancesReportDefinition from './report'
4
8
  import balancesPluginDefinition from './plugins'
5
9
  import typeforce from '@exodus/typeforce'
@@ -18,7 +22,6 @@ const balances = (config) => {
18
22
  definitions: [
19
23
  {
20
24
  definition: balancesDefinition,
21
- writesAtoms: ['balancesAtom'],
22
25
  config,
23
26
  },
24
27
  { definition: balancesAtomDefinition },
@@ -27,8 +30,9 @@ const balances = (config) => {
27
30
  storage: { namespace: 'balances' },
28
31
  aliases: [{ implementationId: 'unsafeStorage', interfaceId: 'storage' }],
29
32
  },
33
+ { definition: fundedWalletAccountsAtomDefinition },
30
34
  { definition: balancesReportDefinition },
31
- { definition: balancesPluginDefinition, writesAtoms: ['hasBalanceAtom'] },
35
+ { definition: balancesPluginDefinition },
32
36
  ],
33
37
  }
34
38
  }
package/module/index.js CHANGED
@@ -26,7 +26,6 @@ class Balances extends ExodusModule {
26
26
  #walletAccounts = [] // string[]
27
27
  #ready = false
28
28
 
29
- #oldBalances = Object.create(null)
30
29
  #balances = Object.create(null)
31
30
  #balancesAtom
32
31
  #accountStatesAtom
@@ -375,19 +374,12 @@ class Balances extends ExodusModule {
375
374
  }
376
375
 
377
376
  #flush = ({ changes } = {}) => {
378
- const oldBalances = this.#oldBalances
379
377
  const balances = cloneBalances(this.#balances)
380
378
 
381
379
  if (Object.keys(balances).length === 0) return // wait till `load` finished
382
380
 
383
381
  this._logger.log('balances updated')
384
- this.#balancesAtom.set({
385
- balances,
386
- oldBalances,
387
- changes,
388
- })
389
-
390
- this.#oldBalances = balances
382
+ this.#balancesAtom.set({ balances, changes })
391
383
  }
392
384
 
393
385
  stop = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/balances",
3
- "version": "12.0.0",
3
+ "version": "12.1.0",
4
4
  "description": "Tracks crypto balances across enabled wallet accounts.",
5
5
  "author": "Exodus Movement Inc.",
6
6
  "license": "UNLICENSED",
@@ -29,11 +29,11 @@
29
29
  "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abalances"
30
30
  },
31
31
  "dependencies": {
32
- "@exodus/atoms": "^6.0.1",
32
+ "@exodus/atoms": "^7.0.0",
33
33
  "@exodus/basic-utils": "^2.1.0",
34
34
  "@exodus/currency": "^2.1.2",
35
35
  "@exodus/module": "^1.1.0",
36
- "@exodus/multi-account-redux": "^2.0.0",
36
+ "@exodus/multi-account-redux": "^2.0.1",
37
37
  "@exodus/typeforce": "^1.18.0",
38
38
  "lodash": "^4.17.21",
39
39
  "make-concurrent": "^4.0.0",
@@ -45,18 +45,18 @@
45
45
  "devDependencies": {
46
46
  "@exodus/assets": "^8.0.94",
47
47
  "@exodus/assets-base": "^8.1.10",
48
- "@exodus/assets-feature": "^4.0.0",
48
+ "@exodus/assets-feature": "^4.0.1",
49
49
  "@exodus/bitcoin-meta": "^1.0.1",
50
50
  "@exodus/blockchain-metadata": "^9.0.1",
51
51
  "@exodus/ethereum-meta": "^1.0.30",
52
52
  "@exodus/models": "^10.1.0",
53
53
  "@exodus/redux-dependency-injection": "^3.0.0",
54
54
  "@exodus/storage-memory": "*",
55
- "@exodus/wallet-accounts": "^14.3.0",
55
+ "@exodus/wallet-accounts": "^15.0.0",
56
56
  "eslint": "^8.44.0",
57
57
  "events": "^3.3.0",
58
58
  "jest": "^29.1.2",
59
59
  "redux": "^4.2.1"
60
60
  },
61
- "gitHead": "0c943e6a82e29239305544665711c1b1b4a98fce"
61
+ "gitHead": "b2cc53c628d9cdb2e4a25557f72b88ec05c75e14"
62
62
  }
package/redux/index.js CHANGED
@@ -38,15 +38,14 @@ const balancesReduxDefinition = {
38
38
  initialState,
39
39
  eventReducers: {
40
40
  balances: (state, payload) => {
41
- const ignoreChanges = state === initialState
42
- if (!ignoreChanges && payload.changes && Object.keys(payload.changes).length > 0) {
41
+ const { hasBalance, ...walletAccountBalances } = state
42
+ const balancesLoaded = Object.keys(walletAccountBalances).every((value) => value.loaded)
43
+
44
+ if (balancesLoaded && payload.changes && Object.keys(payload.changes).length > 0) {
43
45
  return mergeChanges(state, payload.changes)
44
46
  }
45
47
 
46
- return {
47
- hasBalance: state.hasBalance,
48
- ...setAccounts(state, payload.balances),
49
- }
48
+ return { hasBalance, ...setAccounts(state, payload.balances) }
50
49
  },
51
50
  hasBalance: (state, payload) => ({
52
51
  ...state,