mlbonniec / MMM-Coinbase

A module for Michael Teeuw's MagicMirror project that displays your crypto-currencies Coinbase balance.

Home Page:https://magicmirror.builders/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

coinbase0 USD showing even when individual crypto reporting

OliverWasson opened this issue · comments

Hello, after I put in the API keys, the coin amounts work flawlessly, with each coin showing the bought amount. However, the header "Coinbase" with the wallet in USD does not work, showing "Coinbase0 USD". Both keys are in the config, as the individual coins work. Maybe the API updated?

I hope you can fix it :)

Same problem here. The coin balance works fine but the total Coinbase value shows only "0"

Maybe this has something to do with it?

start: function() {
                this.icons = {
                        "BTC": "bitcoin",
                        "ETH": "ethereum"
                };
                this.balance = 0;
                this.currency = "";
                this.cryptoData = [];
        },

especially the "part" this.balance = 0;

I am not sure exactly, I had to reinstall the mirror but I ran into the same issue.

I do it like this now:

In the MMM-Coinbase.js change the following line

columnAmountElement.innerHTML = "<span>" + accts.balance.amount + "</span>";


to

columnAmountElement.innerHTML = "<span>" + accts.native_balance.amount + " " + accts.native_balance.currency + "</span>";


At least you have a slight indication of your Portfolio Balance, but then again it is all messed up and you still litteraly need to check your coins yourself on any client device.

I hope they fix this, it is bad like this, I really like the simplicity of MMM-Coinbase.

Keep up the good work folks!

Hello

Maybe the API updated?

Probably, this project use the old and deprecated official coinbase node lib.

Maybe this has something to do with it?
start: function() {
> this.icons = {
> "BTC": "bitcoin",
> "ETH": "ethereum"
> };
> this.balance = 0;
> this.currency = "";
> this.cryptoData = [];
> },
especially the "part" this.balance = 0;

I am not sure exactly, I had to reinstall the mirror but I ran into the same issue.

No it set a default value to balance but is set by

module.balance += parseInt(accts.native_balance.amount);

I do it like this now:

In the MMM-Coinbase.js change the following line

columnAmountElement.innerHTML = "<span>" + accts.balance.amount + "</span>";

to

columnAmountElement.innerHTML = "<span>" + accts.native_balance.amount + " " + accts.native_balance.currency + "</span>";

I will ask in #19 if it can be made 'cause it's a really small view change

Hi,
is there any way to solve this error?
Screenshot_13

This can be fixed rather easily. It has something to do with the balance being set to 0 after the dom is updated.

Change the following:

const module = this; const config = this.config; const icons = this.icons; this.balance = 0; //ADD THIS this.cryptoData.forEach((accts) => {

socketNotificationReceived: function(notification, payload) { switch(notification) { case "ACCOUNTS": this.cryptoData = payload; this.currency = payload[0].native_balance.currency; this.updateDom(); this.balance = 0; //REMOVE THIS break; } },

},

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.balance = 0;
	
	
	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;
	}
},

});

This is the code that works in my particular case. Thanks The GreatCodeHolio for helping us out! U R THE MAN!

In my case, to solve this issue I removed the lines:

const module = this;

module.balance += parseInt(accts.native_balance.amount);

and added:
this.balance = parseFloat(payload[0].native_balance.amount) + parseFloat(payload[1].native_balance.amount);

in my case having only 2 cryptos my array index go from 0 to 1, but if you have more you have to go from 0 to how much cryptos you have