Skip to content

Commit

Permalink
Merge pull request #75 from matteodanelli/graph-and-polkadot
Browse files Browse the repository at this point in the history
Added the graph and polkadot. Set coloredLogo to true by default
  • Loading branch information
matteodanelli authored Feb 7, 2021
2 parents 1cced52 + 05c2d35 commit 2a9aaf7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
44 changes: 23 additions & 21 deletions MMM-cryptocurrency.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Module.register('MMM-cryptocurrency', {
significantDigits: undefined,
minimumFractionDigits: 2,
maximumFractionDigits: 5,
coloredLogos: false,
coloredLogos: true,
fontSize: 'xx-large',
limit: '100'
},
Expand Down Expand Up @@ -95,6 +95,7 @@ Module.register('MMM-cryptocurrency', {
reddcoin: 118,
'request-network': 2071,
xrp: 52,
'polkadot-new': 6636,
salt: 1996,
siacoin: 1042,
'sirin-labs-token': 2313,
Expand All @@ -108,6 +109,7 @@ Module.register('MMM-cryptocurrency', {
tenx: 1758,
tether: 825,
tezos: 2011,
'the-graph': 6719,
'time-new-bank': 2235,
tron: 1958,
vechain: 1904,
Expand Down Expand Up @@ -207,9 +209,9 @@ Module.register('MMM-cryptocurrency', {
for (var j = 0; j < tdValues.length; j++) {
var tdWrapper = document.createElement('td')
var currValue = tdValues[j]
// If I am showing value then set color
// If I am showing value then set color
if (currValue.includes('%')) {
tdWrapper.style.color = this.colorizeChange(currValue.slice(0,-1))
tdWrapper.style.color = this.colorizeChange(currValue.slice(0, -1))
}
tdWrapper.innerHTML = currValue
trWrapper.appendChild(tdWrapper)
Expand Down Expand Up @@ -261,10 +263,10 @@ Module.register('MMM-cryptocurrency', {
var rightCurrencyFormat = this.config.conversion.toUpperCase()

var options = {
style: 'currency',
currency: this.config.conversion
}
// TODO: iterate through all quotes and process properly
style: 'currency',
currency: this.config.conversion
}
// TODO: iterate through all quotes and process properly
apiResult['price'] = this.numberToLocale(apiResult['quote'][rightCurrencyFormat]['price'], options)

return apiResult
Expand Down Expand Up @@ -302,19 +304,19 @@ Module.register('MMM-cryptocurrency', {
numberToLocale: function(number, options, language) {
// Parse our entries for significantDigits / minimumFractionDigits / maximumFractionDigits
// Logic for all 3 is the same
if(options == undefined) {
if (options == undefined) {
options = {}
}

if(language == undefined) {
if (language == undefined) {
language = this.config.language
}

var significantDigits = undefined
if(!Array.isArray(this.config.significantDigits)){
if (!Array.isArray(this.config.significantDigits)) {
// Not an array, so take value as written
significantDigits = this.config.significantDigits
} else if(this.config.significantDigits.length < this.config.currency.length){
} else if (this.config.significantDigits.length < this.config.currency.length) {
// Array isn't long enough, so take first entry
significantDigits = this.config.significantDigits[0]
} else {
Expand All @@ -323,36 +325,36 @@ Module.register('MMM-cryptocurrency', {
}

var minimumFractionDigits = undefined
if(!Array.isArray(this.config.minimumFractionDigits)){
if (!Array.isArray(this.config.minimumFractionDigits)) {
minimumFractionDigits = this.config.minimumFractionDigits
} else if(this.config.minimumFractionDigits.length < this.config.currency.length){
} else if (this.config.minimumFractionDigits.length < this.config.currency.length) {
minimumFractionDigits = this.config.minimumFractionDigits[0]
} else {
minimumFractionDigits = this.config.minimumFractionDigits[i]
}

var maximumFractionDigits = undefined
if(!Array.isArray(this.config.maximumFractionDigits)){
if (!Array.isArray(this.config.maximumFractionDigits)) {
maximumFractionDigits = this.config.maximumFractionDigits
} else if(this.config.maximumFractionDigits.length < this.config.currency.length){
} else if (this.config.maximumFractionDigits.length < this.config.currency.length) {
maximumFractionDigits = this.config.maximumFractionDigits[0]
} else {
maximumFractionDigits = this.config.maximumFractionDigits[i]
}

if(significantDigits != undefined) {
if (significantDigits != undefined) {
options['maximumSignificantDigits'] = significantDigits
}

if(maximumFractionDigits != undefined) {
if (maximumFractionDigits != undefined) {
options['maximumFractionDigits'] = maximumFractionDigits
}

if(minimumFractionDigits != undefined) {
if (minimumFractionDigits != undefined) {
options['minimumFractionDigits'] = minimumFractionDigits
}

return parseFloat(number).toLocaleString(language,options)
return parseFloat(number).toLocaleString(language, options)
},

/**
Expand Down Expand Up @@ -478,7 +480,7 @@ Module.register('MMM-cryptocurrency', {
imageExists: function(currencyName) {
var imgPath = '/MMM-cryptocurrency/' + this.folder + currencyName + '.png'
var http = new XMLHttpRequest()
http.open('HEAD', imgPath, false)
http.open('HEAD', imgPath)
http.send()
return http.status != 404
},
Expand Down Expand Up @@ -507,4 +509,4 @@ Module.register('MMM-cryptocurrency', {
}
},

})
})
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A <a href="https://github.com/MichMich/MagicMirror">MagicMirror</a> module used
|`minimumFractionDigits`|Minimum number of digits after the decimal point in the price.<br> **Type** `number` <br> **Default** <i>2</i> |
|`maximumFractionDigits`|Maximum number of digits after the decimal point in the price.<br> **Type** `number` <br> **Default** <i>5</i> |
|`showGraphs`| Possibility to show currency graph over the last week in `displayType: logo`. <br> **Type:** `boolean` <br> **Default** <i>false</i> |
|`coloredLogos`| Toggles white or colored logos `displayType: logo`. <br> **Type:** `boolean` <br> **Default** <i>false</i> |
|`coloredLogos`| Toggles white or colored logos `displayType: logo`. <br> **Type:** `boolean` <br> **Default** <i>true</i> |
|`fontSize`| Dimension of price text. You can specify pixel values, em values or keywords.<br> **Type:** `string` <br>**Options:** `xx-small`, `x-small`, `small`, `medium`, `large`, `x-large`, `xx-large` <br> **Default** <i>xx-large</i> |
|`limit`| Number of currencies to download, according to CoinMarketCap ranking. Increase this value only if you cannot display a currency. <br> **Type:** `string` <br> **Default** <i>100</i> |

Expand Down Expand Up @@ -81,6 +81,8 @@ Logo provided only for the following currencies:
- Neo
- Stellar
- Tron
- The graph
- Polkadot

Feel free to ask for support of your favorite currency. Else, just implement it (eg: to add Litecoin logo):
- Add `'litecoin'` to the currency module config
Expand Down Expand Up @@ -109,7 +111,7 @@ It's my first module here after that I built a MagicMirror. I'm so proud of it a
The MIT License (MIT)
=====================

Copyright © 2017 Matteo Danelli
Copyright © 2021 Matteo Danelli

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
Binary file added public/black-white/polkadot-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/black-white/the-graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/colored/polkadot-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/colored/the-graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2a9aaf7

Please sign in to comment.