@exodus/fiat-balances 9.1.2 → 10.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 +17 -0
- package/index.js +11 -1
- package/module/fiat-balances.js +14 -6
- package/module/index.js +1 -1
- package/package.json +8 -4
- package/plugin/index.js +1 -0
- package/plugin/track-non-dust-asset-names.js +98 -0
- package/redux/selectors/byBaseAssetSource.js +16 -0
- package/redux/selectors/byBaseAssetSourceField.js +12 -0
- package/redux/selectors/index.js +4 -0
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
|
+
## [10.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@9.1.2...@exodus/fiat-balances@10.0.0) (2023-12-12)
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
- mv `trackNonDustAssetsNamesPlugin` to fiat-balances (#4988)
|
|
11
|
+
- pass max wallet account amount to redux module (#4968)
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- **fiat-balances:** add by base asset source selector ([#4695](https://github.com/ExodusMovement/exodus-hydra/issues/4695)) ([47a10a0](https://github.com/ExodusMovement/exodus-hydra/commit/47a10a07c5d24e25e838d9c4f6a6063c7364886f))
|
|
16
|
+
- mv `trackNonDustAssetsNamesPlugin` to fiat-balances ([#4988](https://github.com/ExodusMovement/exodus-hydra/issues/4988)) ([270d109](https://github.com/ExodusMovement/exodus-hydra/commit/270d109b0198a5b705059b12a77dff726b3314cc))
|
|
17
|
+
- pass max wallet account amount to redux module ([#4968](https://github.com/ExodusMovement/exodus-hydra/issues/4968)) ([e6ab869](https://github.com/ExodusMovement/exodus-hydra/commit/e6ab8696da1ae56921ca4faef2b964096c005280))
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
- cleanup subscriptions on stop ([#4814](https://github.com/ExodusMovement/exodus-hydra/issues/4814)) ([d053582](https://github.com/ExodusMovement/exodus-hydra/commit/d0535826c2023dd4d3273b367bbcc5cca6e4bb95))
|
|
22
|
+
|
|
6
23
|
## [9.1.2](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@9.1.1...@exodus/fiat-balances@9.1.2) (2023-10-20)
|
|
7
24
|
|
|
8
25
|
### Bug Fixes
|
package/index.js
CHANGED
|
@@ -5,8 +5,17 @@ import {
|
|
|
5
5
|
optimisticFiatBalancesAtomDefinition,
|
|
6
6
|
} from './atoms'
|
|
7
7
|
import fiatBalancesPluginDefinition from './plugin'
|
|
8
|
+
import trackNonDustAssetsNamesPluginDefinition from './plugin/track-non-dust-asset-names'
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @param optimistic {boolean}
|
|
12
|
+
* @param nonDustAssets {object}
|
|
13
|
+
* @param nonDustAssets.balanceThresholdsUsd {object}
|
|
14
|
+
* @param nonDustAssets.balanceThresholdByChainUsd {object}
|
|
15
|
+
* @param nonDustAssets.defaultBalanceThresholdUsd {import('@exodus/fiat-currencies').Unit}
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const fiatBalances = ({ optimistic, nonDustAssets }) => ({
|
|
10
19
|
id: 'fiatBalances',
|
|
11
20
|
definitions: [
|
|
12
21
|
{
|
|
@@ -15,6 +24,7 @@ const fiatBalances = ({ optimistic }) => ({
|
|
|
15
24
|
},
|
|
16
25
|
{ definition: fiatBalancesAtomDefinition },
|
|
17
26
|
{ definition: fiatBalancesPluginDefinition },
|
|
27
|
+
{ definition: trackNonDustAssetsNamesPluginDefinition, config: nonDustAssets },
|
|
18
28
|
{ definition: nonDustBalanceAssetNamesAtomDefinition },
|
|
19
29
|
{
|
|
20
30
|
if: optimistic,
|
package/module/fiat-balances.js
CHANGED
|
@@ -28,6 +28,7 @@ class FiatBalances extends ExodusModule {
|
|
|
28
28
|
// #balances.byWalletAccount: Object,
|
|
29
29
|
// #balances.byAssetSource: Object,
|
|
30
30
|
// #balances.byBaseAssetSource: Object,
|
|
31
|
+
#subscriptions = []
|
|
31
32
|
|
|
32
33
|
constructor({
|
|
33
34
|
assetsModule,
|
|
@@ -51,12 +52,14 @@ class FiatBalances extends ExodusModule {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
load = () => {
|
|
54
|
-
this.#
|
|
55
|
-
this.#
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
this.#subscriptions.push(
|
|
56
|
+
this.#inputAtom.observe(({ currency, rates }) => {
|
|
57
|
+
this.#fiatCurrency = currency
|
|
58
|
+
this.#cachedRates = rates
|
|
59
|
+
this.#maybeRecompute()
|
|
60
|
+
}),
|
|
61
|
+
this.#balancesAtom.observe(this.#setBalances)
|
|
62
|
+
)
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
#isReady = () => {
|
|
@@ -240,6 +243,11 @@ class FiatBalances extends ExodusModule {
|
|
|
240
243
|
const data = cloneBalances({ balances: this.#balances })
|
|
241
244
|
this.#fiatBalancesAtom.set((current) => (isEqual(current, data) ? current : data))
|
|
242
245
|
}
|
|
246
|
+
|
|
247
|
+
stop = () => {
|
|
248
|
+
this.#subscriptions.forEach((unsubscribe) => unsubscribe())
|
|
249
|
+
this.#subscriptions = []
|
|
250
|
+
}
|
|
243
251
|
}
|
|
244
252
|
|
|
245
253
|
const createFiatBalances = (...args) => new FiatBalances(...args)
|
package/module/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default from './fiat-balances'
|
|
1
|
+
export { default } from './fiat-balances'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/fiat-balances",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.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",
|
|
@@ -31,17 +31,21 @@
|
|
|
31
31
|
"@exodus/currency": "^2.1.2",
|
|
32
32
|
"@exodus/fiat-currencies": "^1.0.0",
|
|
33
33
|
"@exodus/module": "^1.1.0",
|
|
34
|
+
"@exodus/typeforce": "^1.18.1",
|
|
34
35
|
"lodash": "^4.17.21",
|
|
36
|
+
"minimalistic-assert": "^1.0.1",
|
|
35
37
|
"reselect": "^3.0.1"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
|
-
"@exodus/
|
|
39
|
-
"@exodus/
|
|
40
|
+
"@exodus/assets": "^9.1.0",
|
|
41
|
+
"@exodus/atoms": "^7.0.0",
|
|
42
|
+
"@exodus/balances": "^12.0.0",
|
|
40
43
|
"@exodus/basic-utils": "^2.0.0",
|
|
41
44
|
"@exodus/blockchain-metadata": "*",
|
|
42
45
|
"@exodus/enabled-assets": "^9.0.1",
|
|
43
46
|
"@exodus/models": "^8.9.0",
|
|
44
47
|
"@exodus/redux-dependency-injection": "^3.0.0",
|
|
48
|
+
"@exodus/solana-meta": "^1.0.4",
|
|
45
49
|
"@exodus/storage-memory": "^2.1.1",
|
|
46
50
|
"@exodus/wallet-accounts": "*",
|
|
47
51
|
"eslint": "^8.44.0",
|
|
@@ -49,5 +53,5 @@
|
|
|
49
53
|
"jest": "^29.1.2",
|
|
50
54
|
"redux": "^4.2.1"
|
|
51
55
|
},
|
|
52
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "678623e0bd6eddc9d7615648878938a807cf3a33"
|
|
53
57
|
}
|
package/plugin/index.js
CHANGED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { flattenToPaths, filterAsync } from '@exodus/basic-utils'
|
|
2
|
+
import fiatCurrencies from '@exodus/fiat-currencies'
|
|
3
|
+
import { isEqual } from 'lodash'
|
|
4
|
+
|
|
5
|
+
const { USD } = fiatCurrencies
|
|
6
|
+
|
|
7
|
+
const DEFAULT_BALANCES_THRESHOLD_USD = USD.defaultUnit(0.5)
|
|
8
|
+
|
|
9
|
+
const createTrackNonDustAssetNamesPlugin = ({
|
|
10
|
+
assetsModule,
|
|
11
|
+
fiatBalancesAtom,
|
|
12
|
+
fiatRateConverter,
|
|
13
|
+
nonDustBalanceAssetNamesAtom,
|
|
14
|
+
config: {
|
|
15
|
+
balanceThresholdsUsd = {},
|
|
16
|
+
balanceThresholdByChainUsd = {},
|
|
17
|
+
defaultBalanceThresholdUsd = DEFAULT_BALANCES_THRESHOLD_USD,
|
|
18
|
+
},
|
|
19
|
+
}) => {
|
|
20
|
+
const handleFiatBalancesChanged = async ({ balances }) => {
|
|
21
|
+
const { byAssetSource } = balances
|
|
22
|
+
if (!byAssetSource) return
|
|
23
|
+
|
|
24
|
+
const balancesByAssetSource = flattenToPaths(byAssetSource).map(
|
|
25
|
+
([walletAccount, assetName, balanceField, balance]) => ({ walletAccount, assetName, balance })
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
const aboveThreshold = await filterAsync(
|
|
29
|
+
balancesByAssetSource,
|
|
30
|
+
async ({ assetName, balance }) => {
|
|
31
|
+
const usdBalance = await fiatRateConverter.toFiatCurrency({
|
|
32
|
+
currency: 'USD',
|
|
33
|
+
amount: balance,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return isAboveEnableThreshold({ assetName, usdBalance })
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
const nonDisableableAssetNamesSet = new Set(aboveThreshold.map(({ assetName }) => assetName))
|
|
41
|
+
|
|
42
|
+
const before = [...(await nonDustBalanceAssetNamesAtom.get())]
|
|
43
|
+
const after = [...nonDisableableAssetNamesSet]
|
|
44
|
+
if (!isEqual(before.sort(), after.sort())) await nonDustBalanceAssetNamesAtom.set(after)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let unobserveFiatBalancesAtom
|
|
48
|
+
const onLoad = () => {
|
|
49
|
+
unobserveFiatBalancesAtom = fiatBalancesAtom.observe((data) => {
|
|
50
|
+
// don't block processing
|
|
51
|
+
handleFiatBalancesChanged(data)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const onUnload = () => {
|
|
56
|
+
unobserveFiatBalancesAtom?.()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const resolveConfiguredThreshold = (asset) =>
|
|
60
|
+
balanceThresholdsUsd[asset.name] ||
|
|
61
|
+
balanceThresholdByChainUsd[asset.baseAsset.name] ||
|
|
62
|
+
defaultBalanceThresholdUsd
|
|
63
|
+
|
|
64
|
+
const isAboveEnableThreshold = async ({ assetName, usdBalance }) => {
|
|
65
|
+
const asset = assetsModule.getAsset(assetName)
|
|
66
|
+
const reserve = asset.accountReserve || asset.currency.ZERO
|
|
67
|
+
const configuredThreshold = resolveConfiguredThreshold(asset)
|
|
68
|
+
const reserveUsd = asset.accountReserve
|
|
69
|
+
? await fiatRateConverter.toFiatCurrency({
|
|
70
|
+
currency: 'USD',
|
|
71
|
+
amount: reserve,
|
|
72
|
+
})
|
|
73
|
+
: USD.ZERO
|
|
74
|
+
|
|
75
|
+
const usdThreshold = reserveUsd.add(configuredThreshold)
|
|
76
|
+
return usdBalance.gte(usdThreshold)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
onLoad,
|
|
81
|
+
onUnload,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const trackNonDustAssetsNamesPluginDefinition = {
|
|
86
|
+
id: 'trackNonDustAssetsNamesPlugin',
|
|
87
|
+
type: 'plugin',
|
|
88
|
+
factory: createTrackNonDustAssetNamesPlugin,
|
|
89
|
+
dependencies: [
|
|
90
|
+
'nonDustBalanceAssetNamesAtom',
|
|
91
|
+
'fiatBalancesAtom',
|
|
92
|
+
'fiatRateConverter',
|
|
93
|
+
'assetsModule',
|
|
94
|
+
'config?',
|
|
95
|
+
],
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default trackNonDustAssetsNamesPluginDefinition
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createSelector } from 'reselect'
|
|
2
|
+
import { toBalanceOnly } from './utils'
|
|
3
|
+
|
|
4
|
+
const selectorFactory = (byAssetSourceSelector) =>
|
|
5
|
+
createSelector(byAssetSourceSelector, toBalanceOnly)
|
|
6
|
+
|
|
7
|
+
const byBaseAssetSourceSelector = {
|
|
8
|
+
id: 'byBaseAssetSource',
|
|
9
|
+
selectorFactory,
|
|
10
|
+
dependencies: [
|
|
11
|
+
//
|
|
12
|
+
{ selector: 'byBaseAssetSourceField' },
|
|
13
|
+
],
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default byBaseAssetSourceSelector
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const resultFunction = (data) => data.byBaseAssetSource
|
|
2
|
+
|
|
3
|
+
const byBaseAssetSourceFieldSelector = {
|
|
4
|
+
id: 'byBaseAssetSourceField',
|
|
5
|
+
resultFunction,
|
|
6
|
+
dependencies: [
|
|
7
|
+
//
|
|
8
|
+
{ selector: 'data' },
|
|
9
|
+
],
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default byBaseAssetSourceFieldSelector
|
package/redux/selectors/index.js
CHANGED
|
@@ -3,6 +3,8 @@ import byWalletAccountSelector from './byWalletAccount'
|
|
|
3
3
|
import byWalletAccountFieldSelector from './byWalletAccountField'
|
|
4
4
|
import byAssetSourceFieldSelector from './byAssetSourceField'
|
|
5
5
|
import byAssetInActiveAccountSelector from './byAssetInActiveAccount'
|
|
6
|
+
import byBaseAssetSourceSelector from './byBaseAssetSource'
|
|
7
|
+
import byBaseAssetSourceFieldSelector from './byBaseAssetSourceField'
|
|
6
8
|
import optimisticByAssetInActiveAccountSelector from './optimisticByAssetInActiveAccount'
|
|
7
9
|
import optimisticByAssetSourceSelector from './optimisticByAssetSource'
|
|
8
10
|
import optimisticByAssetSourceFieldSelector from './optimisticByAssetSourceField'
|
|
@@ -16,6 +18,8 @@ export default [
|
|
|
16
18
|
byAssetSourceSelector,
|
|
17
19
|
byAssetSourceFieldSelector,
|
|
18
20
|
byAssetInActiveAccountSelector,
|
|
21
|
+
byBaseAssetSourceSelector,
|
|
22
|
+
byBaseAssetSourceFieldSelector,
|
|
19
23
|
byWalletAccountSelector,
|
|
20
24
|
byWalletAccountFieldSelector,
|
|
21
25
|
optimisticByAssetInActiveAccountSelector,
|