-
Notifications
You must be signed in to change notification settings - Fork 1
/
constants.js
68 lines (58 loc) · 1.75 KB
/
constants.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require('fs');
const path = require('path');
let blobCache = {};
module.exports = Object.freeze({
formatCurrency: (n, p) => {
p = typeof p === 'number' ? p : 2;
return n.toLocaleString('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: p,
maximumFractionDigits: p
})
},
calcPercentage: (oldValue, newValue) => {
const d = oldValue > newValue;
const n = d ? (oldValue - newValue) : (newValue - oldValue);
return {
p: n / oldValue,
d: oldValue > newValue
}
},
getImgSrc: (iconPath) => {
if(blobCache[iconPath])
return blobCache[iconPath];
// incase the file does not exist
try {
let newPath = path.join(__dirname, iconPath);
let blob = Uint8Array.from(fs.readFileSync(newPath));
blob = URL.createObjectURL(new Blob([blob], { type: 'image/png' }));
blobCache[iconPath] = blob;
return blob;
} catch {
return "";
}
},
FluxActions: {
UPDATE_CRYPTO_LOADING: 'CRYPTO_UPDATE_CRYPTO_LOADING',
UPDATE_CRYPTO_PRICE: 'CRYPTO_UPDATE_CRYPTO_PRICE',
SELECT_CRYPTO_SPAN: 'CRYPTO_SELECT_CRYPTO_SPAN',
SELECT_CRYPTO: 'CRYPTO_SELECT_CRYPTO'
},
CRYPTO_DEBUG: false,
CRYPTO_CHANNELS: Object.freeze({
"BTC-USD": {
icon: "icons/Bitcoin.png",
name: "Bitcoin"
},
"ETH-USD": {
icon: "icons/Ethereum.png",
name: "Ether",
},
"XRP-USD": {
icon: "icons/Ripple.png",
name:"Ripple",
precision: 4
}
}),
});