@exodus/balances 13.2.2 → 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 +6 -0
- package/README.md +46 -82
- package/atoms/index.js +5 -0
- package/module/index.js +1 -0
- package/package.json +10 -8
- package/plugins/index.js +2 -0
- package/redux/selectors/create-balance-selectors.js +1 -1
- package/redux/selectors/create-fuel-threshold.js +1 -1
- package/redux/selectors/create-unconfirmed-balance.js +1 -1
- package/redux/selectors/get-balance-for-field.js +1 -1
- package/redux/selectors/get-balance-selectors.js +1 -1
- package/redux/selectors/get-balances.js +1 -1
- package/redux/selectors/get-unconfirmed-balance.js +1 -1
- package/report/index.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
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
|
+
|
|
6
12
|
## [13.2.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.2.1...@exodus/balances@13.2.2) (2024-07-18)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @exodus/balances
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @exodus/balances
|
|
2
2
|
|
|
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).
|
|
4
|
+
|
|
3
5
|
## Install
|
|
4
6
|
|
|
5
7
|
```sh
|
|
@@ -8,80 +10,69 @@ yarn add @exodus/balances
|
|
|
8
10
|
|
|
9
11
|
## Usage
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- A feature that plugs into the Exodus SDK in your logical or actual background process. This provides the `balancesAtom` to other features.
|
|
14
|
-
- A redux module that plugs into the Exodus SDK in the UI process. This provides selectors for getting [various balances](https://github.com/ExodusMovement/assets/blob/cd0088d03887934685c1bcbb223b55bb94705a56/docs/balances-model.md).
|
|
13
|
+
This feature is designed to be used together with `@exodus/headless`. See [using the sdk](../../docs/using-the-sdk.md).
|
|
15
14
|
|
|
16
|
-
###
|
|
15
|
+
### Play with it
|
|
17
16
|
|
|
18
|
-
|
|
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.
|
|
19
21
|
|
|
20
22
|
```js
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
In the UI process, plug the `balances` redux module into the SDK:
|
|
28
|
-
|
|
29
|
-
```js
|
|
30
|
-
import { setupRedux } from '@exodus/redux-dependency-injection'
|
|
31
|
-
import balances from '@exodus/balances/redux'
|
|
32
|
-
|
|
33
|
-
const { selectors, createHandleEvent, reducers, initialState } = setupRedux({
|
|
34
|
-
dependencies: [
|
|
35
|
-
// other redux modules
|
|
36
|
-
// ...
|
|
37
|
-
balances,
|
|
38
|
-
],
|
|
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',
|
|
39
28
|
})
|
|
40
|
-
|
|
41
|
-
|
|
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()
|
|
42
35
|
```
|
|
43
36
|
|
|
44
|
-
|
|
37
|
+
### API Side
|
|
45
38
|
|
|
46
|
-
|
|
47
|
-
// forward SDK events to the UI process so the relevant redux module can handle them
|
|
48
|
-
sdk.subscribe(({ type, payload }) => handleEvent(type, payload))
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Consuming Balances
|
|
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.
|
|
52
40
|
|
|
53
|
-
|
|
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).
|
|
54
42
|
|
|
55
43
|
```js
|
|
56
|
-
const myModuleFactory = ({ balancesAtom }) => {
|
|
57
|
-
const doSomethingSpecial = async () => {
|
|
58
|
-
// {
|
|
59
|
-
// [walletAccount]: {
|
|
60
|
-
// [assetName]: {
|
|
61
|
-
// // e.g. 'total', 'spendable', 'unconfirmedSent', 'unconfirmedReceived'
|
|
62
|
-
// [balanceField]: NumberUnit, // see @exodus/currency
|
|
63
|
-
// }
|
|
64
|
-
// }
|
|
65
|
-
// }
|
|
66
|
-
const { balances } = await balancesAtom.get()
|
|
67
|
-
// ...
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
doSomethingSpecial,
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
44
|
const myModuleDefinition = {
|
|
76
45
|
id: 'myModule',
|
|
77
46
|
type: 'module',
|
|
78
|
-
factory:
|
|
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
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
doSomethingSpecial,
|
|
63
|
+
}
|
|
64
|
+
},
|
|
79
65
|
dependencies: ['balancesAtom'],
|
|
80
66
|
}
|
|
81
67
|
```
|
|
82
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
|
+
|
|
83
73
|
```js
|
|
84
|
-
|
|
74
|
+
import { selectors } from '~/ui/flux'
|
|
75
|
+
|
|
85
76
|
const MyComponent = () => {
|
|
86
77
|
const bitcoinBalance = useSelector(
|
|
87
78
|
selectors.balances.createSpendable({
|
|
@@ -92,33 +83,6 @@ const MyComponent = () => {
|
|
|
92
83
|
}
|
|
93
84
|
```
|
|
94
85
|
|
|
95
|
-
## Playground
|
|
96
|
-
|
|
97
|
-
Try the balances selectors in the [sdk-playground](../../apps/sdk-playground/).
|
|
98
|
-
|
|
99
|
-
In this repo root, run:
|
|
100
|
-
|
|
101
|
-
```sh
|
|
102
|
-
yarn --cwd apps/sdk-playground dev
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
Open `http://localhost:8008` in the browser and run the following in the dev tools console:
|
|
106
|
-
|
|
107
|
-
```js
|
|
108
|
-
// mock your ethereum address with one that has a balance
|
|
109
|
-
await exodus.debug.addressProvider.mockAddress({
|
|
110
|
-
assetName: 'ethereum',
|
|
111
|
-
walletAccount: 'exodus_0',
|
|
112
|
-
address: '0x1111111111111111111111111111111111111111',
|
|
113
|
-
})
|
|
114
|
-
// force tick the ethereum monitor, or wait a while
|
|
115
|
-
await exodus.txLogMonitors.update({ assetName: 'ethereum', refresh: true })
|
|
116
|
-
// check your balance
|
|
117
|
-
selectors.balances.createTotal({ assetName: 'ethereum', walletAccount: 'exodus_0' })(
|
|
118
|
-
store.getState()
|
|
119
|
-
)
|
|
120
|
-
```
|
|
121
|
-
|
|
122
86
|
## Contributing
|
|
123
87
|
|
|
124
88
|
### WARNING: no asset specifics!
|
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
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/balances",
|
|
3
|
-
"version": "13.2.
|
|
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": [
|
|
@@ -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.8.
|
|
53
|
-
"@exodus/available-assets": "^8.
|
|
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.
|
|
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.8.
|
|
62
|
+
"@exodus/wallet-accounts": "^16.8.2",
|
|
61
63
|
"events": "^3.3.0",
|
|
62
64
|
"redux": "^4.2.1"
|
|
63
65
|
},
|
|
64
|
-
"gitHead": "
|
|
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
|
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 }) => {
|