@exodus/ethereum-api 8.4.2 → 8.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 CHANGED
@@ -3,6 +3,15 @@
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.5.0](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.4.2...@exodus/ethereum-api@8.5.0) (2024-06-17)
7
+
8
+
9
+ ### Features
10
+
11
+ * balance-utils for getBalances ([#2585](https://github.com/ExodusMovement/assets/issues/2585)) ([ee1aaa6](https://github.com/ExodusMovement/assets/commit/ee1aaa6c669bfdbbc6f3053167b678b98b5ef70d))
12
+
13
+
14
+
6
15
  ## [8.4.2](https://github.com/ExodusMovement/assets/compare/@exodus/ethereum-api@8.4.1...@exodus/ethereum-api@8.4.2) (2024-06-14)
7
16
 
8
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "8.4.2",
3
+ "version": "8.5.0",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -20,7 +20,7 @@
20
20
  "lint:fix": "yarn lint --fix"
21
21
  },
22
22
  "dependencies": {
23
- "@exodus/asset-lib": "^4.1.0",
23
+ "@exodus/asset-lib": "^4.2.0",
24
24
  "@exodus/assets": "^9.1.1",
25
25
  "@exodus/basic-utils": "^2.1.0",
26
26
  "@exodus/bip44-constants": "^195.0.0",
@@ -66,5 +66,5 @@
66
66
  "type": "git",
67
67
  "url": "git+https://github.com/ExodusMovement/assets.git"
68
68
  },
69
- "gitHead": "af504da8c4e9f5105c30b97b3e08e4e96f1e8fd4"
69
+ "gitHead": "7f584775d566248fa9633086baee1064edbe8ef0"
70
70
  }
@@ -1,19 +1,12 @@
1
1
  import { isRpcBalanceAsset } from '@exodus/ethereum-lib'
2
2
 
3
3
  import { get } from 'lodash'
4
-
5
- const getBalanceFromAccountState = ({ asset, accountState }) => {
6
- const isBase = asset.name === asset.baseAsset.name
7
- return get(
8
- accountState,
9
- isBase ? ['balance'] : ['tokenBalances', asset.name],
10
- asset.currency.ZERO
11
- )
12
- }
13
-
14
- const getBalanceFromTxLog = ({ txLog, asset }) => {
15
- return txLog.size > 0 ? txLog.getMutations().slice(-1)[0].balance : asset.currency.ZERO
16
- }
4
+ import {
5
+ getBalanceFromAccountState,
6
+ getBalanceFromTxLog,
7
+ getUnconfirmedReceivedBalance,
8
+ getUnconfirmedSentBalance,
9
+ } from '@exodus/asset-lib'
17
10
 
18
11
  const getStaked = ({ accountState, asset }) => {
19
12
  return get(accountState, ['staking', asset.name, 'delegatedBalance']) || asset.currency.ZERO
@@ -29,35 +22,6 @@ const getUnstaked = ({ accountState, asset }) => {
29
22
  )
30
23
  }
31
24
 
32
- const getUnconfirmedSentBalanceFromTxLog = ({ asset, txLog }) => {
33
- let result = asset.currency.ZERO
34
-
35
- for (const tx of txLog) {
36
- const isUnconfirmed = !tx.failed && tx.pending
37
-
38
- if (isUnconfirmed && tx.sent) {
39
- result = result.add(tx.coinAmount.abs())
40
- if (tx.feeAmount && tx.coinAmount.unitType.equals(tx.feeAmount.unitType)) {
41
- result = result.add(tx.feeAmount.abs())
42
- }
43
- }
44
- }
45
-
46
- return result
47
- }
48
-
49
- const getUnconfirmedReceivedBalanceFromTxLog = ({ asset, txLog }) => {
50
- let result = asset.currency.ZERO
51
- for (const tx of txLog) {
52
- const isUnconfirmed = !tx.failed && tx.pending
53
- if (isUnconfirmed && !tx.sent) {
54
- result = result.add(tx.coinAmount.abs())
55
- }
56
- }
57
-
58
- return result
59
- }
60
-
61
25
  /**
62
26
  * Api method to return the balance based on either account state balances or tx history.
63
27
  *
@@ -67,8 +31,8 @@ const getUnconfirmedReceivedBalanceFromTxLog = ({ asset, txLog }) => {
67
31
  * @returns {{balance}|null} an object with the balance or null if the balance is unknown
68
32
  */
69
33
  export const getBalances = ({ asset, txLog, accountState }) => {
70
- const unconfirmedReceived = getUnconfirmedReceivedBalanceFromTxLog({ asset, txLog })
71
- const unconfirmedSent = getUnconfirmedSentBalanceFromTxLog({ asset, txLog })
34
+ const unconfirmedReceived = getUnconfirmedReceivedBalance({ asset, txLog })
35
+ const unconfirmedSent = getUnconfirmedSentBalance({ asset, txLog })
72
36
 
73
37
  // balance from txLog / rpc is considered to be total
74
38
  const balanceWithoutUnconfirmedSent = isRpcBalanceAsset(asset)