@exodus/fiat-balances 12.4.0 → 12.5.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/index.js +8 -1
- package/module/fiat-balances.js +17 -2
- package/package.json +3 -3
- package/plugin/analytics.js +29 -0
- package/plugin/index.js +9 -0
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.5.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@12.5.0...@exodus/fiat-balances@12.5.1) (2024-11-29)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- fix: balances map equality check (#10620)
|
|
11
|
+
|
|
12
|
+
## [12.5.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@12.4.0...@exodus/fiat-balances@12.5.0) (2024-11-29)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- feat: add various crypto balance props (#10419)
|
|
17
|
+
|
|
6
18
|
## [12.4.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@12.3.0...@exodus/fiat-balances@12.4.0) (2024-11-26)
|
|
7
19
|
|
|
8
20
|
### Features
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
nonDustBalanceAssetNamesAtomDefinition,
|
|
5
5
|
optimisticFiatBalancesAtomDefinition,
|
|
6
6
|
} from './atoms'
|
|
7
|
-
import fiatBalancesPluginDefinition from './plugin'
|
|
7
|
+
import fiatBalancesPluginDefinition, { fiatBalancesAnalyticsPlugin } from './plugin'
|
|
8
8
|
import trackNonDustAssetsNamesPluginDefinition from './plugin/track-non-dust-asset-names'
|
|
9
9
|
import fiatBalancesReportDefinition from './report'
|
|
10
10
|
|
|
@@ -17,6 +17,7 @@ const DEFAULT_BALANCE_FIELDS = ['balance']
|
|
|
17
17
|
* @param {object} [opts.nonDustAssets]
|
|
18
18
|
* @param {object} [opts.nonDustAssets.balanceThresholdsUsd]
|
|
19
19
|
* @param {object} [opts.nonDustAssets.balanceThresholdByChainUsd]
|
|
20
|
+
* @param {Array} [opts.assetsToTrackForBalances]
|
|
20
21
|
* @param {import('@exodus/fiat-currencies').Unit} [opts.nonDustAssets.defaultBalanceThresholdUsd]
|
|
21
22
|
*/
|
|
22
23
|
const fiatBalances = (
|
|
@@ -28,6 +29,7 @@ const fiatBalances = (
|
|
|
28
29
|
defaultBalanceThresholdUsd,
|
|
29
30
|
} = Object.create(null),
|
|
30
31
|
balanceFields = DEFAULT_BALANCE_FIELDS,
|
|
32
|
+
assetsToTrackForBalances = [],
|
|
31
33
|
} = Object.create(null)
|
|
32
34
|
) => ({
|
|
33
35
|
id: 'fiatBalances',
|
|
@@ -67,6 +69,11 @@ const fiatBalances = (
|
|
|
67
69
|
},
|
|
68
70
|
],
|
|
69
71
|
},
|
|
72
|
+
{
|
|
73
|
+
if: { registered: ['analytics'] },
|
|
74
|
+
definition: fiatBalancesAnalyticsPlugin,
|
|
75
|
+
config: { assetsToTrackForBalances },
|
|
76
|
+
},
|
|
70
77
|
],
|
|
71
78
|
})
|
|
72
79
|
|
package/module/fiat-balances.js
CHANGED
|
@@ -93,7 +93,7 @@ class FiatBalances {
|
|
|
93
93
|
this.#reset()
|
|
94
94
|
|
|
95
95
|
const balances = this.#latestAssetBalances
|
|
96
|
-
const { byAssetSource, byBaseAssetSource, byWalletAccount } = this.#balances
|
|
96
|
+
const { byAssetSource, byBaseAssetSource, byWalletAccount, byAsset } = this.#balances
|
|
97
97
|
const fiatZero = fiatCurrencies[this.#fiatCurrency].ZERO
|
|
98
98
|
|
|
99
99
|
Object.keys(balances).forEach((walletAccount) => {
|
|
@@ -106,6 +106,10 @@ class FiatBalances {
|
|
|
106
106
|
const balance = assetBalances?.[field]
|
|
107
107
|
if (!balance) return
|
|
108
108
|
|
|
109
|
+
if (!byAsset?.[assetName]) {
|
|
110
|
+
set(byAsset, [assetName, field], fiatZero)
|
|
111
|
+
}
|
|
112
|
+
|
|
109
113
|
if (!byAssetSource?.[walletAccount]?.[assetName]?.[field]) {
|
|
110
114
|
set(byAssetSource, [walletAccount, assetName, field], fiatZero)
|
|
111
115
|
}
|
|
@@ -123,6 +127,8 @@ class FiatBalances {
|
|
|
123
127
|
byBaseAssetSource[walletAccount][baseAssetName][field] =
|
|
124
128
|
byBaseAssetSource[walletAccount][baseAssetName][field].add(fiatValue)
|
|
125
129
|
|
|
130
|
+
byAsset[assetName][field] = byAsset[assetName][field].add(fiatValue)
|
|
131
|
+
|
|
126
132
|
fieldTotal = fieldTotal.add(fiatValue)
|
|
127
133
|
})
|
|
128
134
|
|
|
@@ -150,7 +156,7 @@ class FiatBalances {
|
|
|
150
156
|
const fiatZero = fiatCurrencies[this.#fiatCurrency].ZERO
|
|
151
157
|
|
|
152
158
|
// TODO set changes to fiatBalancesAtom as well
|
|
153
|
-
const { byWalletAccount, byAssetSource, byBaseAssetSource } = this.#balances
|
|
159
|
+
const { byWalletAccount, byAssetSource, byBaseAssetSource, byAsset } = this.#balances
|
|
154
160
|
let needsFlush = false
|
|
155
161
|
Object.entries(changes).forEach(([walletAccount, walletAccountBalancesChanges]) => {
|
|
156
162
|
const walletAccountBalances = byWalletAccount[walletAccount]
|
|
@@ -173,6 +179,13 @@ class FiatBalances {
|
|
|
173
179
|
.sub(fromFiatValue)
|
|
174
180
|
.add(toFiatValue)
|
|
175
181
|
|
|
182
|
+
if (!byAsset[assetName]?.[field]) {
|
|
183
|
+
set(byAsset, [assetName, field], fiatZero)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
byAsset[assetName][field] = byAsset[assetName][field]
|
|
187
|
+
.sub(fromFiatValue)
|
|
188
|
+
.add(toFiatValue)
|
|
176
189
|
//
|
|
177
190
|
;[
|
|
178
191
|
{
|
|
@@ -222,11 +235,13 @@ class FiatBalances {
|
|
|
222
235
|
const byWalletAccount = Object.create(null)
|
|
223
236
|
const byAssetSource = Object.create(null)
|
|
224
237
|
const byBaseAssetSource = Object.create(null)
|
|
238
|
+
const byAsset = Object.create(null)
|
|
225
239
|
this.#balances = Object.assign(Object.create(null), {
|
|
226
240
|
totals,
|
|
227
241
|
byWalletAccount,
|
|
228
242
|
byAssetSource,
|
|
229
243
|
byBaseAssetSource,
|
|
244
|
+
byAsset,
|
|
230
245
|
})
|
|
231
246
|
}
|
|
232
247
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/fiat-balances",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.5.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": "UNLICENSED",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@exodus/assets-base": "^8.1.17",
|
|
47
47
|
"@exodus/assets-feature": "^5.14.1",
|
|
48
48
|
"@exodus/available-assets": "^8.7.0",
|
|
49
|
-
"@exodus/balances": "^13.
|
|
49
|
+
"@exodus/balances": "^13.5.1",
|
|
50
50
|
"@exodus/blockchain-metadata": "^15.7.0",
|
|
51
51
|
"@exodus/combined-assets-meta": "^1.3.0",
|
|
52
52
|
"@exodus/enabled-assets": "^10.8.0",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"events": "^3.3.0",
|
|
62
62
|
"redux": "^4.2.1"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "16255e10556dd9fdcd811351f7fea30c101a4fe7"
|
|
65
65
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const createFiatBalancesAnalyticsPlugin = ({
|
|
2
|
+
analytics,
|
|
3
|
+
fiatBalancesAtom,
|
|
4
|
+
config: { assetsToTrackForBalances },
|
|
5
|
+
}) => {
|
|
6
|
+
let subscriptions = []
|
|
7
|
+
const onStart = () => {
|
|
8
|
+
const unsubscribeBalancesAtom = fiatBalancesAtom.observe(({ balances }) => {
|
|
9
|
+
const assetFiatBalances = assetsToTrackForBalances.reduce((acc, obj) => {
|
|
10
|
+
acc[obj.analyticsName] = balances?.byAsset[obj.assetName]?.balance.toDefaultNumber()
|
|
11
|
+
return acc
|
|
12
|
+
}, Object.create(null))
|
|
13
|
+
analytics.setDefaultEventProperties({
|
|
14
|
+
...assetFiatBalances,
|
|
15
|
+
totalBalanceUsd: balances?.totals?.balance?.toDefaultNumber(),
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
subscriptions = [unsubscribeBalancesAtom]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const onStop = () => {
|
|
23
|
+
subscriptions.forEach((unsubscribe) => unsubscribe())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { onStart, onStop }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default createFiatBalancesAnalyticsPlugin
|
package/plugin/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createAtomObserver } from '@exodus/atoms'
|
|
2
|
+
import createFiatBalancesAnalyticsPlugin from './analytics'
|
|
2
3
|
|
|
3
4
|
const createFiatBalancesPlugin = ({
|
|
4
5
|
port,
|
|
@@ -52,4 +53,12 @@ const fiatBalancesPluginDefinition = {
|
|
|
52
53
|
public: true,
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
export const fiatBalancesAnalyticsPlugin = {
|
|
57
|
+
id: 'fiatBalancesAnalyticsPlugin',
|
|
58
|
+
type: 'plugin',
|
|
59
|
+
factory: createFiatBalancesAnalyticsPlugin,
|
|
60
|
+
dependencies: ['analytics', 'fiatBalancesAtom', 'config?'],
|
|
61
|
+
public: true,
|
|
62
|
+
}
|
|
63
|
+
|
|
55
64
|
export default fiatBalancesPluginDefinition
|