@exodus/fiat-balances 10.13.2 → 11.1.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,22 @@
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.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@11.0.0...@exodus/fiat-balances@11.1.0) (2024-08-13)
7
+
8
+ ### Features
9
+
10
+ - add usd conversions selectors ([#8309](https://github.com/ExodusMovement/exodus-hydra/issues/8309)) ([4ec1152](https://github.com/ExodusMovement/exodus-hydra/commit/4ec11524a5ef186b0d5f4f08e537f8257b4c8644))
11
+
12
+ ## [11.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@10.13.2...@exodus/fiat-balances@11.0.0) (2024-08-12)
13
+
14
+ ### ⚠ BREAKING CHANGES
15
+
16
+ - convert fiat dust value in selector to ~0 (#8320)
17
+
18
+ ### Features
19
+
20
+ - convert fiat dust value in selector to ~0 ([#8320](https://github.com/ExodusMovement/exodus-hydra/issues/8320)) ([78d9126](https://github.com/ExodusMovement/exodus-hydra/commit/78d91269ffb909134da391bfd98ef34915ae4b37))
21
+
6
22
  ## [10.13.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@10.13.1...@exodus/fiat-balances@10.13.2) (2024-08-06)
7
23
 
8
24
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/fiat-balances",
3
- "version": "10.13.2",
3
+ "version": "11.1.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",
@@ -46,7 +46,7 @@
46
46
  "devDependencies": {
47
47
  "@exodus/assets": "^9.1.0",
48
48
  "@exodus/assets-base": "^8.1.17",
49
- "@exodus/assets-feature": "^5.9.0",
49
+ "@exodus/assets-feature": "^5.10.0",
50
50
  "@exodus/available-assets": "^8.4.1",
51
51
  "@exodus/balances": "^13.2.3",
52
52
  "@exodus/blockchain-metadata": "^15.3.5",
@@ -64,5 +64,5 @@
64
64
  "events": "^3.3.0",
65
65
  "redux": "^4.2.1"
66
66
  },
67
- "gitHead": "3cbb1e5c61d7fc1ddecf740fcf5a8fb3d3b6ed91"
67
+ "gitHead": "aa8877dca42334fb1c98613ea10d29ac8a2a5d05"
68
68
  }
@@ -0,0 +1,30 @@
1
+ import { memoize } from '@exodus/basic-utils'
2
+ import { createSelector } from 'reselect'
3
+ import { conversionByRate } from '@exodus/currency'
4
+ import currencies from '@exodus/fiat-currencies'
5
+
6
+ const fiatCurrency = currencies.USD
7
+
8
+ const selectorFactory = (assetsSelector, createAssetRateSelector) =>
9
+ memoize((assetName) =>
10
+ createSelector(
11
+ (state) => assetsSelector(state)[assetName],
12
+ createAssetRateSelector(assetName),
13
+ (asset, rate) => {
14
+ const fiatRate = rate?.priceUSD || 0
15
+ return conversionByRate(asset.currency, fiatCurrency, fiatRate)
16
+ }
17
+ )
18
+ )
19
+
20
+ const createConversionSelectorDefinition = {
21
+ id: 'createAssetConversionUsd',
22
+ selectorFactory,
23
+ dependencies: [
24
+ //
25
+ { selector: 'all', module: 'assets' },
26
+ { selector: 'assetRate', module: 'rates' },
27
+ ],
28
+ }
29
+
30
+ export default createConversionSelectorDefinition
@@ -3,7 +3,22 @@ import { getFiatAdaptiveFraction } from '@exodus/formatting/lib/price'
3
3
  import { hasLeftCurrencySymbol, units } from '@exodus/fiat-currencies'
4
4
  import { formatCurrency, LEFT_FORMAT, RIGHT_FORMAT } from '@exodus/formatting/lib/currency'
5
5
 
6
- function formatPrice(price, { useGrouping = true, format = '%v', symbol, fraction = 2 } = {}) {
6
+ function formatPrice(
7
+ price,
8
+ { useGrouping = true, format = '%v', symbol, fraction = 2, convertDust = true } = {}
9
+ ) {
10
+ const priceNumber = Number(price)
11
+ const isDust = priceNumber < Math.pow(10, -fraction) && priceNumber > 0
12
+ if (convertDust && isDust) {
13
+ return `~${formatCurrency(0, {
14
+ minFraction: 0,
15
+ maxFraction: 0,
16
+ format,
17
+ symbol,
18
+ useGrouping,
19
+ })}`
20
+ }
21
+
7
22
  return formatCurrency(price, {
8
23
  minFraction: fraction,
9
24
  maxFraction: fraction,
@@ -15,7 +30,7 @@ function formatPrice(price, { useGrouping = true, format = '%v', symbol, fractio
15
30
 
16
31
  const resultFunction =
17
32
  (currency) =>
18
- (fiatValue, { customCurrency, adaptiveFraction } = {}) => {
33
+ (fiatValue, { customCurrency, adaptiveFraction, useGrouping, convertDust } = {}) => {
19
34
  const fiatCurrency = customCurrency || currency
20
35
  const value = isNumberUnit(fiatValue) ? fiatValue.toDefaultNumber() : fiatValue
21
36
 
@@ -23,6 +38,8 @@ const resultFunction =
23
38
  format: hasLeftCurrencySymbol(fiatCurrency) ? LEFT_FORMAT : RIGHT_FORMAT,
24
39
  symbol: units[fiatCurrency].symbol,
25
40
  fraction: adaptiveFraction ? getFiatAdaptiveFraction(value) : undefined,
41
+ useGrouping,
42
+ convertDust,
26
43
  })
27
44
  }
28
45
 
@@ -30,6 +30,7 @@ import sortedEnabledAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDe
30
30
  import conversionsSelector from './conversions.js'
31
31
  import createConversionSelector from './create-conversion.js'
32
32
  import createAssetConversion from './create-asset-conversion'
33
+ import createAssetConversionUsd from './create-asset-conversion-usd'
33
34
  import createSortOptimisticAssetsSelectorFactoryDefinition from './sorted-optimistic-assets/create-sort-assets-selector-factory'
34
35
  import sortedOptimisticAssetsWithoutParentCombinedInActiveAccountDefinition from './sorted-optimistic-assets/without-parent-combined-in-active-account'
35
36
  import sortedOptimisticAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDefinition from './sorted-optimistic-assets/with-parent-combined-with-balance-in-active-account'
@@ -72,6 +73,7 @@ export default function createSelectorDefinitions(config) {
72
73
  conversionsSelector,
73
74
  createConversionSelector,
74
75
  createAssetConversion,
76
+ createAssetConversionUsd,
75
77
  createSortOptimisticAssetsSelectorFactoryDefinition(config),
76
78
  sortedOptimisticAssetsWithoutParentCombinedInActiveAccountDefinition,
77
79
  sortedOptimisticAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDefinition,