@exodus/fiat-balances 11.0.0 → 12.0.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,23 @@
|
|
|
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.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@11.1.0...@exodus/fiat-balances@12.0.0) (2024-08-16)
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
- return $0 if fiat amount is zero. fix percentage formatter (#8442)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- bump formatting to v4 ([#8404](https://github.com/ExodusMovement/exodus-hydra/issues/8404)) ([df68f5e](https://github.com/ExodusMovement/exodus-hydra/commit/df68f5e3e853200efdfd018c17809f5cd7598ea3))
|
|
15
|
+
- return $0 if fiat amount is zero. fix percentage formatter ([#8442](https://github.com/ExodusMovement/exodus-hydra/issues/8442)) ([54b76b5](https://github.com/ExodusMovement/exodus-hydra/commit/54b76b5b9984520a7c56058ce6fa0dd797f1cfd0))
|
|
16
|
+
|
|
17
|
+
## [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)
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
- add usd conversions selectors ([#8309](https://github.com/ExodusMovement/exodus-hydra/issues/8309)) ([4ec1152](https://github.com/ExodusMovement/exodus-hydra/commit/4ec11524a5ef186b0d5f4f08e537f8257b4c8644))
|
|
22
|
+
|
|
6
23
|
## [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)
|
|
7
24
|
|
|
8
25
|
### ⚠ BREAKING CHANGES
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/fiat-balances",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.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,7 +36,7 @@
|
|
|
36
36
|
"@exodus/basic-utils": "^2.5.1",
|
|
37
37
|
"@exodus/currency": "^2.1.2",
|
|
38
38
|
"@exodus/fiat-currencies": "^1.0.0",
|
|
39
|
-
"@exodus/formatting": "^
|
|
39
|
+
"@exodus/formatting": "^5.0.0",
|
|
40
40
|
"@exodus/module": "^1.1.0",
|
|
41
41
|
"@exodus/typeforce": "^1.18.1",
|
|
42
42
|
"lodash": "^4.17.21",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"events": "^3.3.0",
|
|
65
65
|
"redux": "^4.2.1"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "2d69e70334df261d197925d4de51620cf2eed3be"
|
|
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,11 +3,20 @@ 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
|
+
const DEFAULT_FRACTION = 2
|
|
7
|
+
|
|
6
8
|
function formatPrice(
|
|
7
9
|
price,
|
|
8
|
-
{
|
|
10
|
+
{
|
|
11
|
+
useGrouping = true,
|
|
12
|
+
format = '%v',
|
|
13
|
+
symbol,
|
|
14
|
+
fraction = DEFAULT_FRACTION,
|
|
15
|
+
convertDust = true,
|
|
16
|
+
} = {}
|
|
9
17
|
) {
|
|
10
18
|
const priceNumber = Number(price)
|
|
19
|
+
|
|
11
20
|
const isDust = priceNumber < Math.pow(10, -fraction) && priceNumber > 0
|
|
12
21
|
if (convertDust && isDust) {
|
|
13
22
|
return `~${formatCurrency(0, {
|
|
@@ -30,14 +39,26 @@ function formatPrice(
|
|
|
30
39
|
|
|
31
40
|
const resultFunction =
|
|
32
41
|
(currency) =>
|
|
33
|
-
(
|
|
42
|
+
(
|
|
43
|
+
fiatValue,
|
|
44
|
+
{
|
|
45
|
+
customCurrency,
|
|
46
|
+
adaptiveFraction, // use adaptiveFraction when convert crypto amount (balance for example) to fiat
|
|
47
|
+
useGrouping,
|
|
48
|
+
convertDust,
|
|
49
|
+
} = {}
|
|
50
|
+
) => {
|
|
34
51
|
const fiatCurrency = customCurrency || currency
|
|
35
52
|
const value = isNumberUnit(fiatValue) ? fiatValue.toDefaultNumber() : fiatValue
|
|
36
53
|
|
|
37
54
|
return formatPrice(value, {
|
|
38
55
|
format: hasLeftCurrencySymbol(fiatCurrency) ? LEFT_FORMAT : RIGHT_FORMAT,
|
|
39
56
|
symbol: units[fiatCurrency].symbol,
|
|
40
|
-
fraction: adaptiveFraction
|
|
57
|
+
fraction: adaptiveFraction
|
|
58
|
+
? getFiatAdaptiveFraction(value)
|
|
59
|
+
: value === 0
|
|
60
|
+
? 0
|
|
61
|
+
: DEFAULT_FRACTION,
|
|
41
62
|
useGrouping,
|
|
42
63
|
convertDust,
|
|
43
64
|
})
|
|
@@ -17,7 +17,7 @@ const selectorFactory =
|
|
|
17
17
|
return {
|
|
18
18
|
balance: balances[asset] || asset.currency.ZERO,
|
|
19
19
|
fiatValue,
|
|
20
|
-
formattedFiatValue: formatFiat(fiatValue),
|
|
20
|
+
formattedFiatValue: formatFiat(fiatValue, { adaptiveFraction: true }),
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -48,7 +48,7 @@ const selectorFactory =
|
|
|
48
48
|
combinedAssets,
|
|
49
49
|
balance: combinedBalance,
|
|
50
50
|
fiatValue: combinedFiatValue,
|
|
51
|
-
formattedFiatValue: formatFiat(combinedFiatValue),
|
|
51
|
+
formattedFiatValue: formatFiat(combinedFiatValue, { adaptiveFraction: true }),
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
package/redux/selectors/index.js
CHANGED
|
@@ -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,
|