@exodus/balances 7.2.0 → 8.1.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 +20 -14
- package/package.json +7 -5
- package/plugins/index.js +16 -0
- 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.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@8.0.0...@exodus/balances@8.1.0) (2023-08-11)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- emit balances atom value through port ([#3314](https://github.com/ExodusMovement/exodus-hydra/issues/3314)) ([c394b71](https://github.com/ExodusMovement/exodus-hydra/commit/c394b718c85f5ceb5e1f3788fafd218c624ee83b))
|
|
11
|
+
|
|
12
|
+
## [8.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@7.1.0...@exodus/balances@8.0.0) (2023-08-03)
|
|
13
|
+
|
|
14
|
+
### ⚠ BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
- balances to use txLogsAtom and accountStatesAtom (#2900)
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
- add balances report ([#3059](https://github.com/ExodusMovement/exodus-hydra/issues/3059)) ([a06ae1c](https://github.com/ExodusMovement/exodus-hydra/commit/a06ae1c988fb9abc8899caa0093528495496df1f))
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
- **balances:** include report in package files ([#3130](https://github.com/ExodusMovement/exodus-hydra/issues/3130)) ([b0e515c](https://github.com/ExodusMovement/exodus-hydra/commit/b0e515c7c32d271303b77b82780cdae80540c1f5))
|
|
25
|
+
|
|
26
|
+
### Code Refactoring
|
|
27
|
+
|
|
28
|
+
- balances to use txLogsAtom and accountStatesAtom ([#2900](https://github.com/ExodusMovement/exodus-hydra/issues/2900)) ([7aa3c74](https://github.com/ExodusMovement/exodus-hydra/commit/7aa3c74fd8a646e47f3c326c9c82662d99515814))
|
|
29
|
+
|
|
6
30
|
## [7.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/balances@7.1.0...@exodus/balances@7.2.0) (2023-08-01)
|
|
7
31
|
|
|
8
32
|
### Features
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import balancesDefinition from './module'
|
|
2
2
|
import { balancesAtomDefinition, hasBalanceAtomDefinition } from './atoms'
|
|
3
3
|
import balancesReportDefinition from './report'
|
|
4
|
+
import balancesPluginDefinition from './plugins'
|
|
4
5
|
|
|
5
6
|
const balances = () => {
|
|
6
7
|
return {
|
|
@@ -13,6 +14,7 @@ const balances = () => {
|
|
|
13
14
|
{ definition: balancesAtomDefinition },
|
|
14
15
|
{ definition: hasBalanceAtomDefinition },
|
|
15
16
|
{ definition: balancesReportDefinition },
|
|
17
|
+
{ definition: balancesPluginDefinition },
|
|
16
18
|
],
|
|
17
19
|
}
|
|
18
20
|
}
|
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) => {
|
|
@@ -354,6 +358,8 @@ const balancesDefinition = {
|
|
|
354
358
|
'config',
|
|
355
359
|
'logger',
|
|
356
360
|
'balancesAtom',
|
|
361
|
+
'txLogsAtom',
|
|
362
|
+
'accountStatesAtom',
|
|
357
363
|
],
|
|
358
364
|
}
|
|
359
365
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/balances",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "Tracks crypto balances across enabled wallet accounts.",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"module",
|
|
15
15
|
"atoms",
|
|
16
|
+
"report",
|
|
17
|
+
"plugins",
|
|
16
18
|
"README.md",
|
|
17
19
|
"CHANGELOG.md",
|
|
18
20
|
"!**/__tests__/**"
|
|
@@ -27,19 +29,19 @@
|
|
|
27
29
|
},
|
|
28
30
|
"dependencies": {
|
|
29
31
|
"@exodus/atoms": "^5.4.0",
|
|
30
|
-
"@exodus/basic-utils": "^2.
|
|
32
|
+
"@exodus/basic-utils": "^2.1.0",
|
|
31
33
|
"@exodus/currency": "^2.1.2",
|
|
32
34
|
"@exodus/module": "^1.1.0",
|
|
33
35
|
"lodash": "^4.17.21",
|
|
34
36
|
"make-concurrent": "^4.0.0"
|
|
35
37
|
},
|
|
36
38
|
"peerDependencies": {
|
|
37
|
-
"@exodus/blockchain-metadata": "^
|
|
39
|
+
"@exodus/blockchain-metadata": "^9.0.1"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@exodus/assets": "^8.0.94",
|
|
41
43
|
"@exodus/assets-base": "^8.1.10",
|
|
42
|
-
"@exodus/blockchain-metadata": "^
|
|
44
|
+
"@exodus/blockchain-metadata": "^9.0.1",
|
|
43
45
|
"@exodus/models": "^8.9.0",
|
|
44
46
|
"@exodus/storage-memory": "*",
|
|
45
47
|
"@exodus/wallet-accounts": "^9.1.0",
|
|
@@ -47,5 +49,5 @@
|
|
|
47
49
|
"events": "^3.3.0",
|
|
48
50
|
"jest": "^29.1.2"
|
|
49
51
|
},
|
|
50
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "ae918b2986c31128583b7f3fccd4ff334bb0583a"
|
|
51
53
|
}
|
package/plugins/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const createBalancesPlugin = ({ balancesAtom, port }) => {
|
|
2
|
+
const onUnlock = () => {
|
|
3
|
+
balancesAtom.get().then((value) => port.emit('balancesAtom', value))
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return { onUnlock }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const balancesPluginDefinition = {
|
|
10
|
+
id: 'balancesPlugin',
|
|
11
|
+
type: 'plugin',
|
|
12
|
+
factory: createBalancesPlugin,
|
|
13
|
+
dependencies: ['balancesAtom', 'port'],
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default balancesPluginDefinition
|
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
|