@exodus/fiat-balances 10.12.3 → 10.13.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 +12 -0
- package/README.md +65 -46
- package/atoms/index.js +3 -0
- package/index.js +2 -0
- package/module/fiat-balances.js +1 -0
- package/package.json +18 -15
- package/plugin/index.js +1 -0
- package/plugin/track-non-dust-asset-names.js +1 -0
- package/redux/selectors/helpers/sort-assets-selector-factory-creator.js +1 -1
- package/report/index.js +25 -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.13.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/fiat-balances@10.12.4...@exodus/fiat-balances@10.13.0) (2024-07-29)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **fiat-balances:** add fiat-balances report node ([#8103](https://github.com/ExodusMovement/exodus-hydra/issues/8103)) ([e48da5f](https://github.com/ExodusMovement/exodus-hydra/commit/e48da5f31e2162259ae04fb6ba282fbcaa6076f8))
|
|
11
|
+
|
|
12
|
+
## [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)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- migrate definitions ([#8030](https://github.com/ExodusMovement/exodus-hydra/issues/8030)) ([d2dfde5](https://github.com/ExodusMovement/exodus-hydra/commit/d2dfde55dfa843eb52842f64b3aac3a6f9a59069))
|
|
17
|
+
|
|
6
18
|
## [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
19
|
|
|
8
20
|
**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
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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
|
}
|
package/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from './atoms'
|
|
7
7
|
import fiatBalancesPluginDefinition from './plugin'
|
|
8
8
|
import trackNonDustAssetsNamesPluginDefinition from './plugin/track-non-dust-asset-names'
|
|
9
|
+
import fiatBalancesReportDefinition from './report'
|
|
9
10
|
|
|
10
11
|
const DEFAULT_BALANCE_FIELDS = ['balance']
|
|
11
12
|
|
|
@@ -33,6 +34,7 @@ const fiatBalances = (
|
|
|
33
34
|
},
|
|
34
35
|
{ definition: fiatBalancesAtomDefinition },
|
|
35
36
|
{ definition: fiatBalancesPluginDefinition },
|
|
37
|
+
{ definition: fiatBalancesReportDefinition },
|
|
36
38
|
{ definition: trackNonDustAssetsNamesPluginDefinition, config: nonDustAssets },
|
|
37
39
|
{ definition: nonDustBalanceAssetNamesAtomDefinition },
|
|
38
40
|
{
|
package/module/fiat-balances.js
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/fiat-balances",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.13.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",
|
|
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": [
|
|
@@ -15,6 +17,7 @@
|
|
|
15
17
|
"redux",
|
|
16
18
|
"atoms",
|
|
17
19
|
"plugin",
|
|
20
|
+
"report",
|
|
18
21
|
"shared",
|
|
19
22
|
"README.md",
|
|
20
23
|
"CHANGELOG.md",
|
|
@@ -43,23 +46,23 @@
|
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"@exodus/assets": "^9.1.0",
|
|
45
48
|
"@exodus/assets-base": "^8.1.17",
|
|
46
|
-
"@exodus/assets-feature": "^5.8.
|
|
47
|
-
"@exodus/available-assets": "^8.
|
|
48
|
-
"@exodus/balances": "^13.2.
|
|
49
|
-
"@exodus/blockchain-metadata": "^15.3.
|
|
49
|
+
"@exodus/assets-feature": "^5.8.3",
|
|
50
|
+
"@exodus/available-assets": "^8.4.1",
|
|
51
|
+
"@exodus/balances": "^13.2.3",
|
|
52
|
+
"@exodus/blockchain-metadata": "^15.3.5",
|
|
50
53
|
"@exodus/combined-assets-meta": "^1.3.0",
|
|
51
|
-
"@exodus/enabled-assets": "^10.
|
|
52
|
-
"@exodus/favorite-assets": "^2.4.
|
|
53
|
-
"@exodus/fee-data-monitors": "^4.2.
|
|
54
|
-
"@exodus/locale": "^2.2.
|
|
54
|
+
"@exodus/enabled-assets": "^10.5.2",
|
|
55
|
+
"@exodus/favorite-assets": "^2.4.3",
|
|
56
|
+
"@exodus/fee-data-monitors": "^4.2.1",
|
|
57
|
+
"@exodus/locale": "^2.2.2",
|
|
55
58
|
"@exodus/models": "^8.9.0",
|
|
56
|
-
"@exodus/rates-monitor": "^4.3.
|
|
57
|
-
"@exodus/redux-dependency-injection": "^
|
|
59
|
+
"@exodus/rates-monitor": "^4.3.3",
|
|
60
|
+
"@exodus/redux-dependency-injection": "^4.0.0",
|
|
58
61
|
"@exodus/solana-meta": "^1.0.4",
|
|
59
62
|
"@exodus/storage-memory": "^2.1.1",
|
|
60
|
-
"@exodus/wallet-accounts": "^16.8.
|
|
63
|
+
"@exodus/wallet-accounts": "^16.8.2",
|
|
61
64
|
"events": "^3.3.0",
|
|
62
65
|
"redux": "^4.2.1"
|
|
63
66
|
},
|
|
64
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "d309b0209d3b7d679984c3f5315cab2104bd6ddb"
|
|
65
68
|
}
|
package/plugin/index.js
CHANGED
|
@@ -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'
|
package/report/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { mapValues } from '@exodus/basic-utils'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* sample report
|
|
5
|
+
* {
|
|
6
|
+
* wallet_account_1: '50 USD',
|
|
7
|
+
* wallet_account_1: '0 USD'
|
|
8
|
+
* }
|
|
9
|
+
*/
|
|
10
|
+
const fiatBalancesReportDefinition = {
|
|
11
|
+
type: 'report',
|
|
12
|
+
id: 'fiatBalancesReport',
|
|
13
|
+
factory: ({ fiatBalancesAtom }) => ({
|
|
14
|
+
namespace: 'fiatBalances',
|
|
15
|
+
export: async () => {
|
|
16
|
+
const result = await fiatBalancesAtom.get()
|
|
17
|
+
return mapValues(result.balances.byWalletAccount, ({ balance }) =>
|
|
18
|
+
balance.toDefaultString({ unit: true })
|
|
19
|
+
)
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
dependencies: ['fiatBalancesAtom'],
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default fiatBalancesReportDefinition
|