@exodus/balances 10.0.0 → 11.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,16 @@
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
+ ## [11.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@10.0.0...@exodus/balances@11.0.0) (2023-09-06)
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ - balances redux (#3749)
11
+
12
+ ### Features
13
+
14
+ - balances redux ([#3749](https://github.com/ExodusMovement/exodus-hydra/issues/3749)) ([52ddf33](https://github.com/ExodusMovement/exodus-hydra/commit/52ddf33e37ac92c197edc9163853339bb366b9de))
15
+
6
16
  ## [10.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@9.1.1...@exodus/balances@10.0.0) (2023-08-31)
7
17
 
8
18
  ### ⚠ BREAKING CHANGES
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/balances",
3
- "version": "10.0.0",
3
+ "version": "11.0.0",
4
4
  "description": "Tracks crypto balances across enabled wallet accounts.",
5
5
  "author": "Exodus Movement Inc.",
6
6
  "license": "UNLICENSED",
@@ -15,6 +15,7 @@
15
15
  "atoms",
16
16
  "report",
17
17
  "plugins",
18
+ "redux",
18
19
  "README.md",
19
20
  "CHANGELOG.md",
20
21
  "!**/__tests__/**"
@@ -32,9 +33,11 @@
32
33
  "@exodus/basic-utils": "^2.1.0",
33
34
  "@exodus/currency": "^2.1.2",
34
35
  "@exodus/module": "^1.1.0",
36
+ "@exodus/multi-account-redux": "^1.6.0",
35
37
  "@exodus/typeforce": "^1.18.0",
36
38
  "lodash": "^4.17.21",
37
- "make-concurrent": "^4.0.0"
39
+ "make-concurrent": "^4.0.0",
40
+ "reselect": "^3.0.1"
38
41
  },
39
42
  "peerDependencies": {
40
43
  "@exodus/blockchain-metadata": "^9.0.1"
@@ -42,13 +45,18 @@
42
45
  "devDependencies": {
43
46
  "@exodus/assets": "^8.0.94",
44
47
  "@exodus/assets-base": "^8.1.10",
48
+ "@exodus/assets-feature": "^1.5.0",
49
+ "@exodus/bitcoin-meta": "^1.0.1",
45
50
  "@exodus/blockchain-metadata": "^9.0.1",
51
+ "@exodus/ethereum-meta": "^1.0.30",
46
52
  "@exodus/models": "^8.9.0",
53
+ "@exodus/redux-dependency-injection": "^3.0.0",
47
54
  "@exodus/storage-memory": "*",
48
- "@exodus/wallet-accounts": "^9.1.0",
55
+ "@exodus/wallet-accounts": "^14.0.0",
49
56
  "eslint": "^8.44.0",
50
57
  "events": "^3.3.0",
51
- "jest": "^29.1.2"
58
+ "jest": "^29.1.2",
59
+ "redux": "^4.2.1"
52
60
  },
53
- "gitHead": "4723d0740241b427c00485e30c0d89a3c6e423b4"
61
+ "gitHead": "202fade631adaaf03ec7e81316f2f6178c41a1ad"
54
62
  }
package/plugins/index.js CHANGED
@@ -4,7 +4,7 @@ const createBalancesPlugin = ({ balancesAtom, port, balances }) => {
4
4
  const balancesAtomObserver = createAtomObserver({
5
5
  port,
6
6
  atom: balancesAtom,
7
- event: 'balancesAtom', // eslint-disable-line hydra/no-atom-event-suffix -- TODO: rename when creating the balances redux module
7
+ event: 'balances',
8
8
  })
9
9
  balancesAtomObserver.register()
10
10
 
@@ -14,17 +14,12 @@ const createBalancesPlugin = ({ balancesAtom, port, balances }) => {
14
14
  balances.load()
15
15
  }
16
16
 
17
- const onUnlock = () => {
18
- balancesAtom.get().then((value) => port.emit('balancesAtom', value))
19
- }
20
-
21
17
  const onStop = () => {
22
18
  balancesAtomObserver.unregister()
23
19
  }
24
20
 
25
21
  return {
26
22
  onLoad,
27
- onUnlock,
28
23
  onStop,
29
24
  }
30
25
  }
package/redux/id.js ADDED
@@ -0,0 +1 @@
1
+ export default 'balances'
package/redux/index.js ADDED
@@ -0,0 +1,51 @@
1
+ import id from './id'
2
+ import initialState from './initial-state'
3
+ import selectorDefinitions from './selectors'
4
+ import { mapValues } from '@exodus/basic-utils'
5
+ import { merge } from 'lodash'
6
+ import helper from './multi-account-helper'
7
+ import { setAccounts } from '@exodus/multi-account-redux/src/common'
8
+
9
+ const mergeChanges = (balancesState, changesByWalletAccount) => {
10
+ return {
11
+ ...balancesState,
12
+ ...mapValues(changesByWalletAccount, (changesByAsset, walletAccount) => {
13
+ if (!balancesState?.[walletAccount]) {
14
+ return {
15
+ loaded: true,
16
+ error: null,
17
+ data: mapValues(changesByAsset, (changesByField) =>
18
+ mapValues(changesByField, (balanceField) => balanceField.to)
19
+ ),
20
+ }
21
+ }
22
+
23
+ const updatedData = mapValues(changesByAsset, (changesByField) =>
24
+ mapValues(changesByField, (balanceField) => balanceField.to)
25
+ )
26
+
27
+ return {
28
+ ...balancesState[walletAccount],
29
+ data: merge({}, balancesState[walletAccount].data, updatedData),
30
+ }
31
+ }),
32
+ }
33
+ }
34
+
35
+ const balancesReduxDefinition = {
36
+ id,
37
+ type: 'redux-module',
38
+ initialState,
39
+ eventReducers: {
40
+ balances: (state, payload) => {
41
+ if (payload.changes && Object.keys(payload.changes).length > 0) {
42
+ return mergeChanges(state, payload.changes)
43
+ }
44
+
45
+ return setAccounts(state, payload.balances)
46
+ },
47
+ },
48
+ selectorDefinitions: [...helper.selectorDefinitions, ...selectorDefinitions],
49
+ }
50
+
51
+ export default balancesReduxDefinition
@@ -0,0 +1,5 @@
1
+ import helper from './multi-account-helper'
2
+
3
+ const initialState = helper.createInitialState()
4
+
5
+ export default initialState
@@ -0,0 +1,10 @@
1
+ import { createReduxModuleHelper } from '@exodus/multi-account-redux'
2
+ import id from './id'
3
+
4
+ const helper = createReduxModuleHelper({
5
+ slice: id,
6
+ createInitialPerAssetData: (asset) => asset.currency.ZERO,
7
+ assetSourceDataSelectors: [{ name: 'balance', selector: (assetData) => assetData.balance }],
8
+ })
9
+
10
+ export default helper
@@ -0,0 +1 @@
1
+ export default []