This repository has been archived by the owner on Jul 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMMM-Coinbase.js
103 lines (83 loc) · 2.71 KB
/
MMM-Coinbase.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Module.register("MMM-Coinbase", {
defaults: {
apiKey: "",
apiSecret: "",
wallet: ["BTC"],
icons: true, // currently only Bitcoin and Ethereum supported
label: false
// updateInterval: 1
},
getStyles: function() {
return [this.file("css/styles.css")];
},
start: function() {
this.icons = {
"BTC": "bitcoin",
"ETH": "ethereum"
};
this.balance = 0;
this.currency = "";
this.cryptoData = [];
},
getHeader: function() {
return this.data.header + "<span class='right'>" + this.balance + " " + this.currency + "</span>";
},
getDom: function() {
const elem = document.createElement("div");
elem.id = "accountWrapper";
const module = this;
const config = this.config;
const icons = this.icons;
this.cryptoData.forEach((accts) => {
module.balance += parseInt(accts.native_balance.amount);
// check if currency is in config
if(config.wallet.indexOf(accts.currency) > -1) {
// add div ROW for currency
const rowElement = document.createElement("div");
rowElement.className = "row";
rowElement.id = accts.currency + "Counter";
// Create column for icon if icons have been activated
if (config.icons) {
const columnIconElement = document.createElement("div");
columnIconElement.className = "column icon";
if(icons.hasOwnProperty(accts.currency))
columnIconElement.innerHTML = "<i class='fa fa-" + icons[accts.currency] + "'></i>";
else
columnIconElement.innerHTML = "<span class='currency-name'>" + accts.currency.toUpperCase() + "</span>";
rowElement.appendChild(columnIconElement);
}
if (config.label) {
const columnCurrencyElement = document.createElement("div");
columnCurrencyElement.className = "column";
columnCurrencyElement.innerHTML = "<span>" + accts.currency + "</span>";
rowElement.appendChild(columnCurrencyElement);
}
const columnAmountElement = document.createElement("div");
columnAmountElement.className = "column";
columnAmountElement.innerHTML = "<span>" + accts.balance.amount + "</span>";
rowElement.appendChild(columnAmountElement);
elem.appendChild(rowElement);
}
});
return elem;
},
notificationReceived: function(notification) {
switch(notification) {
case "DOM_OBJECTS_CREATED":
setInterval(() => {
this.sendSocketNotification("GET_ACCOUNTS", {apiKey: this.config.apiKey, apiSecret: this.config.apiSecret, wallet: this.config.wallet});
}, 5000);
break;
}
},
socketNotificationReceived: function(notification, payload) {
switch(notification) {
case "ACCOUNTS":
this.cryptoData = payload;
this.currency = payload[0].native_balance.currency;
this.updateDom();
this.balance = 0;
break;
}
},
});