@exodus/fiat-balances 13.6.3 → 13.7.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 +12 -0
- package/module/fiat-balances.js +80 -51
- package/package.json +8 -8
- package/redux/selectors/conversions.js +1 -1
- package/redux/selectors/create-asset-conversion-usd.js +3 -3
- package/redux/selectors/create-asset-conversion.js +3 -3
- package/redux/selectors/create-conversion.js +3 -3
- package/redux/selectors/create-conversions.js +1 -2
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
|
+
## [13.7.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@13.7.0...@exodus/fiat-balances@13.7.1) (2026-02-03)
|
|
7
|
+
|
|
8
|
+
### Performance
|
|
9
|
+
|
|
10
|
+
- perf(fiat-balances): reduce allocations in recompute (#15162)
|
|
11
|
+
|
|
12
|
+
## [13.7.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@13.6.3...@exodus/fiat-balances@13.7.0) (2026-01-21)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- feat: filter out combined assets without members (#14961)
|
|
17
|
+
|
|
6
18
|
## [13.6.3](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@13.6.2...@exodus/fiat-balances@13.6.3) (2025-11-24)
|
|
7
19
|
|
|
8
20
|
### Bug Fixes
|
package/module/fiat-balances.js
CHANGED
|
@@ -72,27 +72,28 @@ class FiatBalances {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
#isReady = () => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
const rates = this.#cachedRates?.[this.#fiatCurrency]
|
|
76
|
+
if (!this.#cachedRates || !this.#fiatCurrency || !this.#latestAssetBalances || !rates) {
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (const ticker in rates) {
|
|
81
|
+
if (!rates[ticker]?.invalid) return true
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return false
|
|
82
85
|
}
|
|
83
86
|
|
|
84
|
-
#convertToFiat = ({
|
|
87
|
+
#convertToFiat = ({ asset, value }) => {
|
|
85
88
|
const fiatCurrency = fiatCurrencies[this.#fiatCurrency]
|
|
86
89
|
if (value.isZero) return fiatCurrency.ZERO
|
|
87
|
-
const rates = this.#cachedRates[this.#fiatCurrency]
|
|
88
|
-
const
|
|
89
|
-
let fiatRate
|
|
90
|
+
const rates = this.#cachedRates?.[this.#fiatCurrency]
|
|
91
|
+
const ticker = asset.ticker
|
|
90
92
|
// HACK: Super hacky, terrible, the rates state object should have the prices split up by sub-objects per fiat
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
93
|
+
const fiatRate =
|
|
94
|
+
fiatCurrency.defaultUnit.unitName === 'USD'
|
|
95
|
+
? rates?.[ticker]?.priceUSD || 0
|
|
96
|
+
: rates?.[ticker]?.price || 0
|
|
96
97
|
|
|
97
98
|
if (fiatRate === 0) return fiatCurrency.ZERO
|
|
98
99
|
|
|
@@ -110,45 +111,72 @@ class FiatBalances {
|
|
|
110
111
|
const { byAssetSource, byBaseAssetSource, byWalletAccount, byAsset } = this.#balances
|
|
111
112
|
const fiatZero = fiatCurrencies[this.#fiatCurrency].ZERO
|
|
112
113
|
|
|
113
|
-
|
|
114
|
+
for (const walletAccount in balances) {
|
|
114
115
|
const walletAccountBalances = balances[walletAccount]
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
116
|
+
const walletTotals = Object.create(null)
|
|
117
|
+
for (const field of this.#balanceFields) walletTotals[field] = fiatZero
|
|
118
|
+
|
|
119
|
+
let byWalletAccountRef = byWalletAccount[walletAccount]
|
|
120
|
+
if (!byWalletAccountRef) {
|
|
121
|
+
byWalletAccountRef = Object.create(null)
|
|
122
|
+
byWalletAccount[walletAccount] = byWalletAccountRef
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let byAssetSourceWalletRef = byAssetSource[walletAccount]
|
|
126
|
+
if (!byAssetSourceWalletRef) {
|
|
127
|
+
byAssetSourceWalletRef = Object.create(null)
|
|
128
|
+
byAssetSource[walletAccount] = byAssetSourceWalletRef
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let byBaseAssetSourceWalletRef = byBaseAssetSource[walletAccount]
|
|
132
|
+
if (!byBaseAssetSourceWalletRef) {
|
|
133
|
+
byBaseAssetSourceWalletRef = Object.create(null)
|
|
134
|
+
byBaseAssetSource[walletAccount] = byBaseAssetSourceWalletRef
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
for (const assetName in walletAccountBalances) {
|
|
138
|
+
const assetBalances = walletAccountBalances[assetName]
|
|
139
|
+
if (!assetBalances) continue
|
|
140
|
+
const asset = this.#assetsModule.getAsset(assetName)
|
|
141
|
+
const baseAssetName = asset.baseAsset.name
|
|
142
|
+
|
|
143
|
+
let byAssetSourceAssetRef = byAssetSourceWalletRef[assetName]
|
|
144
|
+
if (!byAssetSourceAssetRef) {
|
|
145
|
+
byAssetSourceAssetRef = Object.create(null)
|
|
146
|
+
byAssetSourceWalletRef[assetName] = byAssetSourceAssetRef
|
|
147
|
+
}
|
|
135
148
|
|
|
136
|
-
|
|
149
|
+
let byBaseAssetSourceAssetRef = byBaseAssetSourceWalletRef[baseAssetName]
|
|
150
|
+
if (!byBaseAssetSourceAssetRef) {
|
|
151
|
+
byBaseAssetSourceAssetRef = Object.create(null)
|
|
152
|
+
byBaseAssetSourceWalletRef[baseAssetName] = byBaseAssetSourceAssetRef
|
|
153
|
+
}
|
|
137
154
|
|
|
138
|
-
|
|
139
|
-
|
|
155
|
+
let byAssetRef = byAsset[assetName]
|
|
156
|
+
if (!byAssetRef) {
|
|
157
|
+
byAssetRef = Object.create(null)
|
|
158
|
+
byAsset[assetName] = byAssetRef
|
|
159
|
+
}
|
|
140
160
|
|
|
141
|
-
|
|
142
|
-
|
|
161
|
+
for (const field of this.#balanceFields) {
|
|
162
|
+
const balance = assetBalances[field]
|
|
163
|
+
if (!balance) continue
|
|
143
164
|
|
|
144
|
-
|
|
165
|
+
const fiatValue = this.#convertToFiat({ value: balance, asset })
|
|
145
166
|
|
|
146
|
-
|
|
147
|
-
|
|
167
|
+
byAssetSourceAssetRef[field] = (byAssetSourceAssetRef[field] || fiatZero).add(fiatValue)
|
|
168
|
+
byBaseAssetSourceAssetRef[field] = (byBaseAssetSourceAssetRef[field] || fiatZero).add(
|
|
169
|
+
fiatValue
|
|
170
|
+
)
|
|
171
|
+
byAssetRef[field] = (byAssetRef[field] || fiatZero).add(fiatValue)
|
|
172
|
+
walletTotals[field] = walletTotals[field].add(fiatValue)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
148
175
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
176
|
+
for (const field of this.#balanceFields) {
|
|
177
|
+
byWalletAccountRef[field] = walletTotals[field]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
152
180
|
|
|
153
181
|
this.#recomputeWalletTotals()
|
|
154
182
|
}
|
|
@@ -176,7 +204,8 @@ class FiatBalances {
|
|
|
176
204
|
const walletAccountBalances = byWalletAccount[walletAccount]
|
|
177
205
|
Object.entries(walletAccountBalancesChanges).forEach(
|
|
178
206
|
([assetName, assetSourceBalancesChanges]) => {
|
|
179
|
-
const
|
|
207
|
+
const asset = this.#assetsModule.getAsset(assetName)
|
|
208
|
+
const baseAssetName = asset.baseAsset.name
|
|
180
209
|
this.#balanceFields.forEach((field) => {
|
|
181
210
|
// we may not be interested in all fields from `balances`
|
|
182
211
|
if (!assetSourceBalancesChanges[field]) return
|
|
@@ -184,8 +213,8 @@ class FiatBalances {
|
|
|
184
213
|
const { from, to } = assetSourceBalancesChanges[field]
|
|
185
214
|
walletAccountBalances[field] = walletAccountBalances[field] || fiatZero
|
|
186
215
|
|
|
187
|
-
const fromFiatValue = this.#convertToFiat({
|
|
188
|
-
const toFiatValue = this.#convertToFiat({
|
|
216
|
+
const fromFiatValue = this.#convertToFiat({ value: from, asset })
|
|
217
|
+
const toFiatValue = this.#convertToFiat({ value: to, asset })
|
|
189
218
|
|
|
190
219
|
if (fromFiatValue.equals(toFiatValue)) return
|
|
191
220
|
needsFlush = true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/fiat-balances",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.7.1",
|
|
4
4
|
"description": "Track asset and portfolio fiat balances based on changes in crypto balances and the user's preferred fiat currency",
|
|
5
5
|
"author": "Exodus Movement, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@exodus/assets": "^11.0.0",
|
|
48
48
|
"@exodus/assets-base": "^10.0.0",
|
|
49
|
-
"@exodus/assets-feature": "^8.
|
|
50
|
-
"@exodus/available-assets": "^8.
|
|
51
|
-
"@exodus/balances": "^13.
|
|
52
|
-
"@exodus/blockchain-metadata": "^
|
|
49
|
+
"@exodus/assets-feature": "^8.8.0",
|
|
50
|
+
"@exodus/available-assets": "^8.10.1",
|
|
51
|
+
"@exodus/balances": "^13.15.1",
|
|
52
|
+
"@exodus/blockchain-metadata": "^17.1.0",
|
|
53
53
|
"@exodus/combined-assets-meta": "^3.3.2",
|
|
54
|
-
"@exodus/enabled-assets": "^10.
|
|
54
|
+
"@exodus/enabled-assets": "^10.11.0",
|
|
55
55
|
"@exodus/favorite-assets": "^2.6.0",
|
|
56
56
|
"@exodus/fee-data-monitors": "^5.0.4",
|
|
57
|
-
"@exodus/models": "^12.
|
|
57
|
+
"@exodus/models": "^12.19.0",
|
|
58
58
|
"@exodus/rates-monitor": "^4.14.7",
|
|
59
59
|
"@exodus/redux-dependency-injection": "^4.1.2",
|
|
60
60
|
"@exodus/solana-meta": "^2.0.0",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"access": "public",
|
|
68
68
|
"provenance": false
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "08c1bde4a68356e37503376e64d8484115eab442"
|
|
71
71
|
}
|
|
@@ -12,7 +12,7 @@ const conversionsSelectorDefinition = {
|
|
|
12
12
|
dependencies: [
|
|
13
13
|
//
|
|
14
14
|
{ selector: 'currencyUnitType', module: 'locale' },
|
|
15
|
-
{ selector: 'all', module: '
|
|
15
|
+
{ selector: 'all', module: 'availableAssets' },
|
|
16
16
|
{ selector: 'fiatRates', module: 'rates' },
|
|
17
17
|
],
|
|
18
18
|
}
|
|
@@ -5,10 +5,10 @@ import currencies from '@exodus/fiat-currencies'
|
|
|
5
5
|
|
|
6
6
|
const fiatCurrency = currencies.USD
|
|
7
7
|
|
|
8
|
-
const selectorFactory = (
|
|
8
|
+
const selectorFactory = (createAssetSelector, createAssetRateSelector) =>
|
|
9
9
|
memoize((assetName) =>
|
|
10
10
|
createSelector(
|
|
11
|
-
(
|
|
11
|
+
createAssetSelector(assetName),
|
|
12
12
|
createAssetRateSelector(assetName),
|
|
13
13
|
(asset, rate) => {
|
|
14
14
|
const fiatRate = rate?.priceUSD || 0
|
|
@@ -22,7 +22,7 @@ const createConversionSelectorDefinition = {
|
|
|
22
22
|
selectorFactory,
|
|
23
23
|
dependencies: [
|
|
24
24
|
//
|
|
25
|
-
{ selector: '
|
|
25
|
+
{ selector: 'createAssetSelector', module: 'assets' },
|
|
26
26
|
{ selector: 'assetRate', module: 'rates' },
|
|
27
27
|
],
|
|
28
28
|
}
|
|
@@ -2,11 +2,11 @@ import { memoize } from '@exodus/basic-utils'
|
|
|
2
2
|
import { createSelector } from 'reselect'
|
|
3
3
|
import { conversionByRate } from '@exodus/currency'
|
|
4
4
|
|
|
5
|
-
const selectorFactory = (fiatCurrencySelector,
|
|
5
|
+
const selectorFactory = (fiatCurrencySelector, createAssetSelector, createAssetRateSelector) =>
|
|
6
6
|
memoize((assetName) =>
|
|
7
7
|
createSelector(
|
|
8
8
|
fiatCurrencySelector,
|
|
9
|
-
(
|
|
9
|
+
createAssetSelector(assetName),
|
|
10
10
|
createAssetRateSelector(assetName),
|
|
11
11
|
(fiatCurrency, asset, rate) => {
|
|
12
12
|
let fiatRate
|
|
@@ -27,7 +27,7 @@ const createConversionSelectorDefinition = {
|
|
|
27
27
|
dependencies: [
|
|
28
28
|
//
|
|
29
29
|
{ selector: 'currencyUnitType', module: 'locale' },
|
|
30
|
-
{ selector: '
|
|
30
|
+
{ selector: 'createAssetSelector', module: 'assets' },
|
|
31
31
|
{ selector: 'assetRate', module: 'rates' },
|
|
32
32
|
],
|
|
33
33
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getCreateConversion } from '../../shared/get-create-conversion.js'
|
|
2
2
|
import { memoize } from '@exodus/basic-utils'
|
|
3
3
|
|
|
4
|
-
const resultFunction = (fiatCurrency,
|
|
5
|
-
memoize((assetName) => getCreateConversion(fiatCurrency, rates)(
|
|
4
|
+
const resultFunction = (fiatCurrency, getAsset, rates) =>
|
|
5
|
+
memoize((assetName) => getCreateConversion(fiatCurrency, rates)(getAsset(assetName)))
|
|
6
6
|
|
|
7
7
|
const createConversionSelectorDefinition = {
|
|
8
8
|
id: 'createConversion',
|
|
@@ -10,7 +10,7 @@ const createConversionSelectorDefinition = {
|
|
|
10
10
|
dependencies: [
|
|
11
11
|
//
|
|
12
12
|
{ selector: 'currencyUnitType', module: 'locale' },
|
|
13
|
-
{ selector: '
|
|
13
|
+
{ selector: 'getAsset', module: 'assets' },
|
|
14
14
|
{ selector: 'fiatRates', module: 'rates' },
|
|
15
15
|
],
|
|
16
16
|
}
|
|
@@ -15,8 +15,7 @@ const createConversionsSelectorDefinition = {
|
|
|
15
15
|
id: 'createConversions',
|
|
16
16
|
selectorFactory,
|
|
17
17
|
dependencies: [
|
|
18
|
-
|
|
19
|
-
{ module: 'assets', selector: 'all' },
|
|
18
|
+
{ module: 'availableAssets', selector: 'all' },
|
|
20
19
|
{ module: 'rates', selector: 'data' },
|
|
21
20
|
],
|
|
22
21
|
}
|