@exodus/balances 13.1.2 → 13.2.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 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
+ ## [13.2.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.2.0...@exodus/balances@13.2.1) (2024-06-26)
7
+
8
+ ### Bug Fixes
9
+
10
+ - using right currency on fuelThreshold ([#7522](https://github.com/ExodusMovement/exodus-hydra/issues/7522)) ([1c87c6e](https://github.com/ExodusMovement/exodus-hydra/commit/1c87c6e67c8d930bbb0e1605173da138c1ef1be5))
11
+
12
+ ## [13.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.1.2...@exodus/balances@13.2.0) (2024-05-29)
13
+
14
+ ### Features
15
+
16
+ - fuel threshold selectors ([#7161](https://github.com/ExodusMovement/exodus-hydra/issues/7161)) ([a6cf8d7](https://github.com/ExodusMovement/exodus-hydra/commit/a6cf8d7fcea6590e2ebbd0da11d51922a8620d78))
17
+
6
18
  ## [13.1.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.1.1...@exodus/balances@13.1.2) (2024-04-26)
7
19
 
8
20
  ### Bug Fixes
package/module/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { isNumberUnit } from '@exodus/currency'
2
2
  import { TxSet } from '@exodus/models'
3
3
  import ExodusModule from '@exodus/module' // eslint-disable-line import/no-deprecated
4
- import { cloneDeepWith, isEmpty, merge, set, zipObject } from 'lodash'
5
- import { difference, flattenToPaths, pick } from '@exodus/basic-utils'
4
+ import { cloneDeepWith, isEmpty, merge, zipObject } from 'lodash'
5
+ import { difference, flattenToPaths, pick, set } from '@exodus/basic-utils'
6
6
  import makeConcurrent from 'make-concurrent'
7
7
  import { processAssetBalances, validateBalances } from './balances-utils'
8
8
  import defaultConfig from '../default-config'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/balances",
3
- "version": "13.1.2",
3
+ "version": "13.2.1",
4
4
  "description": "Tracks crypto balances across enabled wallet accounts.",
5
5
  "author": "Exodus Movement, Inc.",
6
6
  "license": "UNLICENSED",
@@ -31,7 +31,8 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@exodus/atoms": "^7.0.5",
34
- "@exodus/basic-utils": "^2.1.0",
34
+ "@exodus/basic-utils": "^2.5.1",
35
+ "@exodus/core-selectors": "^1.5.0",
35
36
  "@exodus/currency": "^2.1.2",
36
37
  "@exodus/models": "^10.1.0",
37
38
  "@exodus/module": "^1.1.0",
@@ -48,15 +49,17 @@
48
49
  "devDependencies": {
49
50
  "@exodus/assets": "^8.0.94",
50
51
  "@exodus/assets-base": "^8.1.10",
51
- "@exodus/assets-feature": "^5.1.0",
52
+ "@exodus/assets-feature": "^5.6.0",
53
+ "@exodus/available-assets": "^8.3.0",
52
54
  "@exodus/bitcoin-meta": "^1.0.1",
53
55
  "@exodus/blockchain-metadata": "^9.0.1",
54
56
  "@exodus/ethereum-meta": "^1.0.30",
57
+ "@exodus/fee-data-monitors": "^4.2.0",
55
58
  "@exodus/redux-dependency-injection": "workspace:^",
56
59
  "@exodus/storage-memory": "*",
57
- "@exodus/wallet-accounts": "^16.3.1",
60
+ "@exodus/wallet-accounts": "^16.7.1",
58
61
  "events": "^3.3.0",
59
62
  "redux": "^4.2.1"
60
63
  },
61
- "gitHead": "428bfc5fe989222d5822a5096f48393d2f41a4b6"
64
+ "gitHead": "7c12959ab914cce84a1ba3cce64253185599eefe"
62
65
  }
@@ -0,0 +1,30 @@
1
+ import { memoize } from 'lodash'
2
+ import { createSelector } from 'reselect'
3
+ import { isNumberUnit } from '@exodus/currency'
4
+
5
+ const selectorFactory = (getFeeDataSelector, assetsSelector) =>
6
+ memoize((assetName) =>
7
+ createSelector(getFeeDataSelector, assetsSelector, (getFeeData, assets) => {
8
+ const asset = assets[assetName]
9
+ if (!asset) {
10
+ // not all assets are supported by Exodus.
11
+ return null
12
+ }
13
+
14
+ const feeData = getFeeData(asset.baseAsset.name)
15
+ return isNumberUnit(feeData?.fuelThreshold)
16
+ ? feeData.fuelThreshold
17
+ : asset.feeAsset.currency.ZERO
18
+ })
19
+ )
20
+
21
+ const createFuelThresholdSelectorDefinition = {
22
+ id: 'createFuelThreshold',
23
+ selectorFactory,
24
+ dependencies: [
25
+ { module: 'feeData', selector: 'getData' },
26
+ { module: 'assets', selector: 'all' },
27
+ ],
28
+ }
29
+
30
+ export default createFuelThresholdSelectorDefinition
@@ -0,0 +1,59 @@
1
+ import { createSelector } from 'reselect'
2
+ import { memoizeByAssetSource } from '@exodus/core-selectors/utils/memoize'
3
+
4
+ /**
5
+ * Checks if a wallet account has "relative" tokens of the supplied asset (excluding itself):
6
+ *
7
+ * If providing a base asset, then it returns if the wallet has any child balance. Examples:
8
+ * - eth, returns true if there is usdt(eth)
9
+ * - tron, return true if there is usdt(tron)
10
+ *
11
+ * If providing child asset, then it returns if there is any base/parent or 'sister' assent with balance. Example:
12
+ * - tfuel, return true if there is theta.
13
+ *
14
+ * This selector is useful when testing that the wallet is not drying up all the fuel token (relativeTokenName)
15
+ * when holding other assets that require it to operate.
16
+ *
17
+ */
18
+
19
+ const selectorFactory = (isTxLogLoadedSelector, getAssetBalanceSelector, assetsSelector) =>
20
+ memoizeByAssetSource(({ assetName, walletAccount }) =>
21
+ createSelector(
22
+ isTxLogLoadedSelector,
23
+ getAssetBalanceSelector,
24
+ assetsSelector,
25
+ (isTxLogLoaded, getAssetBalance, assets) => {
26
+ if (!isTxLogLoaded(walletAccount)) return false
27
+ const asset = assets[assetName]
28
+ if (!asset) {
29
+ // not all assets are supported by Exodus.
30
+ return false
31
+ }
32
+
33
+ const baseAssetName = asset.baseAsset.name
34
+ const relatedAssets = Object.values(assets).filter(
35
+ (asset) => asset.baseAsset.name === baseAssetName && asset.name !== assetName
36
+ )
37
+ // check that at least one token has non-zero balance
38
+ return relatedAssets.some((token) => {
39
+ const balance = getAssetBalance({
40
+ assetName: token.name,
41
+ walletAccount,
42
+ })
43
+ return balance && !balance.isZero
44
+ })
45
+ }
46
+ )
47
+ )
48
+
49
+ const createRequiresFuelThresholdSelectorDefinition = {
50
+ id: 'createRequiresFuelThreshold',
51
+ selectorFactory,
52
+ dependencies: [
53
+ { module: 'txLog', selector: 'createIsWalletAccountLoadedSelectorOld' },
54
+ { module: 'balances', selector: 'getAssetSourceBalanceSelector' },
55
+ { module: 'availableAssets', selector: 'all' },
56
+ ],
57
+ }
58
+
59
+ export default createRequiresFuelThresholdSelectorDefinition
@@ -5,6 +5,8 @@ import getBalanceSelectors from './get-balance-selectors'
5
5
  import getBalancesSelectorDefinition from './get-balances'
6
6
  import createBalancesSelectors from './create-balance-selectors'
7
7
  import getUnconfirmedBalanceSelectorDefinition from './get-unconfirmed-balance'
8
+ import createFuelThresholdSelectorDefinition from './create-fuel-threshold.js'
9
+ import createRequiresFuelThresholdSelectorDefinition from './create-requires-fuel-threshold.js'
8
10
 
9
11
  export default [
10
12
  byAssetSelectorDefinition,
@@ -14,4 +16,6 @@ export default [
14
16
  ...createBalancesSelectors,
15
17
  getBalancesSelectorDefinition,
16
18
  getUnconfirmedBalanceSelectorDefinition,
19
+ createFuelThresholdSelectorDefinition,
20
+ createRequiresFuelThresholdSelectorDefinition,
17
21
  ]