Skip to content

Commit e5d3d1d

Browse files
committed
feat(contract): Merge master
2 parents 725cb7e + afab3e3 commit e5d3d1d

File tree

10 files changed

+2277
-4558
lines changed

10 files changed

+2277
-4558
lines changed

dist/web3data.min.js

Lines changed: 7 additions & 4046 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web3data.min.js.map

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api.md

Lines changed: 278 additions & 278 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 123 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@
6060
"rimraf": "^3.0.0",
6161
"rollup": "^1.26.0",
6262
"rollup-plugin-commonjs": "^10.1.0",
63+
"rollup-plugin-filesize": "^6.2.1",
6364
"rollup-plugin-json": "^4.0.0",
6465
"rollup-plugin-node-builtins": "^2.1.2",
6566
"rollup-plugin-node-globals": "^1.4.0",
6667
"rollup-plugin-node-resolve": "^5.2.0",
67-
"rollup-plugin-filesize": "^6.2.1",
68+
"rollup-plugin-terser": "^5.1.2",
6869
"superstatic": "^6.0.4",
6970
"xo": "^0.24.0"
7071
},

rollup.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import json from 'rollup-plugin-json'
44
import builtins from 'rollup-plugin-node-builtins'
55
import globals from 'rollup-plugin-node-globals'
66
import filesize from 'rollup-plugin-filesize'
7+
import {terser} from 'rollup-plugin-terser'
78

89
// eslint-disable-next-line import/extensions
910
import pkg from './package.json'
@@ -13,6 +14,7 @@ export default {
1314
output: {
1415
name: 'web3data',
1516
file: pkg.browser,
17+
compact: true,
1618
format: 'umd',
1719
globals: {
1820
crypto: 'crypto'
@@ -29,6 +31,7 @@ export default {
2931
json(),
3032
builtins({crypto: false, https: false}),
3133
globals(),
32-
filesize()
34+
filesize(),
35+
terser()
3336
]
3437
}

src/transaction.js

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,84 +3,74 @@ const {
33
ERROR_MESSAGE_TRANSACTION_NO_HASH: NO_HASH
44
} = require('./constants')
55

6-
const {is, get, onFulfilled, onError} = require('./utils')
6+
const {
7+
is,
8+
get,
9+
onFulfilled,
10+
onError,
11+
throwIf,
12+
recordsFormatter
13+
} = require('./utils')
714

815
class Transaction {
916
constructor(web3data) {
1017
this.web3data = web3data
1118
}
1219

13-
async getTransactions(filterOptions) {
14-
const response = await get(this.web3data, {
20+
getTransactions(filterOptions) {
21+
return get(this.web3data, {
1522
endpoint: ENDPOINT,
1623
filterOptions
17-
})
18-
return new Promise((resolve, reject) => {
19-
if (
20-
!response ||
21-
response.status !== 200 ||
22-
!response.payload ||
23-
!response.payload.records
24-
) {
25-
reject(new Error('Failed to retrieve transactions.'))
26-
} else {
27-
resolve(response.payload.records)
28-
}
29-
})
24+
}).then(onFulfilled.bind({formatter: recordsFormatter}), onError)
3025
}
3126

32-
async getTransaction(hash, filterOptions) {
33-
if (!hash) return Promise.reject(new Error(NO_HASH))
34-
const response = await get(this.web3data, {
27+
getTransaction(hash, filterOptions) {
28+
throwIf(is.notHash(hash), NO_HASH)
29+
return get(this.web3data, {
3530
pathParam: hash,
3631
endpoint: ENDPOINT,
3732
filterOptions
38-
})
39-
return new Promise((resolve, reject) => {
40-
if (!response || response.status !== 200 || !response.payload) {
41-
reject(new Error('Failed to retrieve transaction.'))
42-
} else {
43-
resolve(response.payload)
44-
}
45-
})
33+
}).then(onFulfilled, onError)
4634
}
4735

48-
async getPendingTransactions() {
49-
const pendingTransactions = await this.getTransactions({status: 'pending'})
50-
return new Promise((resolve, reject) => {
51-
if (is.undefined(pendingTransactions) || is.null(pendingTransactions)) {
52-
reject(new Error('Failed to retrieve pending transactions.'))
53-
} else {
54-
resolve(pendingTransactions)
55-
}
56-
})
36+
getPendingTransactions() {
37+
return this.getTransactions({status: 'pending'}).then(
38+
pendingTransactions => {
39+
throwIf(
40+
is.undefined(pendingTransactions) || is.null(pendingTransactions),
41+
'Failed to retrieve pending transactions.'
42+
)
43+
return pendingTransactions
44+
},
45+
console.error
46+
)
5747
}
5848

5949
getGasPrediction() {
6050
return get(this.web3data, {
6151
endpoint: ENDPOINT,
6252
subendpoint: 'gas/predictions'
63-
})
53+
}).then(onFulfilled, onError)
54+
}
55+
56+
getGasPercentiles(filterOptions) {
57+
return get(this.web3data, {
58+
endpoint: ENDPOINT,
59+
subendpoint: 'gas/percentiles',
60+
filterOptions
61+
}).then(onFulfilled, onError)
6462
}
6563

66-
async getGasPrice() {
67-
const response = await this.getGasPrediction()
68-
return new Promise((resolve, reject) => {
69-
if (
70-
is.null(response) ||
71-
is.undefined(response) ||
72-
response.status !== 200
73-
) {
74-
reject(new Error('Failed to retrieve gas price.'))
75-
} else if (!response.payload || !response.payload.average) {
76-
reject(new Error('Failed to retrieve gas price.'))
77-
} else {
78-
resolve(`${response.payload.average.gasPrice}`)
79-
}
64+
getGasPrice() {
65+
return this.getGasPrediction().then(gasPrediction => {
66+
throwIf(
67+
!gasPrediction.average || !gasPrediction.average.gasPrice,
68+
'Failed to retrieve gas price.'
69+
)
70+
return `${gasPrediction.average.gasPrice}`
8071
})
8172
}
8273

83-
// TODO: Needs tests
8474
getVolume(filterOptions) {
8575
return get(this.web3data, {
8676
endpoint: ENDPOINT,
@@ -89,7 +79,6 @@ class Transaction {
8979
}).then(onFulfilled, onError)
9080
}
9181

92-
// TODO: Needs tests
9382
getMetrics(filterOptions) {
9483
return get(this.web3data, {
9584
endpoint: ENDPOINT,

0 commit comments

Comments
 (0)