-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathethersacn.js
43 lines (41 loc) · 1.36 KB
/
ethersacn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import axios from 'axios';
import {ETHERSCAN_API_URL, ETHERSCAN_API_KEY} from "~/assets/variables.js";
import addToCamelInterceptor from '~/assets/axios-to-camel.js';
const instance = axios.create({
baseURL: ETHERSCAN_API_URL,
params: {
apikey: ETHERSCAN_API_KEY,
},
});
addToCamelInterceptor(instance);
/**
* @param {string} address
* @param {{page: number, offset: number}} [options]
* @return {Promise<Array<Object>>}
*/
export function getAddressTransactionList(address, options) {
return instance.get(`?module=account&action=txlist&address=${address}&sort=desc`, {
params: options,
})
.then((response) => {
let seen = {};
return response.data.result
// result may contain duplicates, filter them out
.filter((tx) => {
if (seen[tx.hash]) {
// remove duplicate
return false;
} else {
// save
seen[tx.hash] = true;
// keep
return true;
}
})
.map((tx) => {
// align with web3 getTransactionReceipt
tx.status = !!Number(tx.txreceiptStatus);
return tx;
});
});
}