add setDataToLocalStorage function

pull/2887/head
Max Alekseenko 5 years ago
parent 0a0eacefbd
commit 76145a54a5
  1. 8
      apps/block_scout_web/assets/js/lib/market_history_chart.js

@ -80,12 +80,16 @@ function getDataFromLocalStorage (key) {
return data ? JSON.parse(data) : [] return data ? JSON.parse(data) : []
} }
function setDataToLocalStorage (key, data) {
window.localStorage.setItem(key, JSON.stringify(data))
}
function getPriceData (marketHistoryData) { function getPriceData (marketHistoryData) {
if (marketHistoryData.length === 0) { if (marketHistoryData.length === 0) {
return getDataFromLocalStorage('priceData') return getDataFromLocalStorage('priceData')
} }
const data = marketHistoryData.map(({ date, closingPrice }) => ({ x: date, y: closingPrice })) const data = marketHistoryData.map(({ date, closingPrice }) => ({ x: date, y: closingPrice }))
window.localStorage.setItem('priceData', JSON.stringify(data)) setDataToLocalStorage('priceData', data)
return data return data
} }
@ -99,7 +103,7 @@ function getMarketCapData (marketHistoryData, availableSupply) {
: availableSupply : availableSupply
return { x: date, y: closingPrice * supply } return { x: date, y: closingPrice * supply }
}) })
window.localStorage.setItem('marketCapData', JSON.stringify(data)) setDataToLocalStorage('marketCapData', data)
return data return data
} }

Loading…
Cancel
Save