@exodus/balances 9.1.1 → 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,26 @@
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
+
16
+ ## [10.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@9.1.1...@exodus/balances@10.0.0) (2023-08-31)
17
+
18
+ ### ⚠ BREAKING CHANGES
19
+
20
+ - accept feature config (#3789)
21
+
22
+ ### Features
23
+
24
+ - accept feature config ([#3789](https://github.com/ExodusMovement/exodus-hydra/issues/3789)) ([beac45f](https://github.com/ExodusMovement/exodus-hydra/commit/beac45fd516383b1ab48fc077a417cbc06ba9f5b))
25
+
6
26
  ## [9.1.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@9.1.0...@exodus/balances@9.1.1) (2023-08-28)
7
27
 
8
28
  ### Bug Fixes
package/index.js CHANGED
@@ -2,14 +2,24 @@ import balancesDefinition from './module'
2
2
  import { balancesAtomDefinition, hasBalanceAtomDefinition } from './atoms'
3
3
  import balancesReportDefinition from './report'
4
4
  import balancesPluginDefinition from './plugins'
5
+ import typeforce from '@exodus/typeforce'
6
+
7
+ const balances = (config) => {
8
+ typeforce(
9
+ {
10
+ balanceFields: typeforce.arrayOf('String'),
11
+ },
12
+ config,
13
+ true
14
+ )
5
15
 
6
- const balances = () => {
7
16
  return {
8
17
  id: 'balances',
9
18
  definitions: [
10
19
  {
11
20
  definition: balancesDefinition,
12
21
  writesAtoms: ['balancesAtom'],
22
+ config,
13
23
  },
14
24
  { definition: balancesAtomDefinition },
15
25
  { definition: hasBalanceAtomDefinition },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/balances",
3
- "version": "9.1.1",
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__/**"
@@ -28,12 +29,15 @@
28
29
  "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abalances"
29
30
  },
30
31
  "dependencies": {
31
- "@exodus/atoms": "^5.5.0",
32
+ "@exodus/atoms": "^5.6.0",
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",
37
+ "@exodus/typeforce": "^1.18.0",
35
38
  "lodash": "^4.17.21",
36
- "make-concurrent": "^4.0.0"
39
+ "make-concurrent": "^4.0.0",
40
+ "reselect": "^3.0.1"
37
41
  },
38
42
  "peerDependencies": {
39
43
  "@exodus/blockchain-metadata": "^9.0.1"
@@ -41,13 +45,18 @@
41
45
  "devDependencies": {
42
46
  "@exodus/assets": "^8.0.94",
43
47
  "@exodus/assets-base": "^8.1.10",
48
+ "@exodus/assets-feature": "^1.5.0",
49
+ "@exodus/bitcoin-meta": "^1.0.1",
44
50
  "@exodus/blockchain-metadata": "^9.0.1",
51
+ "@exodus/ethereum-meta": "^1.0.30",
45
52
  "@exodus/models": "^8.9.0",
53
+ "@exodus/redux-dependency-injection": "^3.0.0",
46
54
  "@exodus/storage-memory": "*",
47
- "@exodus/wallet-accounts": "^9.1.0",
55
+ "@exodus/wallet-accounts": "^14.0.0",
48
56
  "eslint": "^8.44.0",
49
57
  "events": "^3.3.0",
50
- "jest": "^29.1.2"
58
+ "jest": "^29.1.2",
59
+ "redux": "^4.2.1"
51
60
  },
52
- "gitHead": "c165657390b8521de9bb8b87a1ed728055f86630"
61
+ "gitHead": "202fade631adaaf03ec7e81316f2f6178c41a1ad"
53
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',
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 []