forked from dfinity/portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto-price.js
32 lines (29 loc) · 903 Bytes
/
crypto-price.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
const fetch = require("node-fetch-retry");
let cache;
/** @type {import('@docusaurus/types').PluginModule} */
const icpPricePlugin = async function (context, options) {
return {
name: "crypto-price",
async loadContent() {
if (!cache) {
const tickers = await Promise.all([
fetch("https://api.coinbase.com/v2/prices/ICP-USD/buy", {
retry: 10,
pause: 500,
}).then((res) => res.json()),
fetch("https://api.coinbase.com/v2/prices/BTC-USD/buy", {
retry: 10,
pause: 500,
}).then((res) => res.json()),
]);
cache = { icp: +tickers[0].data.amount, btc: +tickers[1].data.amount };
}
return cache;
},
async contentLoaded({ content, actions }) {
const { setGlobalData } = actions;
setGlobalData(content);
},
};
};
module.exports = icpPricePlugin;