@exodus/balances 13.3.1 → 13.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 +20 -0
- package/LICENSE +7 -0
- package/README.md +4 -4
- package/atoms/has-balance.js +0 -1
- package/module/index.js +19 -39
- package/package.json +13 -12
- package/redux/index.js +0 -1
- package/redux/selectors/create-balance-selectors.js +2 -2
- package/redux/selectors/create-fuel-threshold.js +2 -2
- package/redux/selectors/create-unconfirmed-balance.js +2 -2
- package/redux/selectors/get-balance-for-field.js +2 -2
- package/redux/selectors/get-balance-selectors.js +1 -2
- package/redux/selectors/get-balances.js +2 -2
- package/redux/selectors/get-unconfirmed-balance.js +2 -2
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
|
+
## [13.4.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.3.2...@exodus/balances@13.4.0) (2024-11-25)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- feat: use atoms v9 (#9651)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- fix: balances tests (#9738)
|
|
15
|
+
|
|
16
|
+
### License
|
|
17
|
+
|
|
18
|
+
- license: re-license under MIT license (#10580)
|
|
19
|
+
|
|
20
|
+
## [13.3.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.3.1...@exodus/balances@13.3.2) (2024-09-13)
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
- log instead of throwing ([#9147](https://github.com/ExodusMovement/exodus-hydra/issues/9147)) ([499f002](https://github.com/ExodusMovement/exodus-hydra/commit/499f002ddb2d35fab3d7b18b59cac07476ea6ee0))
|
|
25
|
+
|
|
6
26
|
## [13.3.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.3.0...@exodus/balances@13.3.1) (2024-09-09)
|
|
7
27
|
|
|
8
28
|
**Note:** Version bump only for package @exodus/balances
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2024 Exodus Movement, Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ yarn add @exodus/balances
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
This feature is designed to be used together with `@exodus/headless`. See [using the sdk](../../docs/using-the-sdk.md).
|
|
13
|
+
This feature is designed to be used together with `@exodus/headless`. See [using the sdk](../../docs/docs-website/docs/development/using-the-sdk.md).
|
|
14
14
|
|
|
15
15
|
### Play with it
|
|
16
16
|
|
|
@@ -36,7 +36,7 @@ selectors.balances
|
|
|
36
36
|
|
|
37
37
|
### API Side
|
|
38
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.
|
|
39
|
+
See [using the sdk](../../docs/docs-website/docs/development/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
40
|
|
|
41
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
42
|
|
|
@@ -68,7 +68,7 @@ const myModuleDefinition = {
|
|
|
68
68
|
|
|
69
69
|
### UI Side
|
|
70
70
|
|
|
71
|
-
See [using the sdk](../../docs/using-the-sdk.md#events) for more details on basic UI-side setup.
|
|
71
|
+
See [using the sdk](../../docs/docs-website/docs/development/using-the-sdk.md#events) for more details on basic UI-side setup.
|
|
72
72
|
|
|
73
73
|
```js
|
|
74
74
|
import { selectors } from '~/ui/flux'
|
|
@@ -87,4 +87,4 @@ const MyComponent = () => {
|
|
|
87
87
|
|
|
88
88
|
### WARNING: no asset specifics!
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
Do NOT introduce any asset specifics like `if (assetName === 'dogicorn') balance = balance.mul(2)`. All asset-specifics belong in `asset.api.getBalances` or other APIs inside the asset libraries.
|
package/atoms/has-balance.js
CHANGED
package/module/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { isNumberUnit } from '@exodus/currency'
|
|
2
2
|
import { TxSet } from '@exodus/models'
|
|
3
|
-
import ExodusModule from '@exodus/module' // eslint-disable-line import/no-deprecated
|
|
4
|
-
// eslint-disable-next-line @exodus/restricted-imports/prefer-basic-utils
|
|
5
3
|
import lodash from 'lodash'
|
|
6
4
|
import { difference, flattenToPaths, pick, set } from '@exodus/basic-utils'
|
|
7
5
|
import makeConcurrent from 'make-concurrent'
|
|
@@ -21,9 +19,8 @@ const zipNonNull = (keys, values) =>
|
|
|
21
19
|
values.filter((value) => value != null)
|
|
22
20
|
)
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class Balances extends ExodusModule {
|
|
22
|
+
class Balances {
|
|
23
|
+
#logger
|
|
27
24
|
#assetsModule
|
|
28
25
|
#assetsAtom
|
|
29
26
|
#balanceFieldsConfig
|
|
@@ -49,8 +46,7 @@ class Balances extends ExodusModule {
|
|
|
49
46
|
txLogsAtom,
|
|
50
47
|
accountStatesAtom,
|
|
51
48
|
}) {
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
this.#logger = logger
|
|
54
50
|
this.#assetsModule = assetsModule
|
|
55
51
|
this.#assetsAtom = assetsAtom
|
|
56
52
|
this.#balanceFieldsConfig = config?.balanceFieldsConfig || defaultConfig.balanceFieldsConfig
|
|
@@ -68,16 +64,13 @@ class Balances extends ExodusModule {
|
|
|
68
64
|
this.#pushIntoSharedQueue(() => fn.apply(this, args))
|
|
69
65
|
}
|
|
70
66
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const captureErrors =
|
|
74
|
-
({ fn, name, sanitizeArgs = () => {} }) =>
|
|
67
|
+
const swallowErrors =
|
|
68
|
+
(fn) =>
|
|
75
69
|
async (...args) => {
|
|
76
70
|
try {
|
|
77
71
|
return await fn(...args)
|
|
78
72
|
} catch (error) {
|
|
79
|
-
this.
|
|
80
|
-
throw error
|
|
73
|
+
this.#logger.error(error)
|
|
81
74
|
}
|
|
82
75
|
}
|
|
83
76
|
|
|
@@ -86,17 +79,8 @@ class Balances extends ExodusModule {
|
|
|
86
79
|
this.#handleTxLogUpdate = shareQueue(this.#handleTxLogUpdate)
|
|
87
80
|
this.#recompute = shareQueue(this.#recompute)
|
|
88
81
|
this.#onAssetsChanged = shareQueue(this.#onAssetsChanged)
|
|
89
|
-
this.#getBalancesForAssetSource =
|
|
90
|
-
|
|
91
|
-
name: 'getBalancesForAssetSource',
|
|
92
|
-
sanitizeArgs: ({ walletAccount, assetName }) => ({ walletAccount, assetName }),
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
this.#setWalletAccounts = captureErrors({
|
|
96
|
-
fn: this.#setWalletAccounts,
|
|
97
|
-
name: 'setWalletAccounts',
|
|
98
|
-
sanitizeArgs: (walletAccounts) => walletAccounts,
|
|
99
|
-
})
|
|
82
|
+
this.#getBalancesForAssetSource = swallowErrors(this.#getBalancesForAssetSource)
|
|
83
|
+
this.#setWalletAccounts = swallowErrors(this.#setWalletAccounts)
|
|
100
84
|
}
|
|
101
85
|
|
|
102
86
|
load = () => {
|
|
@@ -131,9 +115,7 @@ class Balances extends ExodusModule {
|
|
|
131
115
|
|
|
132
116
|
#handleAccountStateUpdate = async (opts) => {
|
|
133
117
|
if (!this.#ready) {
|
|
134
|
-
this.
|
|
135
|
-
isReady: this.#ready,
|
|
136
|
-
})
|
|
118
|
+
this.#logger.log('ignore update from account-state event.', { isReady: this.#ready })
|
|
137
119
|
return
|
|
138
120
|
}
|
|
139
121
|
|
|
@@ -142,9 +124,7 @@ class Balances extends ExodusModule {
|
|
|
142
124
|
|
|
143
125
|
#handleTxLogUpdate = (opts) => {
|
|
144
126
|
if (!this.#ready) {
|
|
145
|
-
this.
|
|
146
|
-
isReady: this.#ready,
|
|
147
|
-
})
|
|
127
|
+
this.#logger.log('ignore update from tx-log event.', { isReady: this.#ready })
|
|
148
128
|
return
|
|
149
129
|
}
|
|
150
130
|
|
|
@@ -189,7 +169,7 @@ class Balances extends ExodusModule {
|
|
|
189
169
|
balances: pick(balances, this.#balanceFields),
|
|
190
170
|
asset,
|
|
191
171
|
zero,
|
|
192
|
-
logger: this
|
|
172
|
+
logger: this.#logger,
|
|
193
173
|
emitter: this,
|
|
194
174
|
})
|
|
195
175
|
}
|
|
@@ -209,7 +189,7 @@ class Balances extends ExodusModule {
|
|
|
209
189
|
}
|
|
210
190
|
|
|
211
191
|
#load = async ({ walletAccount }) => {
|
|
212
|
-
this.
|
|
192
|
+
this.#logger.log(`loading walletAccount ${walletAccount}`)
|
|
213
193
|
this.#balances[walletAccount] = await this.#getBalancesForWalletAccount({ walletAccount })
|
|
214
194
|
}
|
|
215
195
|
|
|
@@ -221,14 +201,14 @@ class Balances extends ExodusModule {
|
|
|
221
201
|
this.#walletAccounts = walletAccounts
|
|
222
202
|
this.#ready = true
|
|
223
203
|
if (removed.length > 0) {
|
|
224
|
-
this.
|
|
204
|
+
this.#logger.log('recomputing after removing walletAccounts', removed)
|
|
225
205
|
removed.forEach((walletAccount) => {
|
|
226
206
|
delete this.#balances[walletAccount]
|
|
227
207
|
})
|
|
228
208
|
}
|
|
229
209
|
|
|
230
210
|
if (added.length > 0) {
|
|
231
|
-
this.
|
|
211
|
+
this.#logger.log('recomputing after adding walletAccounts', added)
|
|
232
212
|
await this.#recompute({ walletAccounts: added })
|
|
233
213
|
} else {
|
|
234
214
|
this.#flush()
|
|
@@ -244,7 +224,7 @@ class Balances extends ExodusModule {
|
|
|
244
224
|
return
|
|
245
225
|
}
|
|
246
226
|
|
|
247
|
-
this.
|
|
227
|
+
this.#logger.log('recomputing based on new assets list')
|
|
248
228
|
this.#recompute()
|
|
249
229
|
}
|
|
250
230
|
|
|
@@ -309,7 +289,7 @@ class Balances extends ExodusModule {
|
|
|
309
289
|
if (!this.#isSupportedAsset(assetName)) return
|
|
310
290
|
|
|
311
291
|
if (!this.#walletAccounts.includes(walletAccount)) {
|
|
312
|
-
this.
|
|
292
|
+
this.#logger.warn(`unexpected update for disabled walletAccount ${walletAccount}`)
|
|
313
293
|
return
|
|
314
294
|
}
|
|
315
295
|
|
|
@@ -340,7 +320,7 @@ class Balances extends ExodusModule {
|
|
|
340
320
|
if (!newBalance) continue
|
|
341
321
|
if ((oldBalance || currency.ZERO).equals(newBalance)) continue
|
|
342
322
|
|
|
343
|
-
this.
|
|
323
|
+
this.#logger.log(`updating assetSource ${walletAccount}:${assetName}`)
|
|
344
324
|
set(changes, [walletAccount, subAssetName, field], {
|
|
345
325
|
from: oldBalance ?? currency.ZERO,
|
|
346
326
|
to: newBalance,
|
|
@@ -364,7 +344,7 @@ class Balances extends ExodusModule {
|
|
|
364
344
|
|
|
365
345
|
if (Object.keys(balances).length === 0) return // wait till `load` finished
|
|
366
346
|
|
|
367
|
-
this.
|
|
347
|
+
this.#logger.log('balances updated')
|
|
368
348
|
this.#balancesAtom.set({ balances, changes })
|
|
369
349
|
}
|
|
370
350
|
|
|
@@ -377,7 +357,7 @@ class Balances extends ExodusModule {
|
|
|
377
357
|
const createBalances = (opts) => new Balances(opts)
|
|
378
358
|
|
|
379
359
|
const balancesDefinition = {
|
|
380
|
-
id:
|
|
360
|
+
id: 'balances',
|
|
381
361
|
type: 'module',
|
|
382
362
|
factory: createBalances,
|
|
383
363
|
dependencies: [
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/balances",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.4.0",
|
|
4
4
|
"description": "Tracks crypto balances across enabled wallet accounts.",
|
|
5
5
|
"author": "Exodus Movement, Inc.",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "run -T exodus-test --jest",
|
|
9
9
|
"lint": "run -T eslint -c ../../eslint.config.mjs",
|
|
@@ -33,12 +33,11 @@
|
|
|
33
33
|
"url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abalances"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@exodus/atoms": "^
|
|
36
|
+
"@exodus/atoms": "^9.0.0",
|
|
37
37
|
"@exodus/basic-utils": "^3.0.1",
|
|
38
38
|
"@exodus/core-selectors": "^3.0.0",
|
|
39
39
|
"@exodus/currency": "^5.0.2",
|
|
40
40
|
"@exodus/models": "^12.0.1",
|
|
41
|
-
"@exodus/module": "^1.3.0",
|
|
42
41
|
"@exodus/multi-account-redux": "^2.0.1",
|
|
43
42
|
"@exodus/redux-dependency-injection": "^4.0.3",
|
|
44
43
|
"@exodus/typeforce": "^1.18.0",
|
|
@@ -52,17 +51,19 @@
|
|
|
52
51
|
"devDependencies": {
|
|
53
52
|
"@exodus/assets": "^11.0.0",
|
|
54
53
|
"@exodus/assets-base": "^10.0.0",
|
|
55
|
-
"@exodus/assets-feature": "^5.
|
|
56
|
-
"@exodus/available-assets": "^8.
|
|
54
|
+
"@exodus/assets-feature": "^5.14.1",
|
|
55
|
+
"@exodus/available-assets": "^8.7.0",
|
|
57
56
|
"@exodus/bitcoin-meta": "^2.0.0",
|
|
58
|
-
"@exodus/blockchain-metadata": "^15.
|
|
57
|
+
"@exodus/blockchain-metadata": "^15.7.0",
|
|
59
58
|
"@exodus/ethereum-meta": "^2.0.0",
|
|
60
|
-
"@exodus/fee-data-monitors": "^
|
|
61
|
-
"@exodus/
|
|
62
|
-
"@exodus/
|
|
63
|
-
"@exodus/wallet-accounts": "^16.10.2",
|
|
59
|
+
"@exodus/fee-data-monitors": "^5.0.2",
|
|
60
|
+
"@exodus/storage-memory": "^2.2.2",
|
|
61
|
+
"@exodus/wallet-accounts": "^17.1.1",
|
|
64
62
|
"events": "^3.3.0",
|
|
65
63
|
"redux": "^4.2.1"
|
|
66
64
|
},
|
|
67
|
-
"
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
},
|
|
68
|
+
"gitHead": "901254d521ab3c43da0be4a4537ed80015e1c6b9"
|
|
68
69
|
}
|
package/redux/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import id from './id.js'
|
|
|
2
2
|
import initialState from './initial-state.js'
|
|
3
3
|
import selectorDefinitions from './selectors/index.js'
|
|
4
4
|
import { mapValues } from '@exodus/basic-utils'
|
|
5
|
-
// eslint-disable-next-line @exodus/restricted-imports/prefer-basic-utils
|
|
6
5
|
import lodash from 'lodash'
|
|
7
6
|
import helper from './multi-account-helper.js'
|
|
8
7
|
import { setAccounts } from '@exodus/multi-account-redux/src/common.js'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import lodash from 'lodash'
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import { MY_STATE } from '@exodus/redux-dependency-injection'
|
|
3
3
|
import { createSelector } from 'reselect'
|
|
4
4
|
|
|
5
|
-
const { memoize } = lodash
|
|
5
|
+
const { memoize } = lodash // eslint-disable-line @exodus/basic-utils/prefer-basic-utils
|
|
6
6
|
|
|
7
7
|
const createBalanceSelectorFactory = ({ field, id }) => {
|
|
8
8
|
const selectorFactory = (selfSelector) =>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import lodash from 'lodash'
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import { createSelector } from 'reselect'
|
|
3
3
|
import { isNumberUnit } from '@exodus/currency'
|
|
4
4
|
|
|
5
|
-
const { memoize } = lodash
|
|
5
|
+
const { memoize } = lodash // eslint-disable-line @exodus/basic-utils/prefer-basic-utils
|
|
6
6
|
|
|
7
7
|
const selectorFactory = (getFeeDataSelector, assetsSelector) =>
|
|
8
8
|
memoize((assetName) =>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import lodash from 'lodash'
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import { createSelector } from 'reselect'
|
|
3
3
|
import { getUnconfirmedBalance } from './get-unconfirmed-balance.js'
|
|
4
4
|
|
|
5
|
-
const { memoize } = lodash
|
|
5
|
+
const { memoize } = lodash // eslint-disable-line @exodus/basic-utils/prefer-basic-utils
|
|
6
6
|
|
|
7
7
|
const selectorFactory = (assetsSelector, createAssetSourceSelector) =>
|
|
8
8
|
memoize(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import lodash from 'lodash'
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import defaultConfig from '../../default-config.js'
|
|
3
3
|
|
|
4
|
-
const { memoize } = lodash
|
|
4
|
+
const { memoize } = lodash // eslint-disable-line @exodus/basic-utils/prefer-basic-utils
|
|
5
5
|
|
|
6
6
|
const { balanceFields } = defaultConfig
|
|
7
7
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
// eslint-disable-next-line @exodus/restricted-imports/prefer-basic-utils
|
|
2
1
|
import lodash from 'lodash'
|
|
3
2
|
|
|
4
|
-
const { memoize } = lodash
|
|
3
|
+
const { memoize } = lodash // eslint-disable-line @exodus/basic-utils/prefer-basic-utils
|
|
5
4
|
|
|
6
5
|
const createResultFunction = (field) => (getBalanceForField) =>
|
|
7
6
|
memoize(
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import lodash from 'lodash'
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import { createSelector } from 'reselect'
|
|
3
3
|
import { MY_STATE } from '@exodus/redux-dependency-injection'
|
|
4
4
|
|
|
5
|
-
const { memoize } = lodash
|
|
5
|
+
const { memoize } = lodash // eslint-disable-line @exodus/basic-utils/prefer-basic-utils
|
|
6
6
|
|
|
7
7
|
const selectorFactory = (selfSelector) =>
|
|
8
8
|
createSelector(selfSelector, (balances) =>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import lodash from 'lodash'
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import { createSelector } from 'reselect'
|
|
3
3
|
|
|
4
|
-
const { memoize } = lodash
|
|
4
|
+
const { memoize } = lodash // eslint-disable-line @exodus/basic-utils/prefer-basic-utils
|
|
5
5
|
|
|
6
6
|
export const getUnconfirmedBalance = ({ asset, txs }) => {
|
|
7
7
|
let result = asset.currency.ZERO
|