@exodus/balances 7.1.0 → 8.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 +24 -0
- package/index.js +2 -0
- package/module/index.js +21 -14
- package/package.json +9 -7
- package/report/index.js +45 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
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
|
+
## [8.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@7.1.0...@exodus/balances@8.0.0) (2023-08-03)
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
- balances to use txLogsAtom and accountStatesAtom (#2900)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- add balances report ([#3059](https://github.com/ExodusMovement/exodus-hydra/issues/3059)) ([a06ae1c](https://github.com/ExodusMovement/exodus-hydra/commit/a06ae1c988fb9abc8899caa0093528495496df1f))
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
- **balances:** include report in package files ([#3130](https://github.com/ExodusMovement/exodus-hydra/issues/3130)) ([b0e515c](https://github.com/ExodusMovement/exodus-hydra/commit/b0e515c7c32d271303b77b82780cdae80540c1f5))
|
|
19
|
+
|
|
20
|
+
### Code Refactoring
|
|
21
|
+
|
|
22
|
+
- balances to use txLogsAtom and accountStatesAtom ([#2900](https://github.com/ExodusMovement/exodus-hydra/issues/2900)) ([7aa3c74](https://github.com/ExodusMovement/exodus-hydra/commit/7aa3c74fd8a646e47f3c326c9c82662d99515814))
|
|
23
|
+
|
|
24
|
+
## [7.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@7.1.0...@exodus/balances@7.2.0) (2023-08-01)
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
- add balances report ([#3059](https://github.com/ExodusMovement/exodus-hydra/issues/3059)) ([a06ae1c](https://github.com/ExodusMovement/exodus-hydra/commit/a06ae1c988fb9abc8899caa0093528495496df1f))
|
|
29
|
+
|
|
6
30
|
## [7.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@6.1.0...@exodus/balances@7.1.0) (2023-07-21)
|
|
7
31
|
|
|
8
32
|
### Features
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import balancesDefinition from './module'
|
|
2
2
|
import { balancesAtomDefinition, hasBalanceAtomDefinition } from './atoms'
|
|
3
|
+
import balancesReportDefinition from './report'
|
|
3
4
|
|
|
4
5
|
const balances = () => {
|
|
5
6
|
return {
|
|
@@ -11,6 +12,7 @@ const balances = () => {
|
|
|
11
12
|
},
|
|
12
13
|
{ definition: balancesAtomDefinition },
|
|
13
14
|
{ definition: hasBalanceAtomDefinition },
|
|
15
|
+
{ definition: balancesReportDefinition },
|
|
14
16
|
],
|
|
15
17
|
}
|
|
16
18
|
}
|
package/module/index.js
CHANGED
|
@@ -37,6 +37,8 @@ class Balances extends ExodusModule {
|
|
|
37
37
|
config: { balanceFields },
|
|
38
38
|
logger,
|
|
39
39
|
balancesAtom,
|
|
40
|
+
txLogsAtom,
|
|
41
|
+
accountStatesAtom,
|
|
40
42
|
}) {
|
|
41
43
|
super({ name: MODULE_ID, logger })
|
|
42
44
|
|
|
@@ -82,28 +84,30 @@ class Balances extends ExodusModule {
|
|
|
82
84
|
sanitizeArgs: (walletAccounts) => walletAccounts,
|
|
83
85
|
})
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
})
|
|
87
|
+
// eslint-disable-next-line hydra/module-side-effects
|
|
88
|
+
enabledWalletAccountsAtom.observe((payload) => {
|
|
89
|
+
this.#setWalletAccounts(Object.keys(payload))
|
|
90
|
+
})
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
)
|
|
92
|
+
// eslint-disable-next-line hydra/module-side-effects
|
|
93
|
+
accountStatesAtom.observe(({ changes }) =>
|
|
94
|
+
flattenToPaths(changes).forEach(([walletAccount, assetName, accountState]) =>
|
|
95
|
+
this.#handleAccountStateUpdate({ walletAccount, assetName, accountState })
|
|
95
96
|
)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
// eslint-disable-next-line hydra/module-side-effects
|
|
100
|
+
txLogsAtom.observe(({ changes }) =>
|
|
101
|
+
flattenToPaths(changes).forEach(([walletAccount, assetName, txLog]) =>
|
|
102
|
+
this.#handleTxLogUpdate({ walletAccount, assetName, txLog })
|
|
100
103
|
)
|
|
101
|
-
|
|
104
|
+
)
|
|
102
105
|
|
|
103
106
|
assetsModule.on('assets-add', this.#onAssetsChanged)
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
#getAsset = (assetName) => this.#assetsModule.getAsset(assetName)
|
|
110
|
+
|
|
107
111
|
#getAssets = () => this.#assetsModule.getAssets()
|
|
108
112
|
|
|
109
113
|
#handleAccountStateUpdate = async (opts) => {
|
|
@@ -113,6 +117,7 @@ class Balances extends ExodusModule {
|
|
|
113
117
|
})
|
|
114
118
|
return
|
|
115
119
|
}
|
|
120
|
+
|
|
116
121
|
return this.#updateAssetSource(opts)
|
|
117
122
|
}
|
|
118
123
|
|
|
@@ -353,6 +358,8 @@ const balancesDefinition = {
|
|
|
353
358
|
'config',
|
|
354
359
|
'logger',
|
|
355
360
|
'balancesAtom',
|
|
361
|
+
'txLogsAtom',
|
|
362
|
+
'accountStatesAtom',
|
|
356
363
|
],
|
|
357
364
|
}
|
|
358
365
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/balances",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Tracks crypto balances across enabled wallet accounts.",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"main": "index.js",
|
|
13
13
|
"files": [
|
|
14
|
-
"index.js",
|
|
15
14
|
"module",
|
|
16
15
|
"atoms",
|
|
16
|
+
"report",
|
|
17
17
|
"README.md",
|
|
18
18
|
"CHANGELOG.md",
|
|
19
19
|
"!**/__tests__/**"
|
|
@@ -27,18 +27,20 @@
|
|
|
27
27
|
"url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Abalances"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@exodus/atoms": "^5.
|
|
31
|
-
"@exodus/basic-utils": "^2.
|
|
30
|
+
"@exodus/atoms": "^5.4.0",
|
|
31
|
+
"@exodus/basic-utils": "^2.1.0",
|
|
32
32
|
"@exodus/currency": "^2.1.2",
|
|
33
33
|
"@exodus/module": "^1.1.0",
|
|
34
34
|
"lodash": "^4.17.21",
|
|
35
35
|
"make-concurrent": "^4.0.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@exodus/blockchain-metadata": "^
|
|
38
|
+
"@exodus/blockchain-metadata": "^9.0.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@exodus/
|
|
41
|
+
"@exodus/assets": "^8.0.94",
|
|
42
|
+
"@exodus/assets-base": "^8.1.10",
|
|
43
|
+
"@exodus/blockchain-metadata": "^9.0.1",
|
|
42
44
|
"@exodus/models": "^8.9.0",
|
|
43
45
|
"@exodus/storage-memory": "*",
|
|
44
46
|
"@exodus/wallet-accounts": "^9.1.0",
|
|
@@ -46,5 +48,5 @@
|
|
|
46
48
|
"events": "^3.3.0",
|
|
47
49
|
"jest": "^29.1.2"
|
|
48
50
|
},
|
|
49
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "dcaf15695cb43cd8618bc126953ba7f2c6a4707a"
|
|
50
52
|
}
|
package/report/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const createBalancesReport = ({ enabledWalletAccountsAtom, balancesAtom }) => ({
|
|
2
|
+
namespace: 'balances',
|
|
3
|
+
export: async () => {
|
|
4
|
+
let walletAccounts
|
|
5
|
+
let balances
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
;[walletAccounts, { balances }] = await Promise.all([
|
|
9
|
+
enabledWalletAccountsAtom.get(),
|
|
10
|
+
balancesAtom.get(),
|
|
11
|
+
])
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return { error }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return Object.keys(walletAccounts)
|
|
17
|
+
.filter((key) => walletAccounts[key].source !== 'ftx')
|
|
18
|
+
.reduce((data, key) => {
|
|
19
|
+
if (!balances[key]) {
|
|
20
|
+
data[key] = { error: 'No balances' }
|
|
21
|
+
return data
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const reportBalances = Object.fromEntries(
|
|
25
|
+
Object.entries(balances[key])
|
|
26
|
+
.filter(([_, value]) => !value.balance.isZero)
|
|
27
|
+
.map(([key, value]) => {
|
|
28
|
+
return [key, value.balance.toDefaultString({ unit: true })]
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
data[key] = { balances: reportBalances }
|
|
33
|
+
return data
|
|
34
|
+
}, {})
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const balancesReportDefinition = {
|
|
39
|
+
id: 'balancesReport',
|
|
40
|
+
type: 'report',
|
|
41
|
+
factory: createBalancesReport,
|
|
42
|
+
dependencies: ['enabledWalletAccountsAtom', 'balancesAtom'],
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default balancesReportDefinition
|