@exodus/balances 5.0.0 → 6.0.1
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 +15 -0
- package/atoms/balances.js +5 -0
- package/atoms/index.js +8 -0
- package/module/index.js +23 -15
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
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
|
+
## [6.0.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@6.0.0...@exodus/balances@6.0.1) (2023-06-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @exodus/balances
|
|
9
|
+
|
|
10
|
+
## [6.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@5.0.0...@exodus/balances@6.0.0) (2023-04-25)
|
|
11
|
+
|
|
12
|
+
### ⚠ BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
- replace emit with atom in balances module (#1349)
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
- add balancesAtom definition ([#1362](https://github.com/ExodusMovement/exodus-hydra/issues/1362)) ([4d126ef](https://github.com/ExodusMovement/exodus-hydra/commit/4d126efef79655178ec1e1faf65b347497ad8647))
|
|
19
|
+
- replace emit with atom in balances module ([#1349](https://github.com/ExodusMovement/exodus-hydra/issues/1349)) ([f9110f8](https://github.com/ExodusMovement/exodus-hydra/commit/f9110f8e9e76b8b199bc4d40461cb1bed3a5be1e))
|
|
20
|
+
|
|
6
21
|
## [5.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@4.0.0...@exodus/balances@5.0.0) (2023-03-14)
|
|
7
22
|
|
|
8
23
|
### ⚠ BREAKING CHANGES
|
package/atoms/index.js
ADDED
package/module/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isNumberUnit } from '@exodus/currency'
|
|
2
2
|
import { TxSet } from '@exodus/models'
|
|
3
3
|
import ExodusModule from '@exodus/module'
|
|
4
|
-
import { cloneDeepWith,
|
|
4
|
+
import { cloneDeepWith, isEmpty, merge, set, zipObject } from 'lodash'
|
|
5
|
+
import { difference, flattenToPaths } from '@exodus/basic-utils'
|
|
5
6
|
import makeConcurrent from 'make-concurrent'
|
|
6
7
|
import getConfirmedBalance from './confirmed-balance'
|
|
7
|
-
import { flattenToPaths } from '@exodus/basic-utils'
|
|
8
8
|
|
|
9
9
|
const cloneBalances = (balances) =>
|
|
10
10
|
cloneDeepWith(balances, (val) => {
|
|
@@ -23,24 +23,27 @@ class Balances extends ExodusModule {
|
|
|
23
23
|
#assetsModule
|
|
24
24
|
#blockchainMetadata
|
|
25
25
|
#balanceFields
|
|
26
|
-
#walletAccounts =
|
|
26
|
+
#walletAccounts = [] // string[]
|
|
27
27
|
#ready = false
|
|
28
28
|
|
|
29
29
|
#oldBalances = Object.create(null)
|
|
30
30
|
#balances = Object.create(null)
|
|
31
|
+
#balancesAtom
|
|
31
32
|
|
|
32
33
|
constructor({
|
|
33
34
|
assetsModule,
|
|
34
35
|
blockchainMetadata,
|
|
35
|
-
|
|
36
|
+
enabledWalletAccountsAtom,
|
|
36
37
|
config: { balanceFields },
|
|
37
38
|
logger,
|
|
39
|
+
balancesAtom,
|
|
38
40
|
}) {
|
|
39
41
|
super({ name: MODULE_ID, logger })
|
|
40
42
|
|
|
41
43
|
this.#assetsModule = assetsModule
|
|
42
44
|
this.#blockchainMetadata = blockchainMetadata
|
|
43
45
|
this.#balanceFields = balanceFields
|
|
46
|
+
this.#balancesAtom = balancesAtom
|
|
44
47
|
|
|
45
48
|
const shareQueue =
|
|
46
49
|
(fn) =>
|
|
@@ -57,10 +60,8 @@ class Balances extends ExodusModule {
|
|
|
57
60
|
|
|
58
61
|
blockchainMetadata.once('load-wallet-accounts', () => {
|
|
59
62
|
// eslint-disable-next-line hydra/module-side-effects
|
|
60
|
-
|
|
61
|
-
this.#setWalletAccounts(
|
|
62
|
-
Object.keys(payload).filter((walletAccount) => payload[walletAccount].enabled)
|
|
63
|
-
)
|
|
63
|
+
enabledWalletAccountsAtom.observe((payload) => {
|
|
64
|
+
this.#setWalletAccounts(Object.keys(payload))
|
|
64
65
|
})
|
|
65
66
|
|
|
66
67
|
blockchainMetadata.on('account-states-update', (payload) =>
|
|
@@ -189,7 +190,7 @@ class Balances extends ExodusModule {
|
|
|
189
190
|
this._logger.log('recomputing after adding walletAccounts', added)
|
|
190
191
|
this.#recompute({ walletAccounts: added })
|
|
191
192
|
} else {
|
|
192
|
-
this
|
|
193
|
+
this.#flush()
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
|
|
@@ -268,7 +269,7 @@ class Balances extends ExodusModule {
|
|
|
268
269
|
})
|
|
269
270
|
|
|
270
271
|
const changes = Object.create(null)
|
|
271
|
-
for (
|
|
272
|
+
for (const subAssetName in newBalances) {
|
|
272
273
|
const { currency } = this.#getAsset(subAssetName)
|
|
273
274
|
const newAssetBalances = newBalances?.[subAssetName]
|
|
274
275
|
// e.g. totalBalance or spendableBalance
|
|
@@ -288,23 +289,23 @@ class Balances extends ExodusModule {
|
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
291
|
|
|
291
|
-
if (!isEmpty(changes)) this
|
|
292
|
+
if (!isEmpty(changes)) this.#flush({ changes })
|
|
292
293
|
}
|
|
293
294
|
|
|
294
295
|
#recompute = async ({ walletAccounts = this.#walletAccounts } = {}) => {
|
|
295
296
|
this.#reset({ walletAccounts })
|
|
296
297
|
await Promise.all(walletAccounts.map((walletAccount) => this.#load({ walletAccount })))
|
|
297
|
-
this
|
|
298
|
+
this.#flush()
|
|
298
299
|
}
|
|
299
300
|
|
|
300
|
-
|
|
301
|
+
#flush = ({ changes } = {}) => {
|
|
301
302
|
const oldBalances = this.#oldBalances
|
|
302
303
|
const balances = cloneBalances(this.#balances)
|
|
303
304
|
|
|
304
305
|
if (Object.keys(balances).length === 0) return // wait till `load` finished
|
|
305
306
|
|
|
306
307
|
this._logger.log('balances updated')
|
|
307
|
-
this.
|
|
308
|
+
this.#balancesAtom.set({
|
|
308
309
|
balances,
|
|
309
310
|
oldBalances,
|
|
310
311
|
changes,
|
|
@@ -320,5 +321,12 @@ export default {
|
|
|
320
321
|
id: MODULE_ID,
|
|
321
322
|
type: 'module',
|
|
322
323
|
factory: createBalances,
|
|
323
|
-
dependencies: [
|
|
324
|
+
dependencies: [
|
|
325
|
+
'assetsModule',
|
|
326
|
+
'blockchainMetadata',
|
|
327
|
+
'enabledWalletAccountsAtom',
|
|
328
|
+
'config',
|
|
329
|
+
'logger',
|
|
330
|
+
'balancesAtom',
|
|
331
|
+
],
|
|
324
332
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/balances",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "balances",
|
|
5
5
|
"author": "Exodus Movement Inc",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abalances"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@exodus/
|
|
28
|
+
"@exodus/atoms": "^5.0.0",
|
|
29
|
+
"@exodus/basic-utils": "^2.0.0",
|
|
29
30
|
"@exodus/currency": "^2.1.2",
|
|
30
31
|
"@exodus/module": "^1.1.0",
|
|
31
32
|
"lodash": "^4.17.21",
|
|
@@ -35,14 +36,13 @@
|
|
|
35
36
|
"@exodus/blockchain-metadata": "^6.0.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@exodus/atoms": "^3.0.0",
|
|
39
39
|
"@exodus/blockchain-metadata": "^8.0.0",
|
|
40
40
|
"@exodus/models": "^8.9.0",
|
|
41
41
|
"@exodus/storage-memory": "*",
|
|
42
|
-
"@exodus/wallet-accounts": "
|
|
42
|
+
"@exodus/wallet-accounts": "^9.1.0",
|
|
43
43
|
"eslint": "^8.33.0",
|
|
44
44
|
"events": "^3.3.0",
|
|
45
45
|
"jest": "^29.1.2"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "f0a3d249bf994a6d5c106a106b5e4b2b6c61a6e8"
|
|
48
48
|
}
|