@exodus/ethereum-api 0.2.4 → 0.2.6
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/package.json +3 -2
- package/src/with-fallback.js +11 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Ethereum Api",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Exodus Movement, Inc.",
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@exodus/ethereum-lib": "^0.2.4",
|
|
14
14
|
"fetchival": "0.3.3",
|
|
15
|
+
"lodash": "^4.17.11",
|
|
15
16
|
"make-concurrent": "4.0.0",
|
|
16
17
|
"ms": "^2.1.1",
|
|
17
18
|
"url": "0.10.3",
|
|
18
19
|
"url-join": "4.0.0",
|
|
19
20
|
"ws": "6.1.0"
|
|
20
21
|
},
|
|
21
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "cb562d91bae2c526403fb66ab8b05127a8f1d673"
|
|
22
23
|
}
|
package/src/with-fallback.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { get } from 'lodash'
|
|
1
2
|
import { _isEthereumToken } from '@exodus/ethereum-lib'
|
|
2
3
|
import { eth as ethServer, etc as etcServer } from './exodus-eth-server'
|
|
3
4
|
import * as etherscan from './etherscan'
|
|
@@ -17,6 +18,13 @@ export function withFallback(fn, fn2) {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
export async function isContract(assetName, address) {
|
|
22
|
+
const server =
|
|
23
|
+
assetName === 'ethereumclassic' ? etcServer : withFallback(ethServer.getCode, etherscan.getCode)
|
|
24
|
+
const code = await server.getCode(address)
|
|
25
|
+
return code.length > 2
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
export async function getNonce({ asset, address }) {
|
|
21
29
|
if (!['ethereum', 'ethereumclassic'].includes(asset.name)) return
|
|
22
30
|
|
|
@@ -39,12 +47,12 @@ export async function estimateGas({ asset, ...args }) {
|
|
|
39
47
|
export async function getBalance({ asset, address }) {
|
|
40
48
|
const fetchEthereumBalance = withFallback(async (address) => {
|
|
41
49
|
const balances = await ethServer.getBalance(address)
|
|
42
|
-
return balances
|
|
50
|
+
return get(balances, 'confirmed.value', '0')
|
|
43
51
|
}, etherscan.fetchBalance)
|
|
44
52
|
|
|
45
53
|
const fetchEthereumClassicBalance = async (address) => {
|
|
46
54
|
const balances = await etcServer.getBalance(address)
|
|
47
|
-
return balances
|
|
55
|
+
return get(balances, 'confirmed.value', '0')
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
return (asset.name === 'ethereum' ? fetchEthereumBalance : fetchEthereumClassicBalance)(address)
|
|
@@ -56,7 +64,7 @@ export async function getTokenBalance({ asset, address }) {
|
|
|
56
64
|
|
|
57
65
|
return withFallback(async (contractAddress, address) => {
|
|
58
66
|
const balances = await ethServer.getBalance(address)
|
|
59
|
-
return balances
|
|
67
|
+
return get(balances, ['confirmed', contractAddress], '0')
|
|
60
68
|
}, etherscan.tokenBalance)(contractAddress, address)
|
|
61
69
|
}
|
|
62
70
|
|