From 0295f2c7e1bcf6c028c592303ecc68a1e5d114d9 Mon Sep 17 00:00:00 2001 From: Jan Litzenburger Date: Sat, 15 Jul 2023 11:37:46 +0200 Subject: [PATCH] Fixed #55 --- MMM-Jast.js | 4 ++-- node_helper.js | 2 +- package.json | 2 +- src/frontend/JastFrontendUtils.ts | 8 ++++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/MMM-Jast.js b/MMM-Jast.js index 806d960..f1c120b 100644 --- a/MMM-Jast.js +++ b/MMM-Jast.js @@ -1,6 +1,6 @@ /*! ***************************************************************************** mmm-jast - Version 2.8.1 + Version 2.8.2 A minimalistic stock ticker based on Yahoo's finance API for the MagicMirror² platform. Please submit bugs at https://github.com/jalibu/MMM-Jast/issues @@ -11,4 +11,4 @@ This file is auto-generated. Do not edit. ***************************************************************************** */ -!function(e){"use strict";function t(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var r=t(e);class n{static getCurrentValueStyle(e){return{style:e.showCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8}}static getChangeValueStyle(e){return{style:e.showChangeValueCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8}}static getPercentStyle(e){return{style:"percent",useGrouping:e.useGrouping,minimumFractionDigits:e.numberDecimalsPercentages<=8?e.numberDecimalsPercentages:8}}static getNumberOfDisplayedStocks(e,t){return t.showHiddenStocks?e.length:e.filter((e=>!e.meta.hidden)).length}static getStockChange(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChange}static getStockChangePercent(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChangePercent}static getCurrentValue(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketPrice}static getStockChangeAsString(e,t){return n.getStockChange(e).toLocaleString(t.locale,Object.assign(n.getChangeValueStyle(t),{currency:e.price.currency}))}static getStockChangePercentAsString(e,t){return n.getStockChangePercent(e).toLocaleString(t.locale,n.getPercentStyle(t))}static getCurrentValueAsString(e,t){return n.getCurrentValue(e).toLocaleString(t.locale,Object.assign(n.getCurrentValueStyle(t),{currency:e.price.currency}))}static getStockName(e){return e.meta.name||e.price.longName}static getPortfolioValueAsString(e,t){return e.value.toLocaleString(t.locale,Object.assign(n.getCurrentValueStyle(t),{currency:e.currency}))}static getPortfolioChangeAsString(e,t){return(e.value-e.oldValue).toLocaleString(t.locale,Object.assign(n.getCurrentValueStyle(t),{currency:e.currency}))}static getPortfolioChangePercentAsString(e,t){return((e.value-e.oldValue)/e.oldValue).toLocaleString(t.locale,n.getPercentStyle(t))}static getPortfolio(e,t){var n,a,i,c;const o=[];for(const l of e)try{const e=null===(n=t.stocks)||void 0===n?void 0:n.find((e=>{var t;return e.symbol===(null===(t=l.meta)||void 0===t?void 0:t.symbol)}));if(null==e?void 0:e.quantity){const t=(null===(a=l.price)||void 0===a?void 0:a.regularMarketPrice)*e.quantity,r=((null===(i=l.price)||void 0===i?void 0:i.regularMarketPrice)-(null===(c=l.price)||void 0===c?void 0:c.regularMarketChange))*e.quantity,n=o.find((e=>e.currency===l.price.currency));n?(n.value+=t,n.oldValue+=r):o.push({value:t,oldValue:r,currency:l.price.currency})}}catch(e){r.warn("There was a problem calculating the detpot growth",e)}return o}}Module.register("MMM-Jast",{defaults:{currencyStyle:"code",fadeSpeedInSeconds:3.5,lastUpdateFormat:"HH:mm",locale:config.locale||"en-GB",maxChangeAge:864e5,maxWidth:"100%",numberDecimalsPercentages:1,numberDecimalsValues:2,scroll:"vertical",showColors:!0,showCurrency:!0,showChangePercent:!0,showChangeValue:!1,showChangeValueCurrency:!1,showHiddenStocks:!1,showLastUpdate:!1,showPortfolioGrowth:!1,showPortfolioGrowthPercent:!1,showPortfolioValue:!1,updateIntervalInSeconds:600,useGrouping:!1,virtualHorizontalMultiplier:2,stocks:[{name:"BASF",symbol:"BAS.DE",quantity:100},{name:"SAP",symbol:"SAP.DE",quantity:200},{name:"Henkel",symbol:"HEN3.DE"},{name:"AbbVie",symbol:"4AB.DE"},{name:"Bitcoin",symbol:"BTC-EUR"},{name:"Alibaba",symbol:"BABA"}]},getScripts:()=>["moment.js"],getStyles:()=>["MMM-Jast.css"],getTranslations:()=>({en:"translations/en.json",de:"translations/de.json"}),getTemplate:()=>"templates/MMM-Jast.njk",getTemplateData(){var e,t;return{config:this.config,stocks:null===(e=this.state)||void 0===e?void 0:e.stocks,lastUpdate:moment(null===(t=this.state)||void 0===t?void 0:t.lastUpdate).format(this.config.lastUpdateFormat),utils:n}},start(){this.loadData(),this.scheduleUpdate(),this.updateDom()},scheduleUpdate(){this.config.updateIntervalInSeconds=this.config.updateIntervalInSeconds<120?120:this.config.updateIntervalInSeconds,setInterval((()=>{this.loadData()}),1e3*this.config.updateIntervalInSeconds)},loadData(){this.sendSocketNotification(`JAST_STOCKS_REQUEST-${this.identifier}`,this.config)},socketNotificationReceived(e,t){e===`JAST_STOCKS_RESPONSE-${this.identifier}`&&(this.state=t,r.log("JAST_STOCKS_RESPONSE",this.state),this.updateDom())}})}(Log); +!function(e){"use strict";function t(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var r=t(e);class a{static getCurrentValueStyle(e){return{style:e.showCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8,maximumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8}}static getChangeValueStyle(e){return{style:e.showChangeValueCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8,maximumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8}}static getPercentStyle(e){return{style:"percent",useGrouping:e.useGrouping,minimumFractionDigits:e.numberDecimalsPercentages<=8?e.numberDecimalsPercentages:8}}static getNumberOfDisplayedStocks(e,t){return t.showHiddenStocks?e.length:e.filter((e=>!e.meta.hidden)).length}static getStockChange(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChange}static getStockChangePercent(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChangePercent}static getCurrentValue(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketPrice}static getStockChangeAsString(e,t){return console.log("Style",a.getChangeValueStyle(t)),a.getStockChange(e).toLocaleString(t.locale,Object.assign(a.getChangeValueStyle(t),{currency:e.price.currency}))}static getStockChangePercentAsString(e,t){return a.getStockChangePercent(e).toLocaleString(t.locale,a.getPercentStyle(t))}static getCurrentValueAsString(e,t){return a.getCurrentValue(e).toLocaleString(t.locale,Object.assign(a.getCurrentValueStyle(t),{currency:e.price.currency}))}static getStockName(e){return e.meta.name||e.price.longName}static getPortfolioValueAsString(e,t){return e.value.toLocaleString(t.locale,Object.assign(a.getCurrentValueStyle(t),{currency:e.currency}))}static getPortfolioChangeAsString(e,t){return(e.value-e.oldValue).toLocaleString(t.locale,Object.assign(a.getCurrentValueStyle(t),{currency:e.currency}))}static getPortfolioChangePercentAsString(e,t){return((e.value-e.oldValue)/e.oldValue).toLocaleString(t.locale,a.getPercentStyle(t))}static getPortfolio(e,t){var a,n,i,l;const c=[];for(const o of e)try{const e=null===(a=t.stocks)||void 0===a?void 0:a.find((e=>{var t;return e.symbol===(null===(t=o.meta)||void 0===t?void 0:t.symbol)}));if(null==e?void 0:e.quantity){const t=(null===(n=o.price)||void 0===n?void 0:n.regularMarketPrice)*e.quantity,r=((null===(i=o.price)||void 0===i?void 0:i.regularMarketPrice)-(null===(l=o.price)||void 0===l?void 0:l.regularMarketChange))*e.quantity,a=c.find((e=>e.currency===o.price.currency));a?(a.value+=t,a.oldValue+=r):c.push({value:t,oldValue:r,currency:o.price.currency})}}catch(e){r.warn("There was a problem calculating the detpot growth",e)}return c}}Module.register("MMM-Jast",{defaults:{currencyStyle:"code",fadeSpeedInSeconds:3.5,lastUpdateFormat:"HH:mm",locale:config.locale||"en-GB",maxChangeAge:864e5,maxWidth:"100%",numberDecimalsPercentages:1,numberDecimalsValues:2,scroll:"vertical",showColors:!0,showCurrency:!0,showChangePercent:!0,showChangeValue:!1,showChangeValueCurrency:!1,showHiddenStocks:!1,showLastUpdate:!1,showPortfolioGrowth:!1,showPortfolioGrowthPercent:!1,showPortfolioValue:!1,updateIntervalInSeconds:600,useGrouping:!1,virtualHorizontalMultiplier:2,stocks:[{name:"BASF",symbol:"BAS.DE",quantity:100},{name:"SAP",symbol:"SAP.DE",quantity:200},{name:"Henkel",symbol:"HEN3.DE"},{name:"AbbVie",symbol:"4AB.DE"},{name:"Bitcoin",symbol:"BTC-EUR"},{name:"Alibaba",symbol:"BABA"}]},getScripts:()=>["moment.js"],getStyles:()=>["MMM-Jast.css"],getTranslations:()=>({en:"translations/en.json",de:"translations/de.json"}),getTemplate:()=>"templates/MMM-Jast.njk",getTemplateData(){var e,t;return{config:this.config,stocks:null===(e=this.state)||void 0===e?void 0:e.stocks,lastUpdate:moment(null===(t=this.state)||void 0===t?void 0:t.lastUpdate).format(this.config.lastUpdateFormat),utils:a}},start(){this.loadData(),this.scheduleUpdate(),this.updateDom()},scheduleUpdate(){this.config.updateIntervalInSeconds=this.config.updateIntervalInSeconds<120?120:this.config.updateIntervalInSeconds,setInterval((()=>{this.loadData()}),1e3*this.config.updateIntervalInSeconds)},loadData(){this.sendSocketNotification(`JAST_STOCKS_REQUEST-${this.identifier}`,this.config)},socketNotificationReceived(e,t){e===`JAST_STOCKS_RESPONSE-${this.identifier}`&&(this.state=t,r.log("JAST_STOCKS_RESPONSE",this.state),this.updateDom())}})}(Log); diff --git a/node_helper.js b/node_helper.js index 88145ef..6983db9 100644 --- a/node_helper.js +++ b/node_helper.js @@ -1,6 +1,6 @@ /*! ***************************************************************************** mmm-jast - Version 2.8.1 + Version 2.8.2 A minimalistic stock ticker based on Yahoo's finance API for the MagicMirror² platform. Please submit bugs at https://github.com/jalibu/MMM-Jast/issues diff --git a/package.json b/package.json index 4984d43..7fdee84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mmm-jast", - "version": "2.8.1", + "version": "2.8.2", "description": "A minimalistic stock ticker based on Yahoo's finance API for the MagicMirror² platform.", "main": "MMM-Jast.js", "repository": { diff --git a/src/frontend/JastFrontendUtils.ts b/src/frontend/JastFrontendUtils.ts index 9b3ab7c..0dc837e 100644 --- a/src/frontend/JastFrontendUtils.ts +++ b/src/frontend/JastFrontendUtils.ts @@ -9,6 +9,7 @@ type CurrencyStyle = { currency?: string currencyDisplay: string minimumFractionDigits: number + maximumFractionDigits: number } type PercentStyle = { @@ -23,7 +24,8 @@ export default class JastUtils { style: config.showCurrency ? 'currency' : 'decimal', useGrouping: config.useGrouping, currencyDisplay: config.currencyStyle, - minimumFractionDigits: config.numberDecimalsValues <= 8 ? config.numberDecimalsValues : 8 + minimumFractionDigits: config.numberDecimalsValues <= 8 ? config.numberDecimalsValues : 8, + maximumFractionDigits: config.numberDecimalsValues <= 8 ? config.numberDecimalsValues : 8 } } @@ -32,7 +34,8 @@ export default class JastUtils { style: config.showChangeValueCurrency ? 'currency' : 'decimal', useGrouping: config.useGrouping, currencyDisplay: config.currencyStyle, - minimumFractionDigits: config.numberDecimalsValues <= 8 ? config.numberDecimalsValues : 8 + minimumFractionDigits: config.numberDecimalsValues <= 8 ? config.numberDecimalsValues : 8, + maximumFractionDigits: config.numberDecimalsValues <= 8 ? config.numberDecimalsValues : 8 } } @@ -61,6 +64,7 @@ export default class JastUtils { } static getStockChangeAsString(stock: StockResponse, config: Config): string { + console.log("Style", JastUtils.getChangeValueStyle(config)) return JastUtils.getStockChange(stock).toLocaleString( config.locale, Object.assign(JastUtils.getChangeValueStyle(config), {