@exodus/fiat-balances 13.7.0 → 13.7.2
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 +88 -59
- package/package.json +7 -7
- 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.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@13.7.1...@exodus/fiat-balances@13.7.2) (2026-02-25)
|
|
7
|
+
|
|
8
|
+
### Performance
|
|
9
|
+
|
|
10
|
+
- perf(fiat-balances): remove dead isEqual deep comparison from flush (#15352)
|
|
11
|
+
|
|
12
|
+
## [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)
|
|
13
|
+
|
|
14
|
+
### Performance
|
|
15
|
+
|
|
16
|
+
- perf(fiat-balances): reduce allocations in recompute (#15162)
|
|
17
|
+
|
|
6
18
|
## [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)
|
|
7
19
|
|
|
8
20
|
### Features
|
package/module/fiat-balances.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { set } from '@exodus/basic-utils'
|
|
2
2
|
import { isNumberUnit } from '@exodus/currency'
|
|
3
|
-
// eslint-disable-next-line no-restricted-imports -- TODO: Fix this the next time the file is edited.
|
|
4
|
-
import lodash from 'lodash'
|
|
5
3
|
import fiatCurrencies from '@exodus/fiat-currencies'
|
|
6
4
|
import { combine } from '@exodus/atoms'
|
|
7
5
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const areKeysSame = (a, b) => {
|
|
7
|
+
const keysA = Object.keys(a)
|
|
8
|
+
const keysB = Object.keys(b)
|
|
9
|
+
if (keysA.length !== keysB.length) return false
|
|
10
|
+
const aKeySet = new Set(keysA)
|
|
11
|
+
return keysB.every((key) => aKeySet.has(key))
|
|
12
|
+
}
|
|
12
13
|
|
|
13
14
|
export const cloneBalances = (balances) => {
|
|
14
15
|
if (isNumberUnit(balances)) {
|
|
@@ -72,27 +73,28 @@ class FiatBalances {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
#isReady = () => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
const rates = this.#cachedRates?.[this.#fiatCurrency]
|
|
77
|
+
if (!this.#cachedRates || !this.#fiatCurrency || !this.#latestAssetBalances || !rates) {
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const ticker in rates) {
|
|
82
|
+
if (!rates[ticker]?.invalid) return true
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return false
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
#convertToFiat = ({
|
|
88
|
+
#convertToFiat = ({ asset, value }) => {
|
|
85
89
|
const fiatCurrency = fiatCurrencies[this.#fiatCurrency]
|
|
86
90
|
if (value.isZero) return fiatCurrency.ZERO
|
|
87
|
-
const rates = this.#cachedRates[this.#fiatCurrency]
|
|
88
|
-
const
|
|
89
|
-
let fiatRate
|
|
91
|
+
const rates = this.#cachedRates?.[this.#fiatCurrency]
|
|
92
|
+
const ticker = asset.ticker
|
|
90
93
|
// HACK: Super hacky, terrible, the rates state object should have the prices split up by sub-objects per fiat
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
94
|
+
const fiatRate =
|
|
95
|
+
fiatCurrency.defaultUnit.unitName === 'USD'
|
|
96
|
+
? rates?.[ticker]?.priceUSD || 0
|
|
97
|
+
: rates?.[ticker]?.price || 0
|
|
96
98
|
|
|
97
99
|
if (fiatRate === 0) return fiatCurrency.ZERO
|
|
98
100
|
|
|
@@ -110,45 +112,72 @@ class FiatBalances {
|
|
|
110
112
|
const { byAssetSource, byBaseAssetSource, byWalletAccount, byAsset } = this.#balances
|
|
111
113
|
const fiatZero = fiatCurrencies[this.#fiatCurrency].ZERO
|
|
112
114
|
|
|
113
|
-
|
|
115
|
+
for (const walletAccount in balances) {
|
|
114
116
|
const walletAccountBalances = balances[walletAccount]
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
117
|
+
const walletTotals = Object.create(null)
|
|
118
|
+
for (const field of this.#balanceFields) walletTotals[field] = fiatZero
|
|
119
|
+
|
|
120
|
+
let byWalletAccountRef = byWalletAccount[walletAccount]
|
|
121
|
+
if (!byWalletAccountRef) {
|
|
122
|
+
byWalletAccountRef = Object.create(null)
|
|
123
|
+
byWalletAccount[walletAccount] = byWalletAccountRef
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let byAssetSourceWalletRef = byAssetSource[walletAccount]
|
|
127
|
+
if (!byAssetSourceWalletRef) {
|
|
128
|
+
byAssetSourceWalletRef = Object.create(null)
|
|
129
|
+
byAssetSource[walletAccount] = byAssetSourceWalletRef
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let byBaseAssetSourceWalletRef = byBaseAssetSource[walletAccount]
|
|
133
|
+
if (!byBaseAssetSourceWalletRef) {
|
|
134
|
+
byBaseAssetSourceWalletRef = Object.create(null)
|
|
135
|
+
byBaseAssetSource[walletAccount] = byBaseAssetSourceWalletRef
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
for (const assetName in walletAccountBalances) {
|
|
139
|
+
const assetBalances = walletAccountBalances[assetName]
|
|
140
|
+
if (!assetBalances) continue
|
|
141
|
+
const asset = this.#assetsModule.getAsset(assetName)
|
|
142
|
+
const baseAssetName = asset.baseAsset.name
|
|
143
|
+
|
|
144
|
+
let byAssetSourceAssetRef = byAssetSourceWalletRef[assetName]
|
|
145
|
+
if (!byAssetSourceAssetRef) {
|
|
146
|
+
byAssetSourceAssetRef = Object.create(null)
|
|
147
|
+
byAssetSourceWalletRef[assetName] = byAssetSourceAssetRef
|
|
148
|
+
}
|
|
135
149
|
|
|
136
|
-
|
|
150
|
+
let byBaseAssetSourceAssetRef = byBaseAssetSourceWalletRef[baseAssetName]
|
|
151
|
+
if (!byBaseAssetSourceAssetRef) {
|
|
152
|
+
byBaseAssetSourceAssetRef = Object.create(null)
|
|
153
|
+
byBaseAssetSourceWalletRef[baseAssetName] = byBaseAssetSourceAssetRef
|
|
154
|
+
}
|
|
137
155
|
|
|
138
|
-
|
|
139
|
-
|
|
156
|
+
let byAssetRef = byAsset[assetName]
|
|
157
|
+
if (!byAssetRef) {
|
|
158
|
+
byAssetRef = Object.create(null)
|
|
159
|
+
byAsset[assetName] = byAssetRef
|
|
160
|
+
}
|
|
140
161
|
|
|
141
|
-
|
|
142
|
-
|
|
162
|
+
for (const field of this.#balanceFields) {
|
|
163
|
+
const balance = assetBalances[field]
|
|
164
|
+
if (!balance) continue
|
|
143
165
|
|
|
144
|
-
|
|
166
|
+
const fiatValue = this.#convertToFiat({ value: balance, asset })
|
|
145
167
|
|
|
146
|
-
|
|
147
|
-
|
|
168
|
+
byAssetSourceAssetRef[field] = (byAssetSourceAssetRef[field] || fiatZero).add(fiatValue)
|
|
169
|
+
byBaseAssetSourceAssetRef[field] = (byBaseAssetSourceAssetRef[field] || fiatZero).add(
|
|
170
|
+
fiatValue
|
|
171
|
+
)
|
|
172
|
+
byAssetRef[field] = (byAssetRef[field] || fiatZero).add(fiatValue)
|
|
173
|
+
walletTotals[field] = walletTotals[field].add(fiatValue)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
148
176
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
177
|
+
for (const field of this.#balanceFields) {
|
|
178
|
+
byWalletAccountRef[field] = walletTotals[field]
|
|
179
|
+
}
|
|
180
|
+
}
|
|
152
181
|
|
|
153
182
|
this.#recomputeWalletTotals()
|
|
154
183
|
}
|
|
@@ -176,7 +205,8 @@ class FiatBalances {
|
|
|
176
205
|
const walletAccountBalances = byWalletAccount[walletAccount]
|
|
177
206
|
Object.entries(walletAccountBalancesChanges).forEach(
|
|
178
207
|
([assetName, assetSourceBalancesChanges]) => {
|
|
179
|
-
const
|
|
208
|
+
const asset = this.#assetsModule.getAsset(assetName)
|
|
209
|
+
const baseAssetName = asset.baseAsset.name
|
|
180
210
|
this.#balanceFields.forEach((field) => {
|
|
181
211
|
// we may not be interested in all fields from `balances`
|
|
182
212
|
if (!assetSourceBalancesChanges[field]) return
|
|
@@ -184,8 +214,8 @@ class FiatBalances {
|
|
|
184
214
|
const { from, to } = assetSourceBalancesChanges[field]
|
|
185
215
|
walletAccountBalances[field] = walletAccountBalances[field] || fiatZero
|
|
186
216
|
|
|
187
|
-
const fromFiatValue = this.#convertToFiat({
|
|
188
|
-
const toFiatValue = this.#convertToFiat({
|
|
217
|
+
const fromFiatValue = this.#convertToFiat({ value: from, asset })
|
|
218
|
+
const toFiatValue = this.#convertToFiat({ value: to, asset })
|
|
189
219
|
|
|
190
220
|
if (fromFiatValue.equals(toFiatValue)) return
|
|
191
221
|
needsFlush = true
|
|
@@ -261,8 +291,7 @@ class FiatBalances {
|
|
|
261
291
|
|
|
262
292
|
#flush = () => {
|
|
263
293
|
this.#logger.log('fiat balances updated')
|
|
264
|
-
|
|
265
|
-
this.#fiatBalancesAtom.set((current) => (isEqual(current, data) ? current : data))
|
|
294
|
+
this.#fiatBalancesAtom.set(cloneBalances({ balances: this.#balances }))
|
|
266
295
|
}
|
|
267
296
|
|
|
268
297
|
stop = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/fiat-balances",
|
|
3
|
-
"version": "13.7.
|
|
3
|
+
"version": "13.7.2",
|
|
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": "^
|
|
50
|
-
"@exodus/available-assets": "^8.
|
|
51
|
-
"@exodus/balances": "^13.
|
|
49
|
+
"@exodus/assets-feature": "^9.0.1",
|
|
50
|
+
"@exodus/available-assets": "^8.11.0",
|
|
51
|
+
"@exodus/balances": "^13.15.1",
|
|
52
52
|
"@exodus/blockchain-metadata": "^17.1.0",
|
|
53
53
|
"@exodus/combined-assets-meta": "^3.3.2",
|
|
54
54
|
"@exodus/enabled-assets": "^10.11.0",
|
|
55
55
|
"@exodus/favorite-assets": "^2.6.0",
|
|
56
|
-
"@exodus/fee-data-monitors": "^5.0.
|
|
57
|
-
"@exodus/models": "^12.
|
|
56
|
+
"@exodus/fee-data-monitors": "^5.0.5",
|
|
57
|
+
"@exodus/models": "^12.19.1",
|
|
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": "3ff15cc5f430736df2959cded07977ab3d45ca70"
|
|
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
|
}
|