@exodus/balances 12.1.0 → 12.3.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.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@12.2.0...@exodus/balances@12.3.0) (2024-01-05)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- 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))
|
|
11
|
+
|
|
12
|
+
## [12.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@12.1.0...@exodus/balances@12.2.0) (2024-01-03)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- **balances:** new unconfirmed balance selector to improve performance ([#5234](https://github.com/ExodusMovement/exodus-hydra/issues/5234)) ([9c97b66](https://github.com/ExodusMovement/exodus-hydra/commit/9c97b6618c0fa494763d76431aa4bbf915495091))
|
|
17
|
+
|
|
6
18
|
## [12.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@12.0.1...@exodus/balances@12.1.0) (2023-12-14)
|
|
7
19
|
|
|
8
20
|
### Features
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/balances",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.3.0",
|
|
4
4
|
"description": "Tracks crypto balances across enabled wallet accounts.",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"@exodus/models": "^10.1.0",
|
|
53
53
|
"@exodus/redux-dependency-injection": "^3.0.0",
|
|
54
54
|
"@exodus/storage-memory": "*",
|
|
55
|
-
"@exodus/wallet-accounts": "^15.
|
|
55
|
+
"@exodus/wallet-accounts": "^15.1.0",
|
|
56
56
|
"eslint": "^8.44.0",
|
|
57
57
|
"events": "^3.3.0",
|
|
58
58
|
"jest": "^29.1.2",
|
|
59
59
|
"redux": "^4.2.1"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "cd84b0179161212d65a695d8b61e91f154b2ecaa"
|
|
62
62
|
}
|
|
@@ -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,5 +1,6 @@
|
|
|
1
1
|
import { memoize } from 'lodash'
|
|
2
2
|
import { createSelector } from 'reselect'
|
|
3
|
+
import { getUnconfirmedBalance } from './get-unconfirmed-balance'
|
|
3
4
|
|
|
4
5
|
const selectorFactory = (assetsSelector, createAssetSourceSelector) =>
|
|
5
6
|
memoize(
|
|
@@ -7,21 +8,7 @@ const selectorFactory = (assetsSelector, createAssetSourceSelector) =>
|
|
|
7
8
|
createSelector(
|
|
8
9
|
assetsSelector,
|
|
9
10
|
createAssetSourceSelector({ assetName, walletAccount }),
|
|
10
|
-
(assets, txs) => {
|
|
11
|
-
const asset = assets[assetName]
|
|
12
|
-
let result = asset.currency.ZERO
|
|
13
|
-
|
|
14
|
-
for (const tx of txs) {
|
|
15
|
-
const isIncommingTX = tx.coinAmount.isPositive
|
|
16
|
-
const isUnconfirmed = !tx.failed && tx.pending
|
|
17
|
-
|
|
18
|
-
if (isUnconfirmed) {
|
|
19
|
-
result = isIncommingTX ? result.add(tx.coinAmount) : result.sub(tx.coinAmount)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return result
|
|
24
|
-
}
|
|
11
|
+
(assets, txs) => getUnconfirmedBalance({ asset: assets[assetName], txs })
|
|
25
12
|
),
|
|
26
13
|
({ assetName, walletAccount }) => [assetName, walletAccount].join('-')
|
|
27
14
|
)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { memoize } from 'lodash'
|
|
2
|
+
import { createSelector } from 'reselect'
|
|
3
|
+
|
|
4
|
+
export const getUnconfirmedBalance = ({ asset, txs }) => {
|
|
5
|
+
let result = asset.currency.ZERO
|
|
6
|
+
|
|
7
|
+
for (const tx of txs) {
|
|
8
|
+
const isIncommingTX = tx.coinAmount.isPositive
|
|
9
|
+
const isUnconfirmed = !tx.failed && tx.pending
|
|
10
|
+
|
|
11
|
+
if (isUnconfirmed) {
|
|
12
|
+
result = isIncommingTX ? result.add(tx.coinAmount) : result.sub(tx.coinAmount)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return result
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const selectorFactory = (assetsSelector, createAssetSourceSelector) =>
|
|
20
|
+
createSelector(assetsSelector, createAssetSourceSelector, (assets, getTxs) =>
|
|
21
|
+
memoize(
|
|
22
|
+
({ assetName, walletAccount }) =>
|
|
23
|
+
getUnconfirmedBalance({
|
|
24
|
+
asset: assets[assetName],
|
|
25
|
+
txs: getTxs({ assetName, walletAccount }),
|
|
26
|
+
}),
|
|
27
|
+
({ assetName, walletAccount }) => [assetName, walletAccount].join('-')
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
const getUnconfirmedBalanceSelectorDefinition = {
|
|
32
|
+
id: 'getUnconfirmedBalance',
|
|
33
|
+
selectorFactory,
|
|
34
|
+
dependencies: [
|
|
35
|
+
{ module: 'assets', selector: 'all' },
|
|
36
|
+
{ module: 'txLog', selector: 'createAssetSourceSelectorOld' },
|
|
37
|
+
],
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default getUnconfirmedBalanceSelectorDefinition
|
package/redux/selectors/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import byAssetSelectorDefinition from './by-asset'
|
|
1
2
|
import createUnconfirmedBalanceSelectorDefinition from './create-unconfirmed-balance'
|
|
3
|
+
import getUnconfirmedBalanceSelectorDefinition from './get-unconfirmed-balance'
|
|
2
4
|
|
|
3
|
-
export default [
|
|
5
|
+
export default [
|
|
6
|
+
byAssetSelectorDefinition,
|
|
7
|
+
createUnconfirmedBalanceSelectorDefinition,
|
|
8
|
+
getUnconfirmedBalanceSelectorDefinition,
|
|
9
|
+
]
|