@exodus/balances 13.2.1 → 13.2.3

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
+ ## [13.2.3](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.2.2...@exodus/balances@13.2.3) (2024-07-25)
7
+
8
+ ### Bug Fixes
9
+
10
+ - migrate definitions ([#8030](https://github.com/ExodusMovement/exodus-hydra/issues/8030)) ([d2dfde5](https://github.com/ExodusMovement/exodus-hydra/commit/d2dfde55dfa843eb52842f64b3aac3a6f9a59069))
11
+
12
+ ## [13.2.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.2.1...@exodus/balances@13.2.2) (2024-07-18)
13
+
14
+ **Note:** Version bump only for package @exodus/balances
15
+
6
16
  ## [13.2.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.2.0...@exodus/balances@13.2.1) (2024-06-26)
7
17
 
8
18
  ### Bug Fixes
package/README.md CHANGED
@@ -1,10 +1,6 @@
1
1
  # @exodus/balances
2
2
 
3
- This module tracks balances across assets and portfolios. It delegates to assets for any asset-specifics.
4
-
5
- ## WARNING: no asset specifics!
6
-
7
- If you introduce any asset specifics like `if (assetName === 'dogicorn') balance = balance.mul(2)`, you will be fired immediately. This is a safety measure to save you from @feri42's wrath. All asset-specifics belong in `asset.api.getBalances` or other APIs inside the asset libraries.
3
+ This Exodus SDK feature tracks the crypto-denominated balances for all enabled wallet accounts. For fiat-denominated balances, check out [@exodus/fiat-balances](../fiat-balances).
8
4
 
9
5
  ## Install
10
6
 
@@ -14,44 +10,81 @@ yarn add @exodus/balances
14
10
 
15
11
  ## Usage
16
12
 
13
+ This feature is designed to be used together with `@exodus/headless`. See [using the sdk](../../docs/using-the-sdk.md).
14
+
15
+ ### Play with it
16
+
17
+ 1. Open the playground https://exodus-hydra.pages.dev/
18
+ 2. Run `selectors.balances.byAsset(store.getState())` in the Dev Tools Console to get balances by asset aggregated across enabled wallet accounts.
19
+ 3. Try out some other selectors from `selectors.balances`. See example usage in [tests](./redux/__tests__/selectors/).
20
+ 4. Mock an address with a balance, tick the blockchain monitor and check your balance.
21
+
17
22
  ```js
18
- import createBalances from '@exodus/balances'
19
-
20
- const balances = createBalances({
21
- // see #/assets-module in exodus-browser or tests for the API
22
- assetsModule,
23
- // pushes data of the form `{ [walletAccount]: WalletAccount }`
24
- walletAccountsAtom,
25
- // @exodus/blockchain-metadata instance
26
- blockchainMetadata,
27
- // the types of balances supported may change. For now it's just the total balance
28
- balanceFields: ['balance'],
29
- // see ../modules/module/src/logger.js for API
30
- logger,
23
+ // mock your ethereum address with one that has a balance
24
+ await exodus.debug.addressProvider.mockAddress({
25
+ assetName: 'ethereum',
26
+ walletAccount: 'exodus_0',
27
+ address: '0x1111111111111111111111111111111111111111',
31
28
  })
29
+ // force tick the ethereum monitor, or wait a while
30
+ await exodus.txLogMonitors.update({ assetName: 'ethereum', refresh: true })
31
+ // check your balance
32
+ selectors.balances
33
+ .createTotal({ assetName: 'ethereum', walletAccount: 'exodus_0' })(store.getState())
34
+ .toString()
35
+ ```
32
36
 
33
- balances.on('balances', ({ balances, changes }) => {
34
- // `balances`
35
- // {
36
- // [walletAccount]: {
37
- // [assetName]: {
38
- // [balanceField]: NumberUnit
39
- // }
40
- // }
41
- // }
42
- //
43
- // `changes`
44
- // {
45
- // [walletAccount]: {
46
- // [assetName]: {
47
- // [balanceField]: {
48
- // from: NumberUnit,
49
- // to: NumberUnit,
50
- // }
51
- // }
52
- // }
53
- // }
54
- })
37
+ ### API Side
38
+
39
+ See [using the sdk](../../docs/using-the-sdk.md#setup-the-api-side) for more details on how features plug into the SDK. Note that the balances feature currently doesn't provide a top level API and is meant to be used purely through selectors.
40
+
41
+ If you're building a feature that requires balances, add a dependency on the `balancesAtom` as below. See also the [available balance fields](./default-config.js).
42
+
43
+ ```js
44
+ const myModuleDefinition = {
45
+ id: 'myModule',
46
+ type: 'module',
47
+ factory: ({ balancesAtom }) => {
48
+ const doSomethingSpecial = async () => {
49
+ // {
50
+ // [walletAccount]: {
51
+ // [assetName]: {
52
+ // // e.g. 'total', 'spendable', 'unconfirmedSent', 'unconfirmedReceived'
53
+ // [balanceField]: NumberUnit, // see @exodus/currency
54
+ // }
55
+ // }
56
+ // }
57
+ const { balances } = await balancesAtom.get()
58
+ // ...
59
+ }
55
60
 
56
- balances.sync() // forces 'balances' event emission
61
+ return {
62
+ doSomethingSpecial,
63
+ }
64
+ },
65
+ dependencies: ['balancesAtom'],
66
+ }
57
67
  ```
68
+
69
+ ### UI Side
70
+
71
+ See [using the sdk](../../docs/using-the-sdk.md#events) for more details on basic UI-side setup.
72
+
73
+ ```js
74
+ import { selectors } from '~/ui/flux'
75
+
76
+ const MyComponent = () => {
77
+ const bitcoinBalance = useSelector(
78
+ selectors.balances.createSpendable({
79
+ assetName: 'bitcoin',
80
+ walletAccount: 'exodus_0',
81
+ })
82
+ ) // returns a NumberUnit
83
+ }
84
+ ```
85
+
86
+ ## Contributing
87
+
88
+ ### WARNING: no asset specifics!
89
+
90
+ If you introduce any asset specifics like `if (assetName === 'dogicorn') balance = balance.mul(2)`, you will be fired immediately. This is a safety measure to save you from @feri42's wrath. All asset-specifics belong in `asset.api.getBalances` or other APIs inside the asset libraries.
package/atoms/index.js CHANGED
@@ -9,6 +9,7 @@ export const balancesAtomDefinition = {
9
9
  type: 'atom',
10
10
  factory: createBalancesAtom,
11
11
  dependencies: [],
12
+ public: true,
12
13
  }
13
14
 
14
15
  export const hasBalanceAtomDefinition = {
@@ -16,6 +17,7 @@ export const hasBalanceAtomDefinition = {
16
17
  type: 'atom',
17
18
  factory: createHasBalanceAtom,
18
19
  dependencies: ['balancesAtom', 'storage'],
20
+ public: true,
19
21
  }
20
22
 
21
23
  export const fundedWalletAccountsAtomDefinition = {
@@ -23,6 +25,7 @@ export const fundedWalletAccountsAtomDefinition = {
23
25
  type: 'atom',
24
26
  factory: createFundedWalletAccountsAtom,
25
27
  dependencies: ['balancesAtom', 'enabledWalletAccountsAtom'],
28
+ public: true,
26
29
  }
27
30
 
28
31
  export const assetNamesWithBalanceAtomDefinition = {
@@ -30,6 +33,7 @@ export const assetNamesWithBalanceAtomDefinition = {
30
33
  type: 'atom',
31
34
  factory: createAssetNamesWithBalanceAtom,
32
35
  dependencies: ['balancesAtom'],
36
+ public: true,
33
37
  }
34
38
 
35
39
  export const assetsWithBalanceCountAtomDefinition = {
@@ -37,4 +41,5 @@ export const assetsWithBalanceCountAtomDefinition = {
37
41
  type: 'atom',
38
42
  factory: createAssetsWithBalanceCountAtom,
39
43
  dependencies: ['assetNamesWithBalanceAtom'],
44
+ public: true,
40
45
  }
package/module/index.js CHANGED
@@ -387,6 +387,7 @@ const balancesDefinition = {
387
387
  'accountStatesAtom',
388
388
  'assetsAtom',
389
389
  ],
390
+ public: true,
390
391
  }
391
392
 
392
393
  export default balancesDefinition
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@exodus/balances",
3
- "version": "13.2.1",
3
+ "version": "13.2.3",
4
4
  "description": "Tracks crypto balances across enabled wallet accounts.",
5
5
  "author": "Exodus Movement, Inc.",
6
6
  "license": "UNLICENSED",
7
7
  "scripts": {
8
- "test": "run -T jest",
8
+ "test": "run -T exodus-test --jest --esbuild",
9
9
  "lint": "run -T eslint . --ignore-path ../../.gitignore",
10
- "lint:fix": "yarn lint --fix"
10
+ "lint:fix": "yarn lint --fix",
11
+ "format": "run -T prettier --write \"**/*.{json,md,yaml}\" --log-level warn",
12
+ "format:check": "run -T prettier --check \"**/*.{json,md,yaml}\" --log-level warn"
11
13
  },
12
14
  "main": "index.js",
13
15
  "files": [
@@ -30,7 +32,7 @@
30
32
  "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abalances"
31
33
  },
32
34
  "dependencies": {
33
- "@exodus/atoms": "^7.0.5",
35
+ "@exodus/atoms": "^8.0.0",
34
36
  "@exodus/basic-utils": "^2.5.1",
35
37
  "@exodus/core-selectors": "^1.5.0",
36
38
  "@exodus/currency": "^2.1.2",
@@ -49,17 +51,17 @@
49
51
  "devDependencies": {
50
52
  "@exodus/assets": "^8.0.94",
51
53
  "@exodus/assets-base": "^8.1.10",
52
- "@exodus/assets-feature": "^5.6.0",
53
- "@exodus/available-assets": "^8.3.0",
54
+ "@exodus/assets-feature": "^5.8.2",
55
+ "@exodus/available-assets": "^8.4.0",
54
56
  "@exodus/bitcoin-meta": "^1.0.1",
55
57
  "@exodus/blockchain-metadata": "^9.0.1",
56
58
  "@exodus/ethereum-meta": "^1.0.30",
57
- "@exodus/fee-data-monitors": "^4.2.0",
59
+ "@exodus/fee-data-monitors": "^4.2.1",
58
60
  "@exodus/redux-dependency-injection": "workspace:^",
59
61
  "@exodus/storage-memory": "*",
60
- "@exodus/wallet-accounts": "^16.7.1",
62
+ "@exodus/wallet-accounts": "^16.8.2",
61
63
  "events": "^3.3.0",
62
64
  "redux": "^4.2.1"
63
65
  },
64
- "gitHead": "7c12959ab914cce84a1ba3cce64253185599eefe"
66
+ "gitHead": "3995391eb48639b2d60ced5224a6a8f4902a2466"
65
67
  }
package/plugins/index.js CHANGED
@@ -6,6 +6,7 @@ export const balancesLifecyclePluginDefinition = {
6
6
  type: 'plugin',
7
7
  factory: createBalancesLifecyclePlugin,
8
8
  dependencies: ['balancesAtom', 'port', 'balances', 'hasBalanceAtom'],
9
+ public: true,
9
10
  }
10
11
 
11
12
  export const balancesAnalyticsPluginDefinition = {
@@ -13,4 +14,5 @@ export const balancesAnalyticsPluginDefinition = {
13
14
  type: 'plugin',
14
15
  factory: createBalancesAnalyticsPlugin,
15
16
  dependencies: ['analytics', 'hasBalanceAtom', 'assetsWithBalanceCountAtom'],
17
+ public: true,
16
18
  }
@@ -1,4 +1,4 @@
1
- import { memoize } from 'lodash'
1
+ import { memoize } from 'lodash' // eslint-disable-line @exodus/restricted-imports/prefer-basic-utils -- TODO: fix next time we touch this file
2
2
  import { MY_STATE } from '@exodus/redux-dependency-injection'
3
3
  import { createSelector } from 'reselect'
4
4
 
@@ -1,4 +1,4 @@
1
- import { memoize } from 'lodash'
1
+ import { memoize } from 'lodash' // eslint-disable-line @exodus/restricted-imports/prefer-basic-utils -- TODO: fix next time we touch this file
2
2
  import { createSelector } from 'reselect'
3
3
  import { isNumberUnit } from '@exodus/currency'
4
4
 
@@ -1,4 +1,4 @@
1
- import { memoize } from 'lodash'
1
+ import { memoize } from 'lodash' // eslint-disable-line @exodus/restricted-imports/prefer-basic-utils -- TODO: fix next time we touch this file
2
2
  import { createSelector } from 'reselect'
3
3
  import { getUnconfirmedBalance } from './get-unconfirmed-balance'
4
4
 
@@ -1,4 +1,4 @@
1
- import { memoize } from 'lodash'
1
+ import { memoize } from 'lodash' // eslint-disable-line @exodus/restricted-imports/prefer-basic-utils -- TODO: fix next time we touch this file
2
2
  import defaultConfig from '../../default-config'
3
3
 
4
4
  const { balanceFields } = defaultConfig
@@ -1,4 +1,4 @@
1
- import { memoize } from 'lodash'
1
+ import { memoize } from 'lodash' // eslint-disable-line @exodus/restricted-imports/prefer-basic-utils -- TODO: fix next time we touch this file
2
2
 
3
3
  const createResultFunction = (field) => (getBalanceForField) =>
4
4
  memoize(
@@ -1,4 +1,4 @@
1
- import { memoize } from 'lodash'
1
+ import { memoize } from 'lodash' // eslint-disable-line @exodus/restricted-imports/prefer-basic-utils -- TODO: fix next time we touch this file
2
2
  import { createSelector } from 'reselect'
3
3
  import { MY_STATE } from '@exodus/redux-dependency-injection'
4
4
 
@@ -1,4 +1,4 @@
1
- import { memoize } from 'lodash'
1
+ import { memoize } from 'lodash' // eslint-disable-line @exodus/restricted-imports/prefer-basic-utils -- TODO: fix next time we touch this file
2
2
  import { createSelector } from 'reselect'
3
3
 
4
4
  export const getUnconfirmedBalance = ({ asset, txs }) => {
package/report/index.js CHANGED
@@ -40,6 +40,7 @@ const balancesReportDefinition = {
40
40
  type: 'report',
41
41
  factory: createBalancesReport,
42
42
  dependencies: ['enabledWalletAccountsAtom', 'balancesAtom'],
43
+ public: true,
43
44
  }
44
45
 
45
46
  export default balancesReportDefinition