@exodus/fiat-balances 10.12.3 → 10.12.4

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,12 @@
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.12.4](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@10.12.3...@exodus/fiat-balances@10.12.4) (2024-07-25)
7
+
8
+ ### Bug Fixes
9
+
10
+ - migrate definitions ([#8030](https://github.com/ExodusMovement/exodus-hydra/issues/8030)) ([d2dfde5](https://github.com/ExodusMovement/exodus-hydra/commit/d2dfde55dfa843eb52842f64b3aac3a6f9a59069))
11
+
6
12
  ## [10.12.3](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@10.12.2...@exodus/fiat-balances@10.12.3) (2024-07-18)
7
13
 
8
14
  **Note:** Version bump only for package @exodus/fiat-balances
package/README.md CHANGED
@@ -1,10 +1,6 @@
1
1
  # @exodus/fiat-balances
2
2
 
3
- This module tracks fiat balances for different networks (assets + their tokens) and portfolios.
4
-
5
- ## WARNING: no asset specifics!
6
-
7
- If you introduce any asset specifics like `if (assetName === 'dogicorn') balance = balance.mul(2)`, you will be fired immediately. This is a safety measure to save you from @feri42's wrath.
3
+ This Exodus SDK feature tracks fiat-denominated balances for all enabled wallet accounts, based on the application's locale and [user's preferred currency](../locale). For crypto-denominated balances, check out [@exodus/balances](../balances).
8
4
 
9
5
  ## Install
10
6
 
@@ -14,49 +10,72 @@ yarn add @exodus/fiat-balances
14
10
 
15
11
  ## Usage
16
12
 
13
+ This feature is designed to be used together with `@exodus/headless`. See [using the sdk](../../docs/using-the-sdk.md).
14
+
15
+ ### Play with it
16
+
17
+ 1. Open the playground https://exodus-hydra.pages.dev/
18
+ 2. Run `selectors.fiatBalances.byAsset(store.getState())` in the Dev Tools Console to get fiat balances by asset aggregated across enabled wallet accounts.
19
+ 3. Try out some other selectors from `selectors.fiatBalances`. See example usage in [tests](./redux/__tests__/selectors/).
20
+ 4. Mock an address with a balance, tick the blockchain monitor and check your balance.
21
+
17
22
  ```js
18
- import createFiatBalances from '@exodus/fiat-balances'
19
-
20
- const fiatBalances = createFiatBalances({
21
- // see #/assets-module in exodus-browser or tests for the API
22
- assetsModule,
23
- // @exodus/balances instance
24
- balances,
25
- // instance of https://github.com/ExodusMovement/exodus-browser/blob/c74cfb08b39f90675c5574707d8162b9472fdeb4/src/_local_modules/monitors/rates/index.js
26
- ratesMonitor,
27
- // only 'balance' is supported for now
28
- balanceFields: ['balance'],
29
- // see ../modules/module/src/logger.js for API
30
- logger,
23
+ // mock your ethereum address with one that has a balance
24
+ await exodus.debug.addressProvider.mockAddress({
25
+ assetName: 'ethereum',
26
+ walletAccount: 'exodus_0',
27
+ address: '0x1111111111111111111111111111111111111111',
31
28
  })
29
+ // force tick the ethereum monitor, or wait a while
30
+ await exodus.txLogMonitors.update({ assetName: 'ethereum', refresh: true })
31
+ // check your ETH balance in the user's preferred currency
32
+ selectors.fiatBalances.byAsset(store.getState()).ethereum.toDefaultString({ unit: true }) // 123.45 USD
33
+ // change currency
34
+ await exodus.locale.setCurrency('EUR')
35
+ selectors.fiatBalances.byAsset(store.getState()).ethereum.toDefaultString({ unit: true }) // 6.78 EUR
36
+ ```
32
37
 
33
- fiatBalances.on('fiat-balances', ({ balances }) => {
34
- // `balances`
35
- // {
36
- // totals: {
37
- // [balanceField]: NumberUnit,
38
- // },
39
- // byWalletAccount: {
40
- // [walletAccount]: {
41
- // [balanceField]: NumberUnit,
42
- // }
43
- // },
44
- // byAssetSource: {
45
- // [walletAccount]: {
46
- // [assetName]: {
47
- // [balanceField]: NumberUnit
48
- // }
49
- // }
50
- // },
51
- // byBaseAssetSource: {
52
- // [walletAccount]: {
53
- // [assetName]: {
54
- // [balanceField]: NumberUnit
55
- // }
56
- // }
57
- // }
58
- // }
59
- })
38
+ ### API Side
39
+
40
+ See [using the sdk](../../docs/using-the-sdk.md#setup-the-api-side) for more details on how features plug into the SDK. Note that the balances feature currently doesn't provide a top level API and is meant to be used purely through selectors.
41
+
42
+ If you're building a feature that requires balances, add a dependency on the `fiatBalancesAtom` as below.
43
+
44
+ ```js
45
+ const myModuleDefinition = {
46
+ id: 'myModule',
47
+ type: 'module',
48
+ factory: ({ fiatBalancesAtom }) => {
49
+ const doSomethingSpecial = async () => {
50
+ const { balances } = await fiatBalancesAtom.get()
51
+ console.log(
52
+ '>>> total wallet balance',
53
+ balances.totals.balance.toDefaultString({ unit: true })
54
+ )
55
+ }
56
+
57
+ return {
58
+ doSomethingSpecial,
59
+ }
60
+ },
61
+ dependencies: ['fiatBalancesAtom'],
62
+ }
63
+ ```
64
+
65
+ ### UI Side
66
+
67
+ See [using the sdk](../../docs/using-the-sdk.md#events) for more details on basic UI-side setup.
68
+
69
+ ```js
70
+ import { selectors } from '~/ui/flux'
71
+
72
+ const MyComponent = () => {
73
+ const totalWalletBalance = useSelector(
74
+ selectors.fiatBalances.optimisticTotalBalance(store.getState())
75
+ ) // returns a NumberUnit
60
76
 
61
- fiatBalances.sync() // forces 'fiat-balances' event emission
77
+ // create a function to convert ethereum to the user's preferred currency
78
+ const ethToFiat = useSelector(selectors.fiatBalances.createAssetConversion('ethereum'))
79
+ const ethBalanceInFiat = ethToFiat(ethereum.currency.defaultUnit(1))
80
+ }
62
81
  ```
package/atoms/index.js CHANGED
@@ -7,6 +7,7 @@ export const fiatBalancesAtomDefinition = {
7
7
  type: 'atom',
8
8
  factory: createFiatBalancesAtom,
9
9
  dependencies: [],
10
+ public: true,
10
11
  }
11
12
 
12
13
  export const optimisticFiatBalancesAtomDefinition = {
@@ -14,6 +15,7 @@ export const optimisticFiatBalancesAtomDefinition = {
14
15
  type: 'atom',
15
16
  factory: createOptimisticFiatBalancesAtom,
16
17
  dependencies: [],
18
+ public: true,
17
19
  }
18
20
 
19
21
  export const nonDustBalanceAssetNamesAtomDefinition = {
@@ -21,4 +23,5 @@ export const nonDustBalanceAssetNamesAtomDefinition = {
21
23
  type: 'atom',
22
24
  factory: createNonDustBalanceAssetNamesAtom,
23
25
  dependencies: [],
26
+ public: true,
24
27
  }
@@ -259,6 +259,7 @@ const fiatBalancesDefinition = {
259
259
  'ratesAtom',
260
260
  'currencyAtom',
261
261
  ],
262
+ public: true,
262
263
  }
263
264
 
264
265
  export default fiatBalancesDefinition
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@exodus/fiat-balances",
3
- "version": "10.12.3",
3
+ "version": "10.12.4",
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",
7
7
  "scripts": {
8
- "test": "run -T jest",
8
+ "test": "run -T exodus-test --jest --esbuild",
9
9
  "lint": "run -T eslint . --ignore-path ../../.gitignore",
10
- "lint:fix": "yarn lint --fix"
10
+ "lint:fix": "yarn lint --fix",
11
+ "format": "run -T prettier --write \"**/*.{json,md,yaml}\" --log-level warn",
12
+ "format:check": "run -T prettier --check \"**/*.{json,md,yaml}\" --log-level warn"
11
13
  },
12
14
  "main": "index.js",
13
15
  "files": [
@@ -43,23 +45,23 @@
43
45
  "devDependencies": {
44
46
  "@exodus/assets": "^9.1.0",
45
47
  "@exodus/assets-base": "^8.1.17",
46
- "@exodus/assets-feature": "^5.8.1",
47
- "@exodus/available-assets": "^8.3.1",
48
- "@exodus/balances": "^13.2.2",
49
- "@exodus/blockchain-metadata": "^15.3.4",
48
+ "@exodus/assets-feature": "^5.8.2",
49
+ "@exodus/available-assets": "^8.4.0",
50
+ "@exodus/balances": "^13.2.3",
51
+ "@exodus/blockchain-metadata": "^15.3.5",
50
52
  "@exodus/combined-assets-meta": "^1.3.0",
51
- "@exodus/enabled-assets": "^10.4.1",
52
- "@exodus/favorite-assets": "^2.4.2",
53
- "@exodus/fee-data-monitors": "^4.2.0",
54
- "@exodus/locale": "^2.2.1",
53
+ "@exodus/enabled-assets": "^10.5.1",
54
+ "@exodus/favorite-assets": "^2.4.3",
55
+ "@exodus/fee-data-monitors": "^4.2.1",
56
+ "@exodus/locale": "^2.2.2",
55
57
  "@exodus/models": "^8.9.0",
56
- "@exodus/rates-monitor": "^4.3.2",
58
+ "@exodus/rates-monitor": "^4.3.3",
57
59
  "@exodus/redux-dependency-injection": "^3.2.3",
58
60
  "@exodus/solana-meta": "^1.0.4",
59
61
  "@exodus/storage-memory": "^2.1.1",
60
- "@exodus/wallet-accounts": "^16.8.1",
62
+ "@exodus/wallet-accounts": "^16.8.2",
61
63
  "events": "^3.3.0",
62
64
  "redux": "^4.2.1"
63
65
  },
64
- "gitHead": "a76a22c96445bcaa05e18de0e0c323cf9dd04cba"
66
+ "gitHead": "3995391eb48639b2d60ced5224a6a8f4902a2466"
65
67
  }
package/plugin/index.js CHANGED
@@ -49,6 +49,7 @@ const fiatBalancesPluginDefinition = {
49
49
  'optimisticFiatBalances?',
50
50
  'optimisticFiatBalancesAtom?',
51
51
  ],
52
+ public: true,
52
53
  }
53
54
 
54
55
  export default fiatBalancesPluginDefinition
@@ -93,6 +93,7 @@ const trackNonDustAssetsNamesPluginDefinition = {
93
93
  'assetsModule',
94
94
  'config?',
95
95
  ],
96
+ public: true,
96
97
  }
97
98
 
98
99
  export default trackNonDustAssetsNamesPluginDefinition
@@ -1,4 +1,4 @@
1
- import { memoize } from 'lodash'
1
+ import { memoize } from 'lodash' // eslint-disable-line @exodus/restricted-imports/prefer-basic-utils -- TODO: fix next time we touch this file
2
2
  import { createSelector } from 'reselect'
3
3
  import { isMultiNetworkAsset } from '../utils'
4
4
  import { keyBy, orderBy } from '@exodus/basic-utils'