diff --git a/package.json b/package.json index e7a4bb8..9da51f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { + "author": "Alec Sloan (https://alecsloan.codes/)", "name": "cryptolio", - "version": "3.5.0", + "version": "3.6.0", "private": true, "dependencies": { "@material-ui/core": "latest", diff --git a/src/App.js b/src/App.js index 168ffbb..4656276 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,3 @@ -import AssetCard from './Components/AssetCard.js' import Header from './Components/Header.js' import Hotkeys from 'react-hot-keys' import React, { Component } from 'react' @@ -8,48 +7,14 @@ import { createMuiTheme } from '@material-ui/core/styles' import { ThemeProvider } from '@material-ui/styles' import './styles/App.css' -import { CssBaseline, Grid, IconButton, Snackbar } from '@material-ui/core' +import { CssBaseline, IconButton, Snackbar } from '@material-ui/core' import CloseIcon from '@material-ui/icons/Close' import { Alert } from '@material-ui/lab' import AssetPanel from './Components/AssetPanel' import * as CoinGecko from './Util/CoinGecko' import * as CoinMarketCap from './Util/CoinMarketCap' import * as Theme from './Theme' -import AssetTable from './Components/AssetTable' -import PortfolioDonutChart from './Components/PortfolioDonutChart' -import PortfolioAreaStackChart from './Components/PortfolioAreaStackChart' - -function CardRow (props) { - const cards = [] - - let assets = props.assets - - if (!assets) { return null } - - if (props.settings.sorting === 'price') { - assets = assets.sort((a, b) => b.price - a.price) - } else if (props.settings.sorting === 'market_cap') { - assets = assets.sort((a, b) => b.market_cap - a.market_cap) - } else if (props.settings.sorting === 'percent_change_1h') { - assets = assets.sort((a, b) => b.percent_change_1h - a.percent_change_1h) - } else if (props.settings.sorting === 'percent_change_24h') { - assets = assets.sort((a, b) => b.percent_change_24h - a.percent_change_24h) - } else if (props.settings.sorting === 'percent_change_7d') { - assets = assets.sort((a, b) => b.percent_change_7d - a.percent_change_7d) - } else { - assets = assets.sort((a, b) => ((b.holdings || 0.000001) * b.price) - ((a.holdings || 0.000001) * a.price)) - } - - assets.forEach(asset => { - cards.push( - - - - ) - }) - - return {cards} -} +import LayoutHandler from './Components/LayoutHandler' class App extends Component { constructor (props) { @@ -63,13 +28,13 @@ class App extends Component { balanceChangeTimeframe: 'percent_change_24h', currency: 'USD', datasource: 'coinmarketcap', - days: 7, decimals2: 100, decimals3: 1, decimals4: null, fetchInterval: 300000, portfolioBreakdown: "none", renderStyle: (window.innerWidth <= 500) ? 'table' : 'card:classic', + renderSubStyle: 'table', show1hChange: true, show24hChange: true, show7dChange: true, @@ -309,28 +274,8 @@ class App extends Component {
- - { - this.state.settings.portfolioBreakdown === "stacked_line" - ? - : null - } - - { - this.state.settings.portfolioBreakdown === "donut" - ? - - - : null - } - - { - (!this.state.settings.renderStyle || this.state.settings.renderStyle.includes('card')) - ? - : - } - - + + b.price - a.price) + } else if (props.settings.sorting === 'market_cap') { + assets = assets.sort((a, b) => b.market_cap - a.market_cap) + } else if (props.settings.sorting === 'percent_change_1h') { + assets = assets.sort((a, b) => b.percent_change_1h - a.percent_change_1h) + } else if (props.settings.sorting === 'percent_change_24h') { + assets = assets.sort((a, b) => b.percent_change_24h - a.percent_change_24h) + } else if (props.settings.sorting === 'percent_change_7d') { + assets = assets.sort((a, b) => b.percent_change_7d - a.percent_change_7d) + } else { + assets = assets.sort((a, b) => ((b.holdings || 0.000001) * b.price) - ((a.holdings || 0.000001) * a.price)) + } + + switch (props.renderStyle || props.settings.renderStyle) { + case "card:classic": + case "card:compact": + return + case "portfolio:chart": + return + case "portfolio:donut": + return + case "table": + default: + return + } +} + +export default LayoutHandler diff --git a/src/Components/PortfolioAreaStackChart.js b/src/Components/PortfolioAreaStackChart.js index 1cfad44..eb173b4 100644 --- a/src/Components/PortfolioAreaStackChart.js +++ b/src/Components/PortfolioAreaStackChart.js @@ -5,6 +5,11 @@ import * as CoinMarketCap from '../Util/CoinMarketCap' import * as CoinGecko from '../Util/CoinGecko' import abbreviate from 'number-abbreviate' import { Skeleton } from '@material-ui/lab' +import { Grid } from '@material-ui/core' +import TimeframeSelector from './TimeframeSelector' +import SortSelector from './SortSelector' +import LayoutHandler from './LayoutHandler' +import MobileAssetCardGallery from '../Layouts/MobileAssetCardGallery' class PortfolioAreaStackChart extends Component { constructor (props) { @@ -69,14 +74,25 @@ class PortfolioAreaStackChart extends Component { } this.state = { - hasAssets: props.assets.filter(asset => asset.holdings > 0).length > 0, option: option } this.getData(props.settings, props.assets); } - async getData (settings, assets, days = 7) { + async getData (settings, assets) { + let days = 7 + + if (settings.balanceChangeTimeframe === "percent_change_1h") { + days = .0417 + } + else if (settings.balanceChangeTimeframe === "percent_change_24h") { + days = 1 + } + else { + days = Number(settings.balanceChangeTimeframe.replace(/[^0-9]/g, '')) + } + const currency = settings.currency const assetsHeld = assets.filter(asset => asset.holdings > 0).sort((a, b) => (b.holdings * b.price) - (a.holdings * a.price)) @@ -110,7 +126,7 @@ class PortfolioAreaStackChart extends Component { if (this.props.settings.datasource === 'coinmarketcap') { for (let [key, value] of Object.entries(assetData)) { - const index = key + const i = key if (assetsHeld.length > 1) { key = value.timestamp @@ -119,13 +135,24 @@ class PortfolioAreaStackChart extends Component { value = value[currency][0] } - let date = `${new Date(key).getMonth() + 1}/${new Date(key).getDate()}`; + if (days > 29) { + let date = `${new Date(key).getMonth() + 1}/${new Date(key).getDate()}`; - if (!dates.includes(date)) { - dates.push(date); + if (!dates.includes(date)) { + dates.push(date); + } } + else if (index === 0) { + let date = new Date(key) + let min = date.getMinutes() + + date.setMinutes(Math.ceil(min / 10) * 10) + date.setSeconds(0) - if (Number(index) === assetData.length - 1) { + dates.push(date.toLocaleString()); + } + + if (Number(i) === assetData.length - 1) { values.push(asset.price * asset.holdings) } else { values.push(value * asset.holdings); @@ -134,7 +161,6 @@ class PortfolioAreaStackChart extends Component { } else { assetData.map((granularDataset) => { - if (index === 0) { let date = new Date(granularDataset[0]) let min = date.getMinutes() @@ -178,8 +204,8 @@ class PortfolioAreaStackChart extends Component { UNSAFE_componentWillReceiveProps (nextProps, nextContext) { const assetsHeld = nextProps.assets.filter(asset => asset.holdings > 0) - if (nextProps.days || assetsHeld.length === 0) { - this.getData(nextProps.settings, nextProps.assets, nextProps.days); + if (nextProps.settings || assetsHeld.length === 0) { + this.getData(nextProps.settings, nextProps.assets); } } @@ -195,6 +221,22 @@ class PortfolioAreaStackChart extends Component { style={{ height: '100%', minHeight: '300px' }} />