@exodus/balances 13.4.0 → 13.5.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 +6 -0
- package/atoms/asset-total-wallet-amounts.js +46 -0
- package/atoms/index.js +9 -0
- package/default-config.js +2 -1
- package/index.js +6 -0
- package/package.json +2 -2
- package/plugins/analytics.js +20 -1
- package/plugins/index.js +7 -1
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
|
+
## [13.5.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.4.0...@exodus/balances@13.5.0) (2024-11-29)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- feat: add various crypto balance props (#10419)
|
|
11
|
+
|
|
6
12
|
## [13.4.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@13.3.2...@exodus/balances@13.4.0) (2024-11-25)
|
|
7
13
|
|
|
8
14
|
### Features
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { compute, dedupe } from '@exodus/atoms'
|
|
2
|
+
|
|
3
|
+
const mapsAreEqual = (mapA, mapB) => {
|
|
4
|
+
if (mapA.size !== mapB.size) {
|
|
5
|
+
return false
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
for (const item of mapA) {
|
|
9
|
+
if (!mapB.has(item)) {
|
|
10
|
+
return false
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return true
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const createAssetTotalWalletAmountsAtom = ({ balancesAtom }) => {
|
|
18
|
+
let previousValue = new Map()
|
|
19
|
+
const selector = ({ balances }) => {
|
|
20
|
+
const assetsWithBalances = new Map()
|
|
21
|
+
|
|
22
|
+
Object.values(balances).forEach((accountBalances) => {
|
|
23
|
+
Object.keys(accountBalances).forEach((assetName) => {
|
|
24
|
+
if (assetsWithBalances.has(assetName)) {
|
|
25
|
+
const currentAssetBalance = assetsWithBalances.get(assetName)
|
|
26
|
+
assetsWithBalances.set(
|
|
27
|
+
assetName,
|
|
28
|
+
accountBalances[assetName]?.balance.add(currentAssetBalance)
|
|
29
|
+
)
|
|
30
|
+
} else {
|
|
31
|
+
assetsWithBalances.set(assetName, accountBalances[assetName]?.balance)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
if (!mapsAreEqual(assetsWithBalances, previousValue)) {
|
|
37
|
+
previousValue = assetsWithBalances
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return previousValue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return dedupe(compute({ atom: balancesAtom, selector }))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default createAssetTotalWalletAmountsAtom
|
package/atoms/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import createAssetsWithBalanceCountAtom from './assets-with-balance-count.js'
|
|
|
3
3
|
import createBalancesAtom from './balances.js'
|
|
4
4
|
import createFundedWalletAccountsAtom from './funded-wallet-accounts.js'
|
|
5
5
|
import createHasBalanceAtom from './has-balance.js'
|
|
6
|
+
import createAssetsTotalWalletAmountsAtom from './asset-total-wallet-amounts.js'
|
|
6
7
|
|
|
7
8
|
export const balancesAtomDefinition = {
|
|
8
9
|
id: 'balancesAtom',
|
|
@@ -43,3 +44,11 @@ export const assetsWithBalanceCountAtomDefinition = {
|
|
|
43
44
|
dependencies: ['assetNamesWithBalanceAtom'],
|
|
44
45
|
public: true,
|
|
45
46
|
}
|
|
47
|
+
|
|
48
|
+
export const assetsTotalWalletAmountsDefinition = {
|
|
49
|
+
id: 'assetsTotalWalletAmountsAtom',
|
|
50
|
+
type: 'atom',
|
|
51
|
+
factory: createAssetsTotalWalletAmountsAtom,
|
|
52
|
+
dependencies: ['balancesAtom'],
|
|
53
|
+
public: true,
|
|
54
|
+
}
|
package/default-config.js
CHANGED
|
@@ -19,7 +19,8 @@ const config = {
|
|
|
19
19
|
balanceFieldsConfig,
|
|
20
20
|
balanceFields: balanceFieldsConfig
|
|
21
21
|
.flatMap((fieldConfig) => [fieldConfig.name, fieldConfig.legacyName])
|
|
22
|
-
.filter(Boolean), // wallets can reduce the number of exposed fields
|
|
22
|
+
.filter(Boolean), // wallets can reduce the number of exposed fields,
|
|
23
|
+
assetsToTrackForBalances: [],
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export default config
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
fundedWalletAccountsAtomDefinition,
|
|
6
6
|
assetsWithBalanceCountAtomDefinition,
|
|
7
7
|
assetNamesWithBalanceAtomDefinition,
|
|
8
|
+
assetsTotalWalletAmountsDefinition,
|
|
8
9
|
} from './atoms/index.js'
|
|
9
10
|
import balancesReportDefinition from './report/index.js'
|
|
10
11
|
import {
|
|
@@ -18,11 +19,14 @@ const balances = (walletConfig) => {
|
|
|
18
19
|
const config = {
|
|
19
20
|
...defaultConfig,
|
|
20
21
|
balanceFields: walletConfig?.balanceFields || defaultConfig.balanceFields,
|
|
22
|
+
assetsToTrackForBalances:
|
|
23
|
+
walletConfig?.assetsToTrackForBalances || defaultConfig.assetsToTrackForBalances,
|
|
21
24
|
}
|
|
22
25
|
typeforce(
|
|
23
26
|
{
|
|
24
27
|
balanceFields: typeforce.arrayOf('String'),
|
|
25
28
|
balanceFieldsConfig: typeforce.arrayOf('Object'),
|
|
29
|
+
assetsToTrackForBalances: typeforce.arrayOf('Object'),
|
|
26
30
|
},
|
|
27
31
|
config,
|
|
28
32
|
true
|
|
@@ -46,9 +50,11 @@ const balances = (walletConfig) => {
|
|
|
46
50
|
{ definition: fundedWalletAccountsAtomDefinition },
|
|
47
51
|
{ definition: balancesReportDefinition },
|
|
48
52
|
{ definition: balancesLifecyclePluginDefinition },
|
|
53
|
+
{ definition: assetsTotalWalletAmountsDefinition },
|
|
49
54
|
{
|
|
50
55
|
if: { registered: ['analytics'] },
|
|
51
56
|
definition: balancesAnalyticsPluginDefinition,
|
|
57
|
+
config: { assetsToTrackForBalances: config.assetsToTrackForBalances },
|
|
52
58
|
},
|
|
53
59
|
],
|
|
54
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/balances",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.5.0",
|
|
4
4
|
"description": "Tracks crypto balances across enabled wallet accounts.",
|
|
5
5
|
"author": "Exodus Movement, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "d979dacecad62ad66a5761afc08d6ea362ca05a5"
|
|
69
69
|
}
|
package/plugins/analytics.js
CHANGED
|
@@ -2,9 +2,16 @@ const createBalancesAnalyticsPlugin = ({
|
|
|
2
2
|
analytics,
|
|
3
3
|
hasBalanceAtom,
|
|
4
4
|
assetsWithBalanceCountAtom,
|
|
5
|
+
assetsTotalWalletAmountsAtom,
|
|
6
|
+
config: { assetsToTrackForBalances },
|
|
5
7
|
}) => {
|
|
6
8
|
let subscriptions = []
|
|
7
9
|
|
|
10
|
+
const getAssetAmountFromNumberUnit = (unit) => {
|
|
11
|
+
if (!unit) return 0
|
|
12
|
+
return unit.toDefaultNumber()
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
const onStart = () => {
|
|
9
16
|
analytics.requireDefaultEventProperties(['hasBalance', 'numberOfAssets'])
|
|
10
17
|
|
|
@@ -16,7 +23,19 @@ const createBalancesAnalyticsPlugin = ({
|
|
|
16
23
|
analytics.setDefaultEventProperties({ numberOfAssets })
|
|
17
24
|
)
|
|
18
25
|
|
|
19
|
-
|
|
26
|
+
const unsubscribeWalletAmountsAtom = assetsTotalWalletAmountsAtom.observe(async (balances) => {
|
|
27
|
+
const assetBalances = assetsToTrackForBalances.reduce((acc, obj) => {
|
|
28
|
+
acc[obj.analyticsName] = getAssetAmountFromNumberUnit(balances.get(obj.assetName))
|
|
29
|
+
return acc
|
|
30
|
+
}, {})
|
|
31
|
+
analytics.setDefaultEventProperties(assetBalances)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
subscriptions = [
|
|
35
|
+
unsubscribeBalanceAtom,
|
|
36
|
+
unsubscribeBalanceCountAtom,
|
|
37
|
+
unsubscribeWalletAmountsAtom,
|
|
38
|
+
]
|
|
20
39
|
}
|
|
21
40
|
|
|
22
41
|
const onStop = () => {
|
package/plugins/index.js
CHANGED
|
@@ -13,6 +13,12 @@ export const balancesAnalyticsPluginDefinition = {
|
|
|
13
13
|
id: 'balancesAnalyticsPlugin',
|
|
14
14
|
type: 'plugin',
|
|
15
15
|
factory: createBalancesAnalyticsPlugin,
|
|
16
|
-
dependencies: [
|
|
16
|
+
dependencies: [
|
|
17
|
+
'analytics',
|
|
18
|
+
'hasBalanceAtom',
|
|
19
|
+
'assetsWithBalanceCountAtom',
|
|
20
|
+
'assetsTotalWalletAmountsAtom',
|
|
21
|
+
'config?',
|
|
22
|
+
],
|
|
17
23
|
public: true,
|
|
18
24
|
}
|