-
Notifications
You must be signed in to change notification settings - Fork 22
/
chainik.js
33 lines (31 loc) · 1.03 KB
/
chainik.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
import axios from 'axios';
import {cacheAdapterEnhancer, Cache} from 'axios-extensions';
import {CHAINIK_API_URL, NETWORK, MAINNET} from "~/assets/variables.js";
import addToCamelInterceptor from '~/assets/axios-to-camel.js';
import {getDefaultAdapter} from '~/assets/axios-default-adapter.js';
const instance = axios.create({
baseURL: CHAINIK_API_URL,
adapter: cacheAdapterEnhancer(getDefaultAdapter(), { enabledByDefault: false}),
});
addToCamelInterceptor(instance);
// 10 min cache
const coinsCache = new Cache({ttl: 10 * 60 * 1000, max: 100});
/**
* @return {Promise<Object.<number, string|null>>}
*/
export function getCoinIconList() {
if (NETWORK !== MAINNET) {
return Promise.resolve({});
}
return instance.get('coins.json', {
cache: coinsCache,
})
.then((response) => {
const coins = response.data;
let iconMap = {};
coins.forEach((coin) => {
iconMap[coin.id] = coin.icon;
});
return iconMap;
});
}