@exodus/balances 12.2.0 → 12.4.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,18 @@
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.4.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@12.3.0...@exodus/balances@12.4.0) (2024-01-08)
7
+
8
+ ### Features
9
+
10
+ - **balances:** analytics plugin ([#5287](https://github.com/ExodusMovement/exodus-hydra/issues/5287)) ([91de7ba](https://github.com/ExodusMovement/exodus-hydra/commit/91de7ba2fc0563f49b1a5e39dd5546cea4415a6b))
11
+
12
+ ## [12.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@12.2.0...@exodus/balances@12.3.0) (2024-01-05)
13
+
14
+ ### Features
15
+
16
+ - add selector to compute balance by asset ([#5258](https://github.com/ExodusMovement/exodus-hydra/issues/5258)) ([4d50ddc](https://github.com/ExodusMovement/exodus-hydra/commit/4d50ddca485d1da794fafe04f40b1fef97a982ec))
17
+
6
18
  ## [12.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@12.1.0...@exodus/balances@12.2.0) (2024-01-03)
7
19
 
8
20
  ### Features
package/index.js CHANGED
@@ -5,17 +5,11 @@ import {
5
5
  fundedWalletAccountsAtomDefinition,
6
6
  } from './atoms'
7
7
  import balancesReportDefinition from './report'
8
- import balancesPluginDefinition from './plugins'
8
+ import { balancesLifecyclePluginDefinition, balancesAnalyticsPluginDefinition } from './plugins'
9
9
  import typeforce from '@exodus/typeforce'
10
10
 
11
11
  const balances = (config) => {
12
- typeforce(
13
- {
14
- balanceFields: typeforce.arrayOf('String'),
15
- },
16
- config,
17
- true
18
- )
12
+ typeforce({ balanceFields: typeforce.arrayOf('String') }, config, true)
19
13
 
20
14
  return {
21
15
  id: 'balances',
@@ -32,7 +26,11 @@ const balances = (config) => {
32
26
  },
33
27
  { definition: fundedWalletAccountsAtomDefinition },
34
28
  { definition: balancesReportDefinition },
35
- { definition: balancesPluginDefinition },
29
+ { definition: balancesLifecyclePluginDefinition },
30
+ {
31
+ if: { registered: ['analytics'] },
32
+ definition: balancesAnalyticsPluginDefinition,
33
+ },
36
34
  ],
37
35
  }
38
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/balances",
3
- "version": "12.2.0",
3
+ "version": "12.4.0",
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
  "jest": "^29.1.2",
59
59
  "redux": "^4.2.1"
60
60
  },
61
- "gitHead": "a158fff895557150c79a1cdec05a29d4587f5577"
61
+ "gitHead": "15dba244250d5c1ceec8432a96c781a19a70aaf0"
62
62
  }
@@ -0,0 +1,19 @@
1
+ const createBalancesAnalyticsPlugin = ({ analytics, hasBalanceAtom }) => {
2
+ let unsubscribe
3
+
4
+ const onStart = () => {
5
+ analytics.setDefaultProperties({ hasBalance: false })
6
+
7
+ unsubscribe = hasBalanceAtom.observe((hasBalance) => {
8
+ analytics.setDefaultProperties({ hasBalance })
9
+ })
10
+ }
11
+
12
+ const onStop = () => {
13
+ unsubscribe?.()
14
+ }
15
+
16
+ return { onStart, onStop }
17
+ }
18
+
19
+ export default createBalancesAnalyticsPlugin
package/plugins/index.js CHANGED
@@ -1,49 +1,16 @@
1
- import { createAtomObserver } from '@exodus/atoms'
1
+ import createBalancesAnalyticsPlugin from './analytics'
2
+ import createBalancesLifecyclePlugin from './lifecycle'
2
3
 
3
- const createBalancesPlugin = ({ balancesAtom, port, balances, hasBalanceAtom }) => {
4
- const balancesAtomObserver = createAtomObserver({
5
- port,
6
- atom: balancesAtom,
7
- event: 'balances',
8
- })
9
- balancesAtomObserver.register()
10
-
11
- const hasBalanceAtomObserver = createAtomObserver({
12
- port,
13
- atom: hasBalanceAtom,
14
- event: 'hasBalance',
15
- })
16
- hasBalanceAtomObserver.register()
17
-
18
- const onLoad = () => {
19
- hasBalanceAtomObserver.start()
20
- balancesAtomObserver.start()
21
-
22
- balances.load()
23
- }
24
-
25
- const onStop = () => {
26
- balancesAtomObserver.unregister()
27
- hasBalanceAtomObserver.unregister()
28
- balances.stop()
29
- }
30
-
31
- const onClear = async () => {
32
- await hasBalanceAtom.set(undefined)
33
- }
34
-
35
- return {
36
- onLoad,
37
- onStop,
38
- onClear,
39
- }
40
- }
41
-
42
- const balancesPluginDefinition = {
43
- id: 'balancesPlugin',
4
+ export const balancesLifecyclePluginDefinition = {
5
+ id: 'balancesLifecyclePlugin',
44
6
  type: 'plugin',
45
- factory: createBalancesPlugin,
7
+ factory: createBalancesLifecyclePlugin,
46
8
  dependencies: ['balancesAtom', 'port', 'balances', 'hasBalanceAtom'],
47
9
  }
48
10
 
49
- export default balancesPluginDefinition
11
+ export const balancesAnalyticsPluginDefinition = {
12
+ id: 'balancesAnalyticsPlugin',
13
+ type: 'plugin',
14
+ factory: createBalancesAnalyticsPlugin,
15
+ dependencies: ['analytics', 'hasBalanceAtom'],
16
+ }
@@ -0,0 +1,40 @@
1
+ import { createAtomObserver } from '@exodus/atoms'
2
+
3
+ const createBalancesLifecyclePlugin = ({ balancesAtom, port, balances, hasBalanceAtom }) => {
4
+ const balancesAtomObserver = createAtomObserver({
5
+ port,
6
+ atom: balancesAtom,
7
+ event: 'balances',
8
+ })
9
+
10
+ const hasBalanceAtomObserver = createAtomObserver({
11
+ port,
12
+ atom: hasBalanceAtom,
13
+ event: 'hasBalance',
14
+ })
15
+
16
+ const onLoad = () => {
17
+ hasBalanceAtomObserver.start()
18
+ balancesAtomObserver.start()
19
+
20
+ balances.load()
21
+ }
22
+
23
+ const onStop = () => {
24
+ balancesAtomObserver.unregister()
25
+ hasBalanceAtomObserver.unregister()
26
+ balances.stop()
27
+ }
28
+
29
+ const onClear = async () => {
30
+ await hasBalanceAtom.set(undefined)
31
+ }
32
+
33
+ return {
34
+ onLoad,
35
+ onStop,
36
+ onClear,
37
+ }
38
+ }
39
+
40
+ export default createBalancesLifecyclePlugin
@@ -0,0 +1,25 @@
1
+ const resultFunction = (walletAccounts, getAssetBalances) =>
2
+ walletAccounts.reduce((all, walletAccount) => {
3
+ for (const [assetName, balance] of Object.entries(getAssetBalances(walletAccount))) {
4
+ if (!all[assetName]) {
5
+ all[assetName] = balance
6
+ continue
7
+ }
8
+
9
+ all[assetName] = all[assetName].add(balance)
10
+ }
11
+
12
+ return all
13
+ }, {})
14
+
15
+ const byAssetSelector = {
16
+ id: 'byAsset',
17
+ resultFunction,
18
+ dependencies: [
19
+ //
20
+ { module: 'walletAccounts', selector: 'enabled' },
21
+ { selector: 'getAccountAssetsBalanceSelector' },
22
+ ],
23
+ }
24
+
25
+ export default byAssetSelector
@@ -1,4 +1,9 @@
1
+ import byAssetSelectorDefinition from './by-asset'
1
2
  import createUnconfirmedBalanceSelectorDefinition from './create-unconfirmed-balance'
2
3
  import getUnconfirmedBalanceSelectorDefinition from './get-unconfirmed-balance'
3
4
 
4
- export default [createUnconfirmedBalanceSelectorDefinition, getUnconfirmedBalanceSelectorDefinition]
5
+ export default [
6
+ byAssetSelectorDefinition,
7
+ createUnconfirmedBalanceSelectorDefinition,
8
+ getUnconfirmedBalanceSelectorDefinition,
9
+ ]