@exodus/fiat-balances 12.3.0 → 12.5.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,20 @@
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.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@12.4.0...@exodus/fiat-balances@12.5.0) (2024-11-29)
7
+
8
+ ### Features
9
+
10
+ - feat: add various crypto balance props (#10419)
11
+
12
+ ## [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)
13
+
14
+ ### Features
15
+
16
+ - feat(fiat-balances): optimisticLoaded selector (#10550)
17
+
18
+ - feat: use formatting v9 (#9903)
19
+
6
20
  ## [12.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@12.2.0...@exodus/fiat-balances@12.3.0) (2024-10-07)
7
21
 
8
22
  ### 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
 
@@ -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.0",
3
+ "version": "12.5.0",
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",
@@ -36,8 +36,7 @@
36
36
  "@exodus/basic-utils": "^3.0.1",
37
37
  "@exodus/currency": "^5.0.2",
38
38
  "@exodus/fiat-currencies": "^1.1.0",
39
- "@exodus/formatting": "^8.0.0",
40
- "@exodus/typeforce": "^1.18.1",
39
+ "@exodus/formatting": "^9.0.0",
41
40
  "lodash": "^4.17.21",
42
41
  "minimalistic-assert": "^1.0.1",
43
42
  "reselect": "^3.0.1"
@@ -45,23 +44,22 @@
45
44
  "devDependencies": {
46
45
  "@exodus/assets": "^9.1.0",
47
46
  "@exodus/assets-base": "^8.1.17",
48
- "@exodus/assets-feature": "^5.13.1",
49
- "@exodus/available-assets": "^8.6.0",
50
- "@exodus/balances": "^13.3.2",
51
- "@exodus/blockchain-metadata": "^15.5.0",
47
+ "@exodus/assets-feature": "^5.14.1",
48
+ "@exodus/available-assets": "^8.7.0",
49
+ "@exodus/balances": "^13.5.0",
50
+ "@exodus/blockchain-metadata": "^15.7.0",
52
51
  "@exodus/combined-assets-meta": "^1.3.0",
53
- "@exodus/enabled-assets": "^10.7.1",
52
+ "@exodus/enabled-assets": "^10.8.0",
54
53
  "@exodus/favorite-assets": "^2.4.3",
55
- "@exodus/fee-data-monitors": "^4.3.0",
56
- "@exodus/locale": "^2.2.2",
57
- "@exodus/models": "^12.1.0",
54
+ "@exodus/fee-data-monitors": "^5.0.2",
55
+ "@exodus/models": "^12.1.1",
58
56
  "@exodus/rates-monitor": "^4.4.1",
59
- "@exodus/redux-dependency-injection": "^4.0.3",
57
+ "@exodus/redux-dependency-injection": "^4.1.1",
60
58
  "@exodus/solana-meta": "^1.0.4",
61
- "@exodus/storage-memory": "^2.2.1",
62
- "@exodus/wallet-accounts": "^17.0.0",
59
+ "@exodus/storage-memory": "^2.2.2",
60
+ "@exodus/wallet-accounts": "^17.1.1",
63
61
  "events": "^3.3.0",
64
62
  "redux": "^4.2.1"
65
63
  },
66
- "gitHead": "bbb6726543eee7ffd4a61dd49f4c6a3304d7ff76"
64
+ "gitHead": "d979dacecad62ad66a5761afc08d6ea362ca05a5"
67
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
+ }, {})
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
package/redux/index.js CHANGED
@@ -42,12 +42,14 @@ const createFiatBalancesReduxDefinition = ({
42
42
  return {
43
43
  ...state,
44
44
  loaded: true,
45
+ optimisticLoaded: true,
45
46
  data,
46
47
  optimisticData: optimisticActivityEnabled ? state.optimisticData : data,
47
48
  }
48
49
  },
49
50
  optimisticFiatBalances: (state, { balances }) => ({
50
51
  ...state,
52
+ optimisticLoaded: true,
51
53
  optimisticData: prepareData({ state, payload: balances }),
52
54
  }),
53
55
  },
@@ -20,6 +20,7 @@ const createDataInitialState = () => ({
20
20
 
21
21
  const initialState = {
22
22
  loaded: false,
23
+ optimisticLoaded: false,
23
24
  data: createDataInitialState(),
24
25
  optimisticData: createDataInitialState(),
25
26
  }
@@ -9,7 +9,6 @@ const resultFunction =
9
9
  customCurrency,
10
10
  adaptiveFraction, // use adaptiveFraction when convert crypto amount (balance for example) to fiat
11
11
  useGrouping,
12
- convertDust,
13
12
  } = {}
14
13
  ) => {
15
14
  const fiatCurrency = customCurrency || currency
@@ -18,8 +17,7 @@ const resultFunction =
18
17
  return formatPrice(value, {
19
18
  currency: fiatCurrency,
20
19
  useGrouping,
21
- convertDust,
22
- fraction: adaptiveFraction ? getFiatAdaptiveFraction(value) : undefined,
20
+ maxFraction: adaptiveFraction ? getFiatAdaptiveFraction(value) : undefined,
23
21
  })
24
22
  }
25
23