From 76145a54a5e11baf6f5797b5d8840ab8c49d4737 Mon Sep 17 00:00:00 2001 From: Max Alekseenko Date: Mon, 2 Dec 2019 14:26:08 +0300 Subject: [PATCH] add setDataToLocalStorage function --- .../block_scout_web/assets/js/lib/market_history_chart.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/block_scout_web/assets/js/lib/market_history_chart.js b/apps/block_scout_web/assets/js/lib/market_history_chart.js index 9d7c4a112e..1ca4137c57 100644 --- a/apps/block_scout_web/assets/js/lib/market_history_chart.js +++ b/apps/block_scout_web/assets/js/lib/market_history_chart.js @@ -80,12 +80,16 @@ function getDataFromLocalStorage (key) { return data ? JSON.parse(data) : [] } +function setDataToLocalStorage (key, data) { + window.localStorage.setItem(key, JSON.stringify(data)) +} + function getPriceData (marketHistoryData) { if (marketHistoryData.length === 0) { return getDataFromLocalStorage('priceData') } const data = marketHistoryData.map(({ date, closingPrice }) => ({ x: date, y: closingPrice })) - window.localStorage.setItem('priceData', JSON.stringify(data)) + setDataToLocalStorage('priceData', data) return data } @@ -99,7 +103,7 @@ function getMarketCapData (marketHistoryData, availableSupply) { : availableSupply return { x: date, y: closingPrice * supply } }) - window.localStorage.setItem('marketCapData', JSON.stringify(data)) + setDataToLocalStorage('marketCapData', data) return data }