@exodus/fiat-balances 10.5.0 → 10.7.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.
Files changed (26) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/index.js +3 -5
  3. package/module/fiat-balances.js +5 -11
  4. package/package.json +11 -10
  5. package/redux/selectors/conversions.js +20 -0
  6. package/redux/selectors/create-conversion.js +17 -0
  7. package/redux/selectors/{create-assets-with-balance.js → helpers/create-assets-with-balance.js} +2 -1
  8. package/redux/selectors/{create-enabled-assets-with-balance.js → helpers/create-enabled-assets-with-balance.js} +1 -1
  9. package/redux/selectors/index.js +26 -16
  10. package/redux/selectors/{optimistic-by-asset-source.js → optimistic/by-asset-source.js} +1 -1
  11. package/redux/selectors/{optimistic-by-base-asset-source.js → optimistic/by-base-asset-source.js} +1 -1
  12. package/redux/selectors/{create-sort-assets-selector-factory.js → sorted-assets/create-sort-assets-selector-factory.js} +1 -1
  13. package/redux/selectors/sorted-assets/enabled/with-parent-combined-with-balance-in-active-account.js +20 -0
  14. package/redux/selectors/sorted-assets/with-parent-combined-in-active-account.js +25 -0
  15. package/redux/selectors/sorted-assets/with-parent-combined-with-balance-in-active-account.js +26 -0
  16. /package/redux/selectors/{optimistic-by-asset-in-active-account.js → optimistic/by-asset-in-active-account.js} +0 -0
  17. /package/redux/selectors/{optimistic-by-asset-source-field.js → optimistic/by-asset-source-field.js} +0 -0
  18. /package/redux/selectors/{optimistic-by-base-asset-source-field.js → optimistic/by-base-asset-source-field.js} +0 -0
  19. /package/redux/selectors/{optimistic-by-wallet-account-field.js → optimistic/by-wallet-account-field.js} +0 -0
  20. /package/redux/selectors/{optimistic-by-wallet-account.js → optimistic/by-wallet-account.js} +0 -0
  21. /package/redux/selectors/{optimistic-total-balance.js → optimistic/total-balance.js} +0 -0
  22. /package/redux/selectors/{sorted-enabled-assets-with-balance-in-active-account.js → sorted-assets/enabled/with-balance-in-active-account.js} +0 -0
  23. /package/redux/selectors/{sorted-enabled-assets-with-total-balance.js → sorted-assets/enabled/with-total-balance.js} +0 -0
  24. /package/redux/selectors/{sorted-assets-with-balance-in-active-account.js → sorted-assets/with-balance-in-active-account.js} +0 -0
  25. /package/redux/selectors/{sorted-assets-with-total-balance.js → sorted-assets/with-total-balance.js} +0 -0
  26. /package/redux/selectors/{sorted-assets-without-parent-combined-in-active-account.js → sorted-assets/without-parent-combined-in-active-account.js} +0 -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
+ ## [10.7.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@10.6.0...@exodus/fiat-balances@10.7.0) (2024-05-02)
7
+
8
+ ### Features
9
+
10
+ - conversions selector ([#6751](https://github.com/ExodusMovement/exodus-hydra/issues/6751)) ([91c17fa](https://github.com/ExodusMovement/exodus-hydra/commit/91c17fab578b15e028e2d0ffdc283bec2ad6c7c4))
11
+
12
+ ## [10.6.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@10.5.0...@exodus/fiat-balances@10.6.0) (2024-04-23)
13
+
14
+ ### Features
15
+
16
+ - add more withParentCombined fiat-balance selectors ([#6585](https://github.com/ExodusMovement/exodus-hydra/issues/6585)) ([d25f7a6](https://github.com/ExodusMovement/exodus-hydra/commit/d25f7a6a27ea3fafa47cd3d48b950ec210fb36ac))
17
+
6
18
  ## [10.5.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@10.4.1...@exodus/fiat-balances@10.5.0) (2024-03-21)
7
19
 
8
20
  ### Features
package/index.js CHANGED
@@ -18,11 +18,9 @@ const DEFAULT_BALANCE_FIELDS = ['balance']
18
18
  * @param nonDustAssets.defaultBalanceThresholdUsd {import('@exodus/fiat-currencies').Unit}
19
19
  */
20
20
 
21
- const fiatBalances = ({
22
- optimistic,
23
- nonDustAssets,
24
- balanceFields = DEFAULT_BALANCE_FIELDS,
25
- } = {}) => ({
21
+ const fiatBalances = (
22
+ { optimistic, nonDustAssets, balanceFields = DEFAULT_BALANCE_FIELDS } = Object.create(null)
23
+ ) => ({
26
24
  id: 'fiatBalances',
27
25
  definitions: [
28
26
  {
@@ -1,8 +1,9 @@
1
- import { conversionByRate, isNumberUnit } from '@exodus/currency'
2
- import ExodusModule from '@exodus/module'
1
+ import { isNumberUnit } from '@exodus/currency'
2
+ import ExodusModule from '@exodus/module' // eslint-disable-line import/no-deprecated
3
3
  import { cloneDeepWith, isEqual, set } from 'lodash'
4
4
  import fiatCurrencies from '@exodus/fiat-currencies'
5
5
  import { combine } from '@exodus/atoms'
6
+ import { getCreateConversion } from '../shared/get-create-conversion.js'
6
7
 
7
8
  // not super efficient, so we're assuming small objects, like { [walletAccount]: xyz }
8
9
  const areKeysSame = (a, b) => isEqual(Object.keys(a).sort(), Object.keys(b).sort())
@@ -76,15 +77,8 @@ class FiatBalances extends ExodusModule {
76
77
  const fiatCurrency = fiatCurrencies[this.#fiatCurrency]
77
78
  const rates = this.#cachedRates[this.#fiatCurrency]
78
79
  const asset = this.#assetsModule.getAsset(assetName)
79
- let fiatRate
80
- // HACK: Super hacky, terrible, the rates state object should have the prices split up by sub-objects per fiat
81
- if (fiatCurrency.defaultUnit.unitName === 'USD') {
82
- fiatRate = rates?.[asset.ticker]?.priceUSD || 0
83
- } else {
84
- fiatRate = rates?.[asset.ticker]?.price || 0
85
- }
86
-
87
- return conversionByRate(asset.currency, fiatCurrency, fiatRate)
80
+
81
+ return getCreateConversion(fiatCurrency, rates)(asset)
88
82
  }
89
83
 
90
84
  #convertToFiat = ({ assetName, value }) => {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@exodus/fiat-balances",
3
- "version": "10.5.0",
3
+ "version": "10.7.0",
4
4
  "description": "Track asset and portfolio fiat balances based on changes in crypto balances and the user's preferred fiat currency",
5
- "author": "Exodus Movement Inc.",
5
+ "author": "Exodus Movement, Inc.",
6
6
  "license": "UNLICENSED",
7
7
  "scripts": {
8
8
  "test": "run -T jest",
@@ -42,20 +42,21 @@
42
42
  "devDependencies": {
43
43
  "@exodus/assets": "^9.1.0",
44
44
  "@exodus/assets-base": "^8.1.17",
45
- "@exodus/assets-feature": "^5.0.0",
46
- "@exodus/available-assets": "^8.0.1",
47
- "@exodus/balances": "^13.0.0",
45
+ "@exodus/assets-feature": "^5.3.1",
46
+ "@exodus/available-assets": "^8.1.0",
47
+ "@exodus/balances": "^13.1.2",
48
48
  "@exodus/blockchain-metadata": "*",
49
- "@exodus/enabled-assets": "^10.1.2",
50
- "@exodus/favorite-assets": "^2.4.0",
49
+ "@exodus/combined-assets-meta": "^1.3.0",
50
+ "@exodus/enabled-assets": "^10.3.0",
51
+ "@exodus/favorite-assets": "^2.4.1",
51
52
  "@exodus/models": "^8.9.0",
52
- "@exodus/rates-monitor": "^4.1.1",
53
- "@exodus/redux-dependency-injection": "^3.0.0",
53
+ "@exodus/rates-monitor": "^4.2.0",
54
+ "@exodus/redux-dependency-injection": "^3.1.0",
54
55
  "@exodus/solana-meta": "^1.0.4",
55
56
  "@exodus/storage-memory": "^2.1.1",
56
57
  "@exodus/wallet-accounts": "*",
57
58
  "events": "^3.3.0",
58
59
  "redux": "^4.2.1"
59
60
  },
60
- "gitHead": "d5391f8fcf4d672e46580928aedea0fb5d64dbd5"
61
+ "gitHead": "2c2340d9d3d499799e1c6e3aa3730e591824fd4f"
61
62
  }
@@ -0,0 +1,20 @@
1
+ import { getCreateConversion } from '../../shared/get-create-conversion.js'
2
+ import { mapValues } from '@exodus/basic-utils'
3
+
4
+ const resultFunction = (fiatCurrency, assets, rates) => {
5
+ const createConversion = getCreateConversion(fiatCurrency, rates)
6
+ return mapValues(assets, (asset) => createConversion(asset))
7
+ }
8
+
9
+ const conversionsSelectorDefinition = {
10
+ id: 'conversions',
11
+ resultFunction,
12
+ dependencies: [
13
+ //
14
+ { selector: 'currencyUnitType', module: 'locale' },
15
+ { selector: 'all', module: 'assets' },
16
+ { selector: 'fiatRates', module: 'rates' },
17
+ ],
18
+ }
19
+
20
+ export default conversionsSelectorDefinition
@@ -0,0 +1,17 @@
1
+ import { getCreateConversion } from '../../shared/get-create-conversion.js'
2
+
3
+ const resultFunction = (fiatCurrency, rates, assets) => (assetName) =>
4
+ getCreateConversion(fiatCurrency, rates)(assets[assetName])
5
+
6
+ const createConversionSelectorDefinition = {
7
+ id: 'createConversion',
8
+ resultFunction,
9
+ dependencies: [
10
+ //
11
+ { selector: 'currencyUnitType', module: 'locale' },
12
+ { selector: 'all', module: 'assets' },
13
+ { selector: 'fiatRates', module: 'rates' },
14
+ ],
15
+ }
16
+
17
+ export default createConversionSelectorDefinition
@@ -1,6 +1,7 @@
1
1
  import { createSelector } from 'reselect'
2
- import { isMultiNetworkAsset } from './utils'
2
+ import { isMultiNetworkAsset } from '../utils'
3
3
 
4
+ // adds extra props to assets list: balance, fiatBalance, formattedFiatValue and combinedAssets with same props
4
5
  const selectorFactory =
5
6
  (fiatCurrencySelector, getFormatFiat) =>
6
7
  ({ assetsListSelector, balancesSelector, fiatBalancesSelector }) =>
@@ -1,5 +1,5 @@
1
1
  import { createSelector } from 'reselect'
2
- import { isMultiNetworkAsset } from './utils'
2
+ import { isMultiNetworkAsset } from '../utils'
3
3
  import { groupBy } from 'lodash'
4
4
 
5
5
  const selectorFactory =
@@ -6,23 +6,28 @@ import byAssetSourceFieldSelector from './by-asset-source-field'
6
6
  import byAssetInActiveAccountSelector from './by-asset-in-active-account'
7
7
  import byBaseAssetSourceSelector from './by-base-asset-source'
8
8
  import byBaseAssetSourceFieldSelector from './by-base-asset-source-field'
9
- import optimisticByAssetInActiveAccountSelector from './optimistic-by-asset-in-active-account'
10
- import optimisticByAssetSourceSelector from './optimistic-by-asset-source'
11
- import optimisticByAssetSourceFieldSelector from './optimistic-by-asset-source-field'
12
- import optimisticByBaseAssetSourceSelector from './optimistic-by-base-asset-source'
13
- import optimisticByBaseAssetSourceFieldSelector from './optimistic-by-base-asset-source-field'
14
- import optimisticByWalletAccountSelector from './optimistic-by-wallet-account'
15
- import optimisticByWalletAccountFieldSelector from './optimistic-by-wallet-account-field'
16
- import optimisticTotalBalanceSelector from './optimistic-total-balance'
17
- import createSortAssetsSelectorFactorySelector from './create-sort-assets-selector-factory'
18
- import createAssetsWithBalanceSelector from './create-assets-with-balance'
19
- import sortedAssetsWithoutParentCombinedInActiveAccountSelector from './sorted-assets-without-parent-combined-in-active-account'
9
+ import optimisticByAssetInActiveAccountSelector from './optimistic/by-asset-in-active-account'
10
+ import optimisticByAssetSourceSelector from './optimistic/by-asset-source'
11
+ import optimisticByAssetSourceFieldSelector from './optimistic/by-asset-source-field'
12
+ import optimisticByBaseAssetSourceSelector from './optimistic/by-base-asset-source'
13
+ import optimisticByBaseAssetSourceFieldSelector from './optimistic/by-base-asset-source-field'
14
+ import optimisticByWalletAccountSelector from './optimistic/by-wallet-account'
15
+ import optimisticByWalletAccountFieldSelector from './optimistic/by-wallet-account-field'
16
+ import optimisticTotalBalanceSelector from './optimistic/total-balance'
17
+ import createSortAssetsSelectorFactorySelector from './sorted-assets/create-sort-assets-selector-factory'
18
+ import createAssetsWithBalanceSelector from './helpers/create-assets-with-balance'
19
+ import sortedAssetsWithoutParentCombinedInActiveAccountSelector from './sorted-assets/without-parent-combined-in-active-account'
20
+ import sortedAssetsWithParentCombinedInActiveAccountSelector from './sorted-assets/with-parent-combined-in-active-account'
20
21
  import getFormatFiatSelector from './get-format-fiat'
21
- import sortedAssetsWithBalanceInActiveAccountSelector from './sorted-assets-with-balance-in-active-account'
22
- import sortedAssetsWithTotalBalanceSelector from './sorted-assets-with-total-balance'
23
- import sortedEnabledAssetsWithBalanceInActiveAccountSelector from './sorted-enabled-assets-with-balance-in-active-account'
24
- import createEnabledAssetsWithBalanceSelector from './create-enabled-assets-with-balance'
25
- import sortedEnabledAssetsWithTotalBalanceSelector from './sorted-enabled-assets-with-total-balance'
22
+ import sortedAssetsWithBalanceInActiveAccountSelector from './sorted-assets/with-balance-in-active-account'
23
+ import sortedAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDefinition from './sorted-assets/with-parent-combined-with-balance-in-active-account'
24
+ import sortedAssetsWithTotalBalanceSelector from './sorted-assets/with-total-balance'
25
+ import sortedEnabledAssetsWithBalanceInActiveAccountSelector from './sorted-assets/enabled/with-balance-in-active-account'
26
+ import createEnabledAssetsWithBalanceSelector from './helpers/create-enabled-assets-with-balance'
27
+ import sortedEnabledAssetsWithTotalBalanceSelector from './sorted-assets/enabled/with-total-balance'
28
+ import sortedEnabledAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDefinition from './sorted-assets/enabled/with-parent-combined-with-balance-in-active-account'
29
+ import conversionsSelector from './conversions.js'
30
+ import createConversionSelector from './create-conversion.js'
26
31
 
27
32
  export default function createSelectorDefinitions(config) {
28
33
  return [
@@ -46,10 +51,15 @@ export default function createSelectorDefinitions(config) {
46
51
  createAssetsWithBalanceSelector,
47
52
  createEnabledAssetsWithBalanceSelector,
48
53
  sortedAssetsWithoutParentCombinedInActiveAccountSelector,
54
+ sortedAssetsWithParentCombinedInActiveAccountSelector,
49
55
  sortedAssetsWithBalanceInActiveAccountSelector,
56
+ sortedAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDefinition,
57
+ sortedEnabledAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDefinition,
50
58
  sortedEnabledAssetsWithBalanceInActiveAccountSelector,
51
59
  sortedEnabledAssetsWithTotalBalanceSelector,
52
60
  sortedAssetsWithTotalBalanceSelector,
53
61
  getFormatFiatSelector,
62
+ conversionsSelector,
63
+ createConversionSelector,
54
64
  ]
55
65
  }
@@ -1,5 +1,5 @@
1
1
  import { createSelector } from 'reselect'
2
- import { toBalanceOnly } from './utils'
2
+ import { toBalanceOnly } from '../utils'
3
3
 
4
4
  const selectorFactory = (optimisticByAssetSourceFieldSelector) =>
5
5
  createSelector(optimisticByAssetSourceFieldSelector, toBalanceOnly)
@@ -1,5 +1,5 @@
1
1
  import { createSelector } from 'reselect'
2
- import { toBalanceOnly } from './utils'
2
+ import { toBalanceOnly } from '../utils'
3
3
 
4
4
  const selectorFactory = (optimisticByAssetSourceSelector) =>
5
5
  createSelector(optimisticByAssetSourceSelector, toBalanceOnly)
@@ -2,7 +2,7 @@ import { memoize } from 'lodash'
2
2
  import { keyBy, orderBy } from '@exodus/basic-utils'
3
3
  import { createSelector } from 'reselect'
4
4
  import { isDustAmount } from '@exodus/formatting/lib/asset'
5
- import { isMultiNetworkAsset } from './utils'
5
+ import { isMultiNetworkAsset } from '../utils'
6
6
 
7
7
  const SORTING_MAP = [
8
8
  [(a) => a.sortAssetMetaData.isFavoriteAsset, 'desc'],
@@ -0,0 +1,20 @@
1
+ const selectorFactory = (
2
+ createEnabledAssetsWithBalance,
3
+ sortedAssetsWithParentCombinedWithBalanceInActiveAccount
4
+ ) => {
5
+ return createEnabledAssetsWithBalance({
6
+ assetsListSelector: sortedAssetsWithParentCombinedWithBalanceInActiveAccount,
7
+ })
8
+ }
9
+
10
+ const sortedEnabledAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDefinition = {
11
+ id: 'sortedEnabledAssetsWithParentCombinedWithBalanceInActiveAccount',
12
+ selectorFactory,
13
+ dependencies: [
14
+ //
15
+ { selector: 'createEnabledAssetsWithBalance' },
16
+ { selector: 'sortedAssetsWithParentCombinedWithBalanceInActiveAccount' },
17
+ ],
18
+ }
19
+
20
+ export default sortedEnabledAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDefinition
@@ -0,0 +1,25 @@
1
+ const selectorFactory = (
2
+ createSortAssetsSelectorFactory,
3
+ activeWalletAccountSelector,
4
+ allWithParentCombinedNetwork
5
+ ) => {
6
+ const createSortedWithParentCombinedSelector = createSortAssetsSelectorFactory(
7
+ allWithParentCombinedNetwork
8
+ )
9
+
10
+ return (state) =>
11
+ createSortedWithParentCombinedSelector(activeWalletAccountSelector(state))(state)
12
+ }
13
+
14
+ const sortedAssetsWithParentCombinedInActiveAccountDefinition = {
15
+ id: 'sortedAssetsWithParentCombinedInActiveAccount',
16
+ selectorFactory,
17
+ dependencies: [
18
+ //
19
+ { selector: 'createSortAssetsSelectorFactory' },
20
+ { module: 'walletAccounts', selector: 'active' },
21
+ { module: 'availableAssets', selector: 'allWithParentCombinedNetwork' },
22
+ ],
23
+ }
24
+
25
+ export default sortedAssetsWithParentCombinedInActiveAccountDefinition
@@ -0,0 +1,26 @@
1
+ const selectorFactory = (
2
+ createAssetsWithBalanceSelector,
3
+ sortedAssetsWithParentCombinedInActiveAccountSelector,
4
+ fiatBalancesByAssetInActiveAccount,
5
+ activeAccountAssetsBalanceSelector
6
+ ) => {
7
+ return createAssetsWithBalanceSelector({
8
+ assetsListSelector: sortedAssetsWithParentCombinedInActiveAccountSelector,
9
+ balancesSelector: activeAccountAssetsBalanceSelector,
10
+ fiatBalancesSelector: fiatBalancesByAssetInActiveAccount,
11
+ })
12
+ }
13
+
14
+ const sortedAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDefinition = {
15
+ id: 'sortedAssetsWithParentCombinedWithBalanceInActiveAccount',
16
+ selectorFactory,
17
+ dependencies: [
18
+ //
19
+ { selector: 'createAssetsWithBalance' },
20
+ { selector: 'sortedAssetsWithParentCombinedInActiveAccount' },
21
+ { selector: 'byAssetInActiveAccount' },
22
+ { module: 'balances', selector: 'activeAccountAssetsBalanceSelector' },
23
+ ],
24
+ }
25
+
26
+ export default sortedAssetsWithParentCombinedWithBalanceInActiveAccountSelectorDefinition