@exodus/balances 11.0.3 → 11.2.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 +12 -0
- package/module/index.js +35 -14
- package/package.json +5 -5
- package/redux/selectors/create-unconfirmed-balance.js +39 -0
- package/redux/selectors/index.js +3 -1
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
|
+
## [11.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@11.1.0...@exodus/balances@11.2.0) (2023-10-25)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- add selector to compute unconfirmed balance ([#4552](https://github.com/ExodusMovement/exodus-hydra/issues/4552)) ([a3b5217](https://github.com/ExodusMovement/exodus-hydra/commit/a3b52173c5cf3dd23aa7f1f21aea62f9e09f6b58))
|
|
11
|
+
|
|
12
|
+
## [11.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@11.0.3...@exodus/balances@11.1.0) (2023-10-20)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- warn on different number unit ([#4512](https://github.com/ExodusMovement/exodus-hydra/issues/4512)) ([d11cbc7](https://github.com/ExodusMovement/exodus-hydra/commit/d11cbc770535cb5f978526d5634a391b1bd4146f))
|
|
17
|
+
|
|
6
18
|
## [11.0.3](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@11.0.2...@exodus/balances@11.0.3) (2023-10-20)
|
|
7
19
|
|
|
8
20
|
### Bug Fixes
|
package/module/index.js
CHANGED
|
@@ -21,7 +21,6 @@ export const MODULE_ID = 'balances'
|
|
|
21
21
|
|
|
22
22
|
class Balances extends ExodusModule {
|
|
23
23
|
#assetsModule
|
|
24
|
-
#blockchainMetadata
|
|
25
24
|
#balanceFields
|
|
26
25
|
#walletAccounts = [] // string[]
|
|
27
26
|
#ready = false
|
|
@@ -36,7 +35,6 @@ class Balances extends ExodusModule {
|
|
|
36
35
|
|
|
37
36
|
constructor({
|
|
38
37
|
assetsModule,
|
|
39
|
-
blockchainMetadata,
|
|
40
38
|
enabledWalletAccountsAtom,
|
|
41
39
|
config: { balanceFields },
|
|
42
40
|
logger,
|
|
@@ -47,7 +45,6 @@ class Balances extends ExodusModule {
|
|
|
47
45
|
super({ name: MODULE_ID, logger })
|
|
48
46
|
|
|
49
47
|
this.#assetsModule = assetsModule
|
|
50
|
-
this.#blockchainMetadata = blockchainMetadata
|
|
51
48
|
this.#balanceFields = balanceFields
|
|
52
49
|
this.#balancesAtom = balancesAtom
|
|
53
50
|
this.#accountStatesAtom = accountStatesAtom
|
|
@@ -163,7 +160,27 @@ class Balances extends ExodusModule {
|
|
|
163
160
|
const asset = this.#getAsset(assetName)
|
|
164
161
|
const txLog = txLogsByAssetName[assetName]
|
|
165
162
|
const balances = asset.api.getBalances({ asset, accountState, txLog })
|
|
166
|
-
if (!balances || isEmpty(balances)) return null
|
|
163
|
+
if (!balances || isEmpty(balances) || !balances.balance) return null
|
|
164
|
+
if (!balances.balance.unitType.equals(asset.currency)) {
|
|
165
|
+
this.emit('error', {
|
|
166
|
+
fn: 'getAssetBalances',
|
|
167
|
+
error: 'asset.api.getBalances returns different currency',
|
|
168
|
+
args: {
|
|
169
|
+
balanceUnit: balances.balance.unitType.defaultUnit.unitName,
|
|
170
|
+
assetUnit: asset.currency.defaultUnit.unitName,
|
|
171
|
+
},
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
this._logger.warn(
|
|
175
|
+
'asset.api.getBalances returns different currency, asset currency:',
|
|
176
|
+
asset.currency.defaultUnit.unitName,
|
|
177
|
+
'balance currency',
|
|
178
|
+
balances.balance.unitType.defaultUnit.unitName,
|
|
179
|
+
'return zero balance for it'
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
return Object.fromEntries(this.#balanceFields.map((field) => [field, asset.currency.ZERO]))
|
|
183
|
+
}
|
|
167
184
|
|
|
168
185
|
if (balances.balance && this.#balanceFields.includes('confirmedBalance')) {
|
|
169
186
|
balances.confirmedBalance = getConfirmedBalance({
|
|
@@ -257,15 +274,20 @@ class Balances extends ExodusModule {
|
|
|
257
274
|
accountState: providedAccountState = null,
|
|
258
275
|
txLogsByAssetName: providedTxLogsByAssetName = {},
|
|
259
276
|
}) => {
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
277
|
+
const { value: txLogsByAssetSource } = await this.#txLogsAtom.get()
|
|
278
|
+
let accountState = providedAccountState
|
|
279
|
+
if (!accountState) {
|
|
280
|
+
const asset = this.#getAsset(assetName).baseAsset
|
|
281
|
+
const assetNameToUse = asset.name
|
|
282
|
+
const { value } = await this.#accountStatesAtom.get()
|
|
283
|
+
const cached = value[walletAccount]?.[assetNameToUse]
|
|
284
|
+
if (cached) {
|
|
285
|
+
accountState = cached
|
|
286
|
+
} else {
|
|
287
|
+
const AccountState = asset.api?.createAccountState?.()
|
|
288
|
+
accountState = AccountState?.create()
|
|
289
|
+
}
|
|
290
|
+
}
|
|
269
291
|
|
|
270
292
|
const assetNames = this.#getRelatedAssetNames(assetName)
|
|
271
293
|
const txLogsByAssetName = zipObject(
|
|
@@ -368,7 +390,6 @@ const balancesDefinition = {
|
|
|
368
390
|
factory: createBalances,
|
|
369
391
|
dependencies: [
|
|
370
392
|
'assetsModule',
|
|
371
|
-
'blockchainMetadata',
|
|
372
393
|
'enabledWalletAccountsAtom',
|
|
373
394
|
'config',
|
|
374
395
|
'logger',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/balances",
|
|
3
|
-
"version": "11.0
|
|
3
|
+
"version": "11.2.0",
|
|
4
4
|
"description": "Tracks crypto balances across enabled wallet accounts.",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abalances"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@exodus/atoms": "^
|
|
32
|
+
"@exodus/atoms": "^6.0.0",
|
|
33
33
|
"@exodus/basic-utils": "^2.1.0",
|
|
34
34
|
"@exodus/currency": "^2.1.2",
|
|
35
35
|
"@exodus/module": "^1.1.0",
|
|
@@ -45,18 +45,18 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@exodus/assets": "^8.0.94",
|
|
47
47
|
"@exodus/assets-base": "^8.1.10",
|
|
48
|
-
"@exodus/assets-feature": "^3.
|
|
48
|
+
"@exodus/assets-feature": "^3.7.0",
|
|
49
49
|
"@exodus/bitcoin-meta": "^1.0.1",
|
|
50
50
|
"@exodus/blockchain-metadata": "^9.0.1",
|
|
51
51
|
"@exodus/ethereum-meta": "^1.0.30",
|
|
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": "^14.
|
|
55
|
+
"@exodus/wallet-accounts": "^14.2.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": "8b3bfdde1a35b05e6f42445f5d40a573a68d919b"
|
|
62
62
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { memoize } from 'lodash'
|
|
2
|
+
import { createSelector } from 'reselect'
|
|
3
|
+
|
|
4
|
+
const selectorFactory = (assetsSelector, createAssetSourceSelector) =>
|
|
5
|
+
memoize(
|
|
6
|
+
({ assetName, walletAccount }) =>
|
|
7
|
+
createSelector(
|
|
8
|
+
assetsSelector,
|
|
9
|
+
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 isUnconfirmed = tx.error || tx.pending || tx.confirmations <= 0
|
|
16
|
+
|
|
17
|
+
if (isUnconfirmed) {
|
|
18
|
+
result = tx.coinAmount.isNegative
|
|
19
|
+
? result.sub(tx.coinAmount)
|
|
20
|
+
: result.add(tx.coinAmount)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return result
|
|
25
|
+
}
|
|
26
|
+
),
|
|
27
|
+
({ assetName, walletAccount }) => [assetName, walletAccount].join('-')
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const createUnconfirmedBalanceSelectorDefinition = {
|
|
31
|
+
id: 'createUnconfirmedBalance',
|
|
32
|
+
selectorFactory,
|
|
33
|
+
dependencies: [
|
|
34
|
+
{ module: 'assets', selector: 'all' },
|
|
35
|
+
{ module: 'txLog', selector: 'createAssetSourceSelector' },
|
|
36
|
+
],
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default createUnconfirmedBalanceSelectorDefinition
|
package/redux/selectors/index.js
CHANGED