From a15e385b70de63eeca794cce7b9a827934df7a60 Mon Sep 17 00:00:00 2001 From: Viktor Date: Thu, 27 Jun 2024 15:06:04 +0200 Subject: [PATCH] [WebApp] fetch earnings per machine data and pass to the chart (#1151) * fetch earnings per machine data and pass to the chart * earnings per machine data handling * fix get earnings window for line chart * EarningLineChart: 5 initially selected machines * url added for "Where to find the Machine ID?" link * EarningLineChart: LIne fill prop source - improved * EarningLineChart: loader added / empty state - handled --------- Co-authored-by: Maksym Abramian --- .../src/modules/balance/BalanceStore.tsx | 216 ++- .../web-app/src/modules/balance/utils.tsx | 106 +- .../earn-views/EarningLineChartContainer.tsx | 1253 +---------------- .../earn-views/components/EarningChart.tsx | 13 +- .../earn-views/components/EarningHistory.tsx | 49 +- .../EarningLineChart/EarningLineChart.tsx | 172 ++- .../components/EarningMachineList.tsx | 88 ++ .../components/EarningMachineList.tsx | 122 -- .../web-app/src/modules/earn-views/mocks.ts | 1243 ++++++++++++++++ 9 files changed, 1765 insertions(+), 1497 deletions(-) create mode 100644 packages/web-app/src/modules/earn-views/components/EarningLineChart/components/EarningMachineList.tsx delete mode 100644 packages/web-app/src/modules/earn-views/components/EarningMachineList.tsx create mode 100644 packages/web-app/src/modules/earn-views/mocks.ts diff --git a/packages/web-app/src/modules/balance/BalanceStore.tsx b/packages/web-app/src/modules/balance/BalanceStore.tsx index 2e10b5c35..196249de1 100644 --- a/packages/web-app/src/modules/balance/BalanceStore.tsx +++ b/packages/web-app/src/modules/balance/BalanceStore.tsx @@ -1,9 +1,24 @@ import type { AxiosInstance } from 'axios' -import { action, computed, flow, observable } from 'mobx' +import type { Guid } from 'guid-typescript' +import { action, computed, flow, observable, runInAction } from 'mobx' +import type { Moment } from 'moment' import moment from 'moment' import type { RootStore } from '../../Store' -import type { ChartDaysShowing, EarningWindow } from './models' -import { batchEarningsWindow, getEarningWindowsGroupedByDay } from './utils' +import type { MachinesApiClient } from '../../api/machinesApiClient/generated/machinesApiClient' +import type { + EarningHistoryTimeframeEnum, + Machine, + MachineEarningHistory, +} from '../../api/machinesApiClient/generated/models' +import { getMachinesApiClient } from '../../api/machinesApiClient/getMachinesApiClient' +import type { ChartDaysShowing, EarningPerMachine, EarningWindow } from './models' +import { + batchEarningsWindow, + getBaseKeyAsGuid, + getEarningWindowsGroupedByDay, + normalizeEarningHistory, + normalizeEarningsPerMachine, +} from './utils' enum EarningChartTimeFilter { Last24Hour = '24 hour filter', @@ -12,21 +27,36 @@ enum EarningChartTimeFilter { } export class BalanceStore { - @observable - public currentBalance: number = 0 + private machinesApiClient: MachinesApiClient + + private _latestEarningsPerMachineFetchMoment: Moment | null = null @observable - public lifetimeBalance: number = 0 + private _earningsHistory: Map = new Map() @observable - private earningHistory: Map = new Map() + private _earningsPerMachine: EarningPerMachine | null = {} @observable private daysShowingEarnings: ChartDaysShowing = 1 + @observable + public currentBalance: number = 0 + + @observable + public lifetimeBalance: number = 0 + + @observable + public machines: Machine[] | null = [] + @computed public get earningsHistory(): EarningWindow[] { - return this.getEarningWindows(this.daysShowingEarnings) + return this.getEarningWindows(this.daysShowingEarnings, this._earningsHistory) + } + + @computed + public get earningsPerMachine(): EarningPerMachine { + return this.getEarningWindowsPerMachine(this.daysShowingEarnings) } @computed @@ -73,26 +103,123 @@ export class BalanceStore { @observable public lastMonthEarnings: number = 0 - private getEarningWindows = (numberOfDays: ChartDaysShowing): EarningWindow[] => { + private getMachines = async () => { + try { + const machinesResponse = await this.machinesApiClient?.v2.machines.get() + + if (machinesResponse?.items) { + return machinesResponse?.items + } + } catch (error) { + console.error('BalanceStore.getMultipleMachinesEarnings: ', error) + } + + return null + } + + private getEarningsPerMachine = async (machines: Machine[], chartsDaysShowing: ChartDaysShowing) => { + try { + return ( + await Promise.all( + machines + .filter((machine) => machine.machine_id) + .map((machine) => { + const timeframe: EarningHistoryTimeframeEnum = + chartsDaysShowing === 1 ? '24h' : (`${chartsDaysShowing}d` as EarningHistoryTimeframeEnum) + return this.machinesApiClient?.v2.machines + .byMachine_id(getBaseKeyAsGuid(machine.machine_id as Guid)) + .earningHistory.get({ queryParameters: { timeframe } }) + }), + ) + ).filter((value) => value) as MachineEarningHistory[] + } catch (error) { + console.error('BalanceStore.getEarningsPerMachine: ', error) + return null + } + } + + @action + fetchEarningsPerMachine = () => { + const shouldFetch = + this._latestEarningsPerMachineFetchMoment === null || + moment().diff(this._latestEarningsPerMachineFetchMoment, 'hours') > 0 + + if (shouldFetch) { + this._latestEarningsPerMachineFetchMoment = moment() + + this.getMachines() + .then((machines) => { + if (machines) { + runInAction(() => { + this.machines = machines + }) + return this.getEarningsPerMachine(machines, 30) + } + throw new Error('There is no machines') + }) + .then((earningsPerMachine) => { + if (earningsPerMachine) { + return runInAction(() => { + this._earningsPerMachine = normalizeEarningsPerMachine(earningsPerMachine) + }) + } + throw new Error('There are no earning per machines') + }) + .catch((error) => { + console.error('BalanceStore.getMultipleMachinesEarnings: ', error) + }) + } + } + + private getEarningWindowsPerMachine = (chartsDaysShowing: ChartDaysShowing): EarningPerMachine => { + if (this._earningsPerMachine === null) { + return {} + } + return Object.keys(this._earningsPerMachine).reduce((earningWindowsPerMachine, machineId) => { + if (!this._earningsPerMachine) { + return {} + } + + const machineEarningsMap = this._earningsPerMachine[machineId]?.reduce((machineEarningsMap, item) => { + machineEarningsMap.set(item.timestamp.unix(), item.earnings) + return machineEarningsMap + }, new Map()) + + if (!machineEarningsMap) { + return {} + } + + return { + ...earningWindowsPerMachine, + [machineId]: this.getEarningWindows(chartsDaysShowing, machineEarningsMap, true), + } + }, {} as EarningPerMachine) + } + + private getEarningWindows = ( + chartsDaysShowing: ChartDaysShowing, + earningHistory: Map, + isPerMachineEarning?: boolean, + ): EarningWindow[] => { const windows: EarningWindow[] = [] const now = moment.utc() - const threshold = moment(now).subtract(numberOfDays, 'days') + const threshold = moment(now).subtract(chartsDaysShowing, 'days') let batchedEarningWindows = new Map() - switch (numberOfDays) { + switch (chartsDaysShowing) { case 1: - batchedEarningWindows = this.earningHistory + batchedEarningWindows = isPerMachineEarning ? batchEarningsWindow(earningHistory, 4) : earningHistory break case 7: - batchedEarningWindows = batchEarningsWindow(this.earningHistory, 8) + batchedEarningWindows = batchEarningsWindow(earningHistory, 8) break case 30: - batchedEarningWindows = batchEarningsWindow(this.earningHistory, 48) + batchedEarningWindows = batchEarningsWindow(earningHistory, 48) break default: - batchedEarningWindows = this.earningHistory + batchedEarningWindows = earningHistory } for (let [unixTime, earning] of batchedEarningWindows) { @@ -108,16 +235,21 @@ export class BalanceStore { const sortedEarningWindowsByTimestamp = windows.sort((a, b) => a.timestamp.diff(b.timestamp)) - if (numberOfDays === 1) { + if (chartsDaysShowing === 1) { return sortedEarningWindowsByTimestamp } - const groupedByTheDayEarningWindows = getEarningWindowsGroupedByDay(sortedEarningWindowsByTimestamp, numberOfDays) + const groupedByTheDayEarningWindows = getEarningWindowsGroupedByDay( + sortedEarningWindowsByTimestamp, + chartsDaysShowing, + ) return groupedByTheDayEarningWindows } - constructor(private readonly store: RootStore, private readonly axios: AxiosInstance) {} + constructor(private readonly store: RootStore, private readonly axios: AxiosInstance) { + this.machinesApiClient = getMachinesApiClient(axios) + } @action.bound refreshBalanceAndHistory = flow(function* (this: BalanceStore) { @@ -143,49 +275,13 @@ export class BalanceStore { const earningData = response.data - const roundedDown = Math.floor(moment().minute() / 15) * 15 - - const now = moment().minute(roundedDown).second(0).millisecond(0) - - const threshold24Hrs = moment(now).subtract(24, 'hours') - const threshold7Days = moment(now).subtract(7, 'days') - - const earningValues: Map = new Map() - - let total24Hrs = 0 - let total7Days = 0 - let total30Days = 0 - - //Process the input data into a usable format - for (let key in earningData) { - const timestamp = moment(key) - const earnings: number = earningData[key] - earningValues.set(timestamp.unix(), earnings) - - if (timestamp >= threshold24Hrs) { - total24Hrs += earnings - } - - if (timestamp >= threshold7Days) { - total7Days += earnings - } - - total30Days += earnings - } - - this.lastMonthEarnings = total30Days - this.lastWeekEarnings = total7Days - this.lastDayEarnings = total24Hrs - - const history = new Map() - - for (let i = 0; i < 2880; ++i) { - const earning = earningValues.get(now.unix()) - history.set(now.unix(), earning || 0) - now.subtract(15, 'minutes') - } + const { lastMonthEarnings, lastWeekEarnings, lastDayEarnings, earningHistory } = + normalizeEarningHistory(earningData) - this.earningHistory = history + this.lastMonthEarnings = lastMonthEarnings + this.lastWeekEarnings = lastWeekEarnings + this.lastDayEarnings = lastDayEarnings + this._earningsHistory = earningHistory } catch (error) { console.error('Balance history error: ') console.error(error) diff --git a/packages/web-app/src/modules/balance/utils.tsx b/packages/web-app/src/modules/balance/utils.tsx index 4dc628ec2..97e3f3f27 100644 --- a/packages/web-app/src/modules/balance/utils.tsx +++ b/packages/web-app/src/modules/balance/utils.tsx @@ -1,6 +1,8 @@ +import { Guid } from 'guid-typescript' import { chunk, groupBy } from 'lodash' import moment from 'moment' -import type { EarningWindow } from './models' +import type { MachineEarningHistory } from '../../api/machinesApiClient/generated/models' +import type { EarningPerMachine, EarningWindow } from './models' export const batchEarningsWindow = (earnings: Map, batchSize: number): Map => { const earningHistory = new Map() @@ -35,3 +37,105 @@ export const getEarningWindowsGroupedByDay = ( return chunkedDaysPeriodEarnings } + +export type BaseKey = string | number + +export const getBaseKeyAsGuid = (key: BaseKey | Guid): Guid => { + // TODO: Do not force to string and bypass type check (after Kiota is fixed). + // https://github.com/microsoft/kiota-typescript/issues/1113 + if (key instanceof Guid) { + return key.toString() as unknown as Guid + } + return Guid.parse(key.toString()).toString() as unknown as Guid +} + +export const normalizeEarningsPerMachine = ( + earningsPerMachine: MachineEarningHistory[] | null, +): EarningPerMachine | null => { + let normalizedEarningsPerMachine: EarningPerMachine | null = null + if (earningsPerMachine) { + normalizedEarningsPerMachine = earningsPerMachine.reduce((aggregatedEarningsPerMachine, machineEarnings) => { + if (machineEarnings.earnings) { + const machineId = machineEarnings.machine_id?.toString() as string + const { earningHistory: earningHistoryMap } = normalizeEarningHistory( + machineEarnings.earnings as Record, + ) + + const machineEarningHistory = Object.fromEntries(earningHistoryMap.entries()) + + const earnings = Object.keys(machineEarningHistory).map((timestamp: string) => { + const timestampMoment = moment(Number(timestamp) * 1000) + return { + timestamp: timestampMoment, + earnings: machineEarningHistory[timestamp] ?? 0, + } + }) + + return { + ...aggregatedEarningsPerMachine, + [machineId]: earnings, + } + } + + return aggregatedEarningsPerMachine + }, {} as EarningPerMachine) + + return normalizedEarningsPerMachine + } + + return null +} + +export const normalizeEarningHistory = ( + earningData: Record, +): { + lastMonthEarnings: number + lastWeekEarnings: number + lastDayEarnings: number + earningHistory: Map +} => { + const roundedDown = Math.floor(moment().minute() / 15) * 15 + + const now = moment().minute(roundedDown).second(0).millisecond(0) + + const threshold24Hrs = moment(now).subtract(24, 'hours') + const threshold7Days = moment(now).subtract(7, 'days') + + const earningValues: Map = new Map() + + let total24Hrs = 0 + let total7Days = 0 + let total30Days = 0 + + //Process the input data into a usable format + for (let key in earningData) { + const timestamp = moment(key) + const earnings: number = earningData[key] as number + earningValues.set(timestamp.unix(), earnings) + + if (timestamp >= threshold24Hrs) { + total24Hrs += earnings + } + + if (timestamp >= threshold7Days) { + total7Days += earnings + } + + total30Days += earnings + } + + const history = new Map() + + for (let i = 0; i < 2880; ++i) { + const earning = earningValues.get(now.unix()) + history.set(now.unix(), earning || 0) + now.subtract(15, 'minutes') + } + + return { + lastMonthEarnings: total30Days, + lastWeekEarnings: total7Days, + lastDayEarnings: total24Hrs, + earningHistory: history, + } +} diff --git a/packages/web-app/src/modules/earn-views/EarningLineChartContainer.tsx b/packages/web-app/src/modules/earn-views/EarningLineChartContainer.tsx index 1f3c05f3b..04b23a7ac 100644 --- a/packages/web-app/src/modules/earn-views/EarningLineChartContainer.tsx +++ b/packages/web-app/src/modules/earn-views/EarningLineChartContainer.tsx @@ -1,1254 +1,13 @@ -import { connect } from '../../connect' import type { RootStore } from '../../Store' +import { connect } from '../../connect' import { EarningLineChart } from './components/EarningLineChart' -const mockedEarningsPerMachine = (daysShowing: number) => { - const shouldShowAmPm = daysShowing === 1 - const shouldShowDateMonth = daysShowing === 7 - const earningsPerMachine24hours = { - 'cd6649d2-1374-4133-a0fd-783e05e7aa02': [ - { - timestamp: '2024-06-18T10:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T10:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T10:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T10:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T11:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T11:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T11:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T11:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T12:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T12:15:00.000Z', - earnings: 0.04214125125, - }, - { - timestamp: '2024-06-18T12:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T12:45:00.000Z', - earnings: 0.012131424125125, - }, - { - timestamp: '2024-06-18T13:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T13:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T13:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T13:45:00.000Z', - earnings: 0.05215215215, - }, - { - timestamp: '2024-06-18T14:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T14:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T14:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T14:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T15:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T15:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T15:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T15:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T16:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T16:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T16:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T16:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T17:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T17:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T17:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T17:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T18:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T18:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T18:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T18:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T19:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T19:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T19:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T19:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T20:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T20:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T20:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T20:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T21:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T21:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T21:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T21:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T23:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T23:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T23:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T23:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T00:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T00:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T00:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T00:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T01:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T01:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T01:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T01:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T02:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T02:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T02:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T02:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T03:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T03:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T03:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T03:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T04:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T04:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T04:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T04:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T05:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T05:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T05:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T05:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T06:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T06:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T06:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T06:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T07:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T07:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T07:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T07:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T08:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T08:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T08:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T08:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T09:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T09:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T09:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T09:45:00.000Z', - earnings: 0, - }, - ], - 'cdfkd234-1374-4133-a0fd-783e05egd24g': [ - { - timestamp: '2024-06-18T10:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T10:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T10:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T10:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T11:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T11:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T11:30:00.000Z', - earnings: 0.05215215215, - }, - { - timestamp: '2024-06-18T11:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T12:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T12:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T12:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T12:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T13:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T13:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T13:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T13:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T14:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T14:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T14:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T14:45:00.000Z', - earnings: 0.05215215215, - }, - { - timestamp: '2024-06-18T15:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T15:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T15:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T15:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T16:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T16:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T16:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T16:45:00.000Z', - earnings: 0.05215215215, - }, - { - timestamp: '2024-06-18T17:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T17:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T17:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T17:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T18:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T18:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T18:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T18:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T19:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T19:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T19:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T19:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T20:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T20:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T20:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T20:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T21:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T21:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T21:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T21:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T23:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T23:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T23:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T23:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T00:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T00:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T00:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T00:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T01:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T01:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T01:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T01:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T02:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T02:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T02:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T02:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T03:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T03:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T03:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T03:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T04:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T04:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T04:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T04:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T05:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T05:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T05:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T05:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T06:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T06:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T06:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T06:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T07:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T07:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T07:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T07:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T08:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T08:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T08:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T08:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T09:00:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T09:15:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T09:30:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-19T09:45:00.000Z', - earnings: 0, - }, - ], - } - const earningsPerMachine7days = { - 'cd6649d2-1374-4133-a0fd-783e05e7aa02': [ - { - timestamp: '2024-06-12T22:45:00.000Z', - earnings: 0.29999238912, - }, - { - timestamp: '2024-06-13T22:45:00.000Z', - earnings: 0.029999238912, - }, - { - timestamp: '2024-06-14T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-15T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-16T22:45:00.000Z', - earnings: 0.00125658384, - }, - { - timestamp: '2024-06-17T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0, - }, - ], - 'cdm649d2-1374-4133-a0fd-783e05e7aa02': [ - { - timestamp: '2024-06-12T22:45:00.000Z', - earnings: 0.5999238912, - }, - { - timestamp: '2024-06-13T22:45:00.000Z', - earnings: 0.029999238912, - }, - { - timestamp: '2024-06-14T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-15T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-16T22:45:00.000Z', - earnings: 0.10125658384, - }, - { - timestamp: '2024-06-17T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0, - }, - ], - 'cd664xd2-1374-4133-a0fd-783e05e7aa02': [ - { - timestamp: '2024-06-12T22:45:00.000Z', - earnings: 0.29999238912, - }, - { - timestamp: '2024-06-13T22:45:00.000Z', - earnings: 0.229999238912, - }, - { - timestamp: '2024-06-14T22:45:00.000Z', - earnings: 0.325325, - }, - { - timestamp: '2024-06-15T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-16T22:45:00.000Z', - earnings: 0.00125658384, - }, - { - timestamp: '2024-06-17T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0, - }, - ], - 'cd6649j2-1374-4133-a0fd-783e05e7aa02': [ - { - timestamp: '2024-06-12T22:45:00.000Z', - earnings: 0.29999238912, - }, - { - timestamp: '2024-06-13T22:45:00.000Z', - earnings: 0.021499238912, - }, - { - timestamp: '2024-06-14T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-15T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-16T22:45:00.000Z', - earnings: 0.00125658384, - }, - { - timestamp: '2024-06-17T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0.4324235, - }, - ], - 'gd6649d2-1374-4133-a0fd-783e05e7aa02': [ - { - timestamp: '2024-06-12T22:45:00.000Z', - earnings: 0.29999238912, - }, - { - timestamp: '2024-06-13T22:45:00.000Z', - earnings: 0.029999238912, - }, - { - timestamp: '2024-06-14T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-15T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-16T22:45:00.000Z', - earnings: 0.52125658384, - }, - { - timestamp: '2024-06-17T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0, - }, - ], - 'cd1649d2-1374-4133-a0fd-783e057aa02': [ - { - timestamp: '2024-06-12T22:45:00.000Z', - earnings: 0.29999238912, - }, - { - timestamp: '2024-06-13T22:45:00.000Z', - earnings: 0.029999238912, - }, - { - timestamp: '2024-06-14T22:45:00.000Z', - earnings: 0.5325325, - }, - { - timestamp: '2024-06-15T22:45:00.000Z', - earnings: 0.21551, - }, - { - timestamp: '2024-06-16T22:45:00.000Z', - earnings: 0.00125658384, - }, - { - timestamp: '2024-06-17T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0, - }, - ], - 'cdfkd234-1374-4133-a0fd-783e05egd24g': [ - { - timestamp: '2024-06-12T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-13T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-14T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-15T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-16T22:45:00.000Z', - earnings: 0.212414, - }, - { - timestamp: '2024-06-17T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0, - }, - ], - } - const earningsPerMachine30days = { - 'cd6649d2-1374-4133-a0fd-783e05e7aa02': [ - { - timestamp: '2024-05-20T22:45:00.000Z', - earnings: 0.100675274272, - }, - { - timestamp: '2024-05-21T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-22T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-23T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-24T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-25T22:45:00.000Z', - earnings: 0.4523523525352, - }, - { - timestamp: '2024-05-26T22:45:00.000Z', - earnings: 0.0000878523786068759, - }, - { - timestamp: '2024-05-27T22:45:00.000Z', - earnings: 0.0024540381142155914, - }, - { - timestamp: '2024-05-28T22:45:00.000Z', - earnings: 0.000239697393818121, - }, - { - timestamp: '2024-05-29T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-30T22:45:00.000Z', - earnings: 0.22224126002, - }, - { - timestamp: '2024-05-31T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-01T22:45:00.000Z', - earnings: 0.003241766201949881, - }, - { - timestamp: '2024-06-02T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-03T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-04T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-05T22:45:00.000Z', - earnings: 0.000216046054874071, - }, - { - timestamp: '2024-06-06T22:45:00.000Z', - earnings: 0.0011643950392236195, - }, - { - timestamp: '2024-06-07T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-08T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-09T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-10T22:45:00.000Z', - earnings: 0.00097026947760907, - }, - { - timestamp: '2024-06-11T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-12T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-13T22:45:00.000Z', - earnings: 0.029999238912, - }, - { - timestamp: '2024-06-14T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-15T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-16T22:45:00.000Z', - earnings: 0.00125658384, - }, - { - timestamp: '2024-06-17T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0, - }, - ], - 'cdfkd234-1374-4133-a0fd-783e05egd24g': [ - { - timestamp: '2024-05-20T22:45:00.000Z', - earnings: 0.000675274272, - }, - { - timestamp: '2024-05-21T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-22T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-23T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-24T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-25T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-26T22:45:00.000Z', - earnings: 0.0000878523786068759, - }, - { - timestamp: '2024-05-27T22:45:00.000Z', - earnings: 0.0024540381142155914, - }, - { - timestamp: '2024-05-28T22:45:00.000Z', - earnings: 0.000239697393818121, - }, - { - timestamp: '2024-05-29T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-30T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-05-31T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-01T22:45:00.000Z', - earnings: 0.003241766201949881, - }, - { - timestamp: '2024-06-02T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-03T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-04T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-05T22:45:00.000Z', - earnings: 0.000216046054874071, - }, - { - timestamp: '2024-06-06T22:45:00.000Z', - earnings: 0.0011643950392236195, - }, - { - timestamp: '2024-06-07T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-08T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-09T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-10T22:45:00.000Z', - earnings: 0.00097026947760907, - }, - { - timestamp: '2024-06-11T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-12T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-13T22:45:00.000Z', - earnings: 0.06235235253532, - }, - { - timestamp: '2024-06-14T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-15T22:45:00.000Z', - earnings: 0.241415626634, - }, - { - timestamp: '2024-06-16T22:45:00.000Z', - earnings: 0.00004124124, - }, - { - timestamp: '2024-06-17T22:45:00.000Z', - earnings: 0, - }, - { - timestamp: '2024-06-18T22:45:00.000Z', - earnings: 0, - }, - ], - } - if (shouldShowAmPm) { - return earningsPerMachine24hours - } else if (shouldShowDateMonth) { - return earningsPerMachine7days - } else { - return earningsPerMachine30days +const mapStoreToProps = (store: RootStore): any => { + return { + earningsPerMachine: store.balance.earningsPerMachine, + daysShowing: store.balance.getDaysShowingEarnings, + fetchEarningsPerMachine: store.balance.fetchEarningsPerMachine, } } -const mapStoreToProps = (store: RootStore): any => ({ - earningsPerMachine: mockedEarningsPerMachine(store.balance.getDaysShowingEarnings), - daysShowing: store.balance.getDaysShowingEarnings, -}) - export const EarningLineChartContainer = connect(mapStoreToProps, EarningLineChart) diff --git a/packages/web-app/src/modules/earn-views/components/EarningChart.tsx b/packages/web-app/src/modules/earn-views/components/EarningChart.tsx index bea2e1173..6f7fc9363 100644 --- a/packages/web-app/src/modules/earn-views/components/EarningChart.tsx +++ b/packages/web-app/src/modules/earn-views/components/EarningChart.tsx @@ -15,6 +15,15 @@ import type { ChartDaysShowing, EarningWindow } from '../../balance/models' import { MidnightHour, NoonHour } from '../pages/constants' const styles = (theme: SaladTheme) => ({ + earningChartWrapper: { + height: '400px', + width: '100%', + display: 'flex', + justifyContent: 'flex-start', + alignItems: 'flex-start', + flexDirection: 'row', + gap: '24px', + }, removeContainerPadding: { paddingTop: 0, }, @@ -423,7 +432,7 @@ class _EarningChart extends Component {

No data to display

{earningHistory && ( - <> +
{ - +
)} ) diff --git a/packages/web-app/src/modules/earn-views/components/EarningHistory.tsx b/packages/web-app/src/modules/earn-views/components/EarningHistory.tsx index 6e263a91a..7d376eb8f 100644 --- a/packages/web-app/src/modules/earn-views/components/EarningHistory.tsx +++ b/packages/web-app/src/modules/earn-views/components/EarningHistory.tsx @@ -9,16 +9,25 @@ import { EarningLineChartContainer } from '../EarningLineChartContainer' import { EarnSectionHeader } from './EarnSectionHeader' const styles = (theme: SaladTheme) => ({ - container: { + earningHistoryWrapper: { display: 'flex', + justifyContent: 'flex-start', + alignItems: 'flex-start', flexDirection: 'column', - maxWidth: 860, + width: '100%', position: 'relative', }, - chartContainer: { + chartWrapper: { display: 'flex', - height: 250, + flexDirection: 'column', + flex: 1, + position: 'relative', + height: 200, width: '100%', + }, + chartContainer: { + display: 'flex', + height: 300, position: 'relative', flexDirection: 'column', }, @@ -65,25 +74,27 @@ const EarningHistoryRaw = ({ classes, viewLast24Hours, viewLast7Days, viewLast30 ] return ( -
+
Earning History -

See earnings from the last...

-
-
- +
+

See earnings from the last...

+
+
+ +
+
+ +
-
- +
+ {isEarningsPerMachineEnabled ? : }
-
- {isEarningsPerMachineEnabled ? : } -
) } diff --git a/packages/web-app/src/modules/earn-views/components/EarningLineChart/EarningLineChart.tsx b/packages/web-app/src/modules/earn-views/components/EarningLineChart/EarningLineChart.tsx index 0bf2080a2..4be3cdd68 100644 --- a/packages/web-app/src/modules/earn-views/components/EarningLineChart/EarningLineChart.tsx +++ b/packages/web-app/src/modules/earn-views/components/EarningLineChart/EarningLineChart.tsx @@ -1,5 +1,7 @@ +import { LoadingSpinner } from '@saladtechnologies/garden-components' import type CSS from 'csstype' import moment from 'moment' +import { useEffect, useState } from 'react' import type { WithStyles } from 'react-jss' import withStyles from 'react-jss' import { CartesianGrid, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts' @@ -9,8 +11,26 @@ import type { ChartDaysShowing, EarningPerMachine, EarningWindow } from '../../. import { earningsChartColors } from '../../pages/constants' import { normalizeEarningsPerMachineData } from '../../utils' import { CustomizedXAxisTick } from './components' +import type { MachineOptions } from './components/EarningMachineList' +import { EarningMachineList } from './components/EarningMachineList' const styles: (theme: SaladTheme) => Record = (theme: SaladTheme) => ({ + earningLineChartWrapper: { + height: '400px', + width: '100%', + display: 'flex', + justifyContent: 'flex-start', + alignItems: 'flex-start', + flexDirection: 'row', + gap: '24px', + }, + loaderWrapper: { + height: '100%', + width: '100%', + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + }, tickFont: { fontFamily: 'Mallory', color: theme.lightGreen, @@ -25,62 +45,122 @@ const styles: (theme: SaladTheme) => Record = (theme: Sa }, }) +const initiallyCheckedMachineOptionsAmount = 5 + +const getMachineOptions = (earningsPerMachine: EarningPerMachine) => { + return Object.keys(earningsPerMachine).reduce((machineOptions, machineId, index) => { + const isCheckedInitially = index < initiallyCheckedMachineOptionsAmount + return { + ...machineOptions, + [machineId]: { + id: machineId, + color: earningsChartColors[index] as string, + isChecked: isCheckedInitially, + }, + } + }, {} as MachineOptions) +} + interface Props extends WithStyles { earningsPerMachine: EarningPerMachine daysShowing: ChartDaysShowing + fetchEarningsPerMachine: () => void } -const _EarningLineChart = ({ classes, earningsPerMachine, daysShowing }: Props) => { +const _EarningLineChart = ({ classes, earningsPerMachine, daysShowing, fetchEarningsPerMachine }: Props) => { const is24HoursChart = daysShowing === 1 + const [machineOptions, setMachineOptions] = useState({}) - const machineEarningsData = Object.keys(earningsPerMachine).map((key) => ({ - name: key.substring(0, 8), - data: normalizeEarningsPerMachineData(earningsPerMachine[key] as EarningWindow[], daysShowing), + useEffect(() => { + setMachineOptions(getMachineOptions(earningsPerMachine)) + }, [earningsPerMachine]) + + const handleMachineOptionClick = (machineId: string) => { + setMachineOptions( + (prevMachineOptions) => + ({ + ...prevMachineOptions, + [machineId]: { + ...prevMachineOptions[machineId], + isChecked: !prevMachineOptions[machineId]?.isChecked, + }, + } as MachineOptions), + ) + } + + const machineEarningsData = Object.keys(earningsPerMachine).map((machineId) => ({ + id: machineId, + name: machineId.substring(0, 8), + data: normalizeEarningsPerMachineData(earningsPerMachine[machineId] as EarningWindow[], daysShowing), })) + useEffect(() => { + fetchEarningsPerMachine() + }, [fetchEarningsPerMachine]) + + const isLoading = machineEarningsData.length <= 0 + const isNoMachineOptionChecked = !Object.values(machineOptions).some((machineOption) => machineOption.isChecked) + return ( - - - - } - /> - (earnings === 0 ? '' : `$${earnings}`)} - tickLine={false} - /> - formatBalance(Number(value))} - labelFormatter={(value) => (is24HoursChart ? moment(value, 'HH').format('h A') : value)} - wrapperClassName={classes.tooltipWrapper} - /> - {machineEarningsData.map((machineEarning, index) => ( - - ))} - - +
+ {isLoading ? ( +
+ +
+ ) : ( + <> + + + + } + /> + (earnings === 0 ? '' : `$${earnings}`)} + tickLine={false} + /> + formatBalance(Number(value))} + labelFormatter={(value) => (is24HoursChart ? moment(value, 'HH').format('h A') : value)} + wrapperClassName={classes.tooltipWrapper} + /> + {machineEarningsData.map( + (machineEarning) => + machineOptions[machineEarning.id]?.isChecked && ( + + ), + )} + + + + + )} +
) } diff --git a/packages/web-app/src/modules/earn-views/components/EarningLineChart/components/EarningMachineList.tsx b/packages/web-app/src/modules/earn-views/components/EarningLineChart/components/EarningMachineList.tsx new file mode 100644 index 000000000..6e01b21a3 --- /dev/null +++ b/packages/web-app/src/modules/earn-views/components/EarningLineChart/components/EarningMachineList.tsx @@ -0,0 +1,88 @@ +import { Text } from '@saladtechnologies/garden-components' +import type CSS from 'csstype' +import { type FC } from 'react' +import Scrollbars from 'react-custom-scrollbars-2' +import type { WithStyles } from 'react-jss' +import withStyles from 'react-jss' +import type { SaladTheme } from '../../../../../SaladTheme' +import { Checkbox } from '../../../../../components' +import { earningsChartColors } from '../../../pages/constants' + +const styles: (theme: SaladTheme) => Record = (theme: SaladTheme) => ({ + container: { + display: 'flex', + flexDirection: 'column', + position: 'relative', + height: '100%', + width: '260px', + overflow: 'hidden', + color: theme.lightGreen, + }, + header: { + marginBottom: '8px', + display: 'flex', + justifyContent: 'center', + alignItems: 'flex-start', + flexDirection: 'column', + }, + link: { + color: theme.mediumGreen, + textDecoration: 'underline', + cursor: 'pointer', + }, + option: { + display: 'flex', + flexDirection: 'row', + justifyContent: 'flex-start', + alignItems: 'center', + cursor: 'pointer', + }, +}) + +interface MachineOption { + id: string + color: string + isChecked: boolean +} + +export type MachineOptions = Record + +interface Props extends WithStyles { + machineOptions: MachineOptions + onSelectedMachineChange: (machineId: string) => void +} + +const EarningMachineListRaw: FC = ({ classes, machineOptions, onSelectedMachineChange }) => { + const machineOptionsList = Object.values(machineOptions) + const totalMachinesAmount = machineOptionsList.length + const checkedMachinesAmount = machineOptionsList.filter((machineOption) => machineOption.isChecked).length + + const title = `Machines (${checkedMachinesAmount}/${totalMachinesAmount})` + + return ( +
+ + + {machineOptionsList.map((machineOption, index) => ( +
onSelectedMachineChange(machineOption.id)} + key={machineOption.id} + > + + {machineOption.id.substring(0, 8)} +
+ ))} +
+
+ ) +} + +export const EarningMachineList = withStyles(styles)(EarningMachineListRaw) diff --git a/packages/web-app/src/modules/earn-views/components/EarningMachineList.tsx b/packages/web-app/src/modules/earn-views/components/EarningMachineList.tsx deleted file mode 100644 index 89a29a2b6..000000000 --- a/packages/web-app/src/modules/earn-views/components/EarningMachineList.tsx +++ /dev/null @@ -1,122 +0,0 @@ -import { Text } from '@saladtechnologies/garden-components' -import type CSS from 'csstype' -import { useState, type FC } from 'react' -import Scrollbars from 'react-custom-scrollbars-2' -import type { WithStyles } from 'react-jss' -import withStyles from 'react-jss' -import type { SaladTheme } from '../../../SaladTheme' -import { Checkbox } from '../../../components' - -const styles: (theme: SaladTheme) => Record = (theme: SaladTheme) => ({ - container: { - display: 'flex', - flexDirection: 'column', - position: 'relative', - height: '200px', - width: '210px', - overflow: 'hidden', - color: theme.lightGreen, - }, - header: { - marginBottom: '8px', - display: 'flex', - justifyContent: 'center', - alignItems: 'flex-start', - flexDirection: 'column', - }, - link: { - color: theme.mediumGreen, - textDecoration: 'underline', - cursor: 'pointer', - }, - option: { - display: 'flex', - flexDirection: 'row', - justifyContent: 'flex-start', - alignItems: 'center', - cursor: 'pointer', - }, -}) - -interface Machine { - id: string - color: string - isChecked: boolean -} - -type MachineOptions = Record - -const mockedMachines: Record = { - 'machine-id-1': { id: 'machine-id-1', isChecked: false, color: '#277c87' }, - 'machine-id-2': { id: 'machine-id-2', isChecked: false, color: '#ce7f25' }, - 'machine-id-3': { id: 'machine-id-3', isChecked: false, color: '#13b58a' }, - 'machine-id-4': { id: 'machine-id-4', isChecked: false, color: '#58580a' }, - 'machine-id-5': { id: 'machine-id-5', isChecked: false, color: '#278729' }, - 'machine-id-6': { id: 'machine-id-6', isChecked: false, color: '#093ac0' }, - 'machine-id-7': { id: 'machine-id-7', isChecked: false, color: '#da6207' }, - 'machine-id-8': { id: 'machine-id-8', isChecked: false, color: '#0aa445' }, - 'machine-id-9': { id: 'machine-id-9', isChecked: false, color: '#0fc2aa' }, - 'machine-id-10': { id: 'machine-id-10', isChecked: false, color: '#d71e9c' }, - 'machine-id-11': { id: 'machine-id-11', isChecked: false, color: '#13a6ce' }, - 'machine-id-12': { id: 'machine-id-12', isChecked: false, color: '#0eb00e' }, - 'machine-id-13': { id: 'machine-id-13', isChecked: false, color: '#59de62' }, - 'machine-id-14': { id: 'machine-id-14', isChecked: false, color: '#722787' }, - 'machine-id-15': { id: 'machine-id-15', isChecked: false, color: '#3c2787' }, - 'machine-id-16': { id: 'machine-id-16', isChecked: false, color: '#273587' }, - 'machine-id-17': { id: 'machine-id-17', isChecked: false, color: '#278784' }, - 'machine-id-18': { id: 'machine-id-18', isChecked: false, color: '#278729' }, - 'machine-id-19': { id: 'machine-id-19', isChecked: false, color: '#c4490c' }, - 'machine-id-20': { id: 'machine-id-20', isChecked: false, color: '#d355af' }, -} - -interface Props extends WithStyles {} - -const EarningMachineListRaw: FC = ({ classes }) => { - const [machineOptions, setMachineOptions] = useState(mockedMachines) - - const handleMachineOptionClick = (machineId: string) => { - setMachineOptions( - (prevMachineOptions) => - ({ - ...prevMachineOptions, - [machineId]: { - ...prevMachineOptions[machineId], - isChecked: !prevMachineOptions[machineId]?.isChecked, - }, - } as MachineOptions), - ) - } - - const machineOptionsList = Object.values(machineOptions) - const totalMachinesAmount = machineOptionsList.length - const checkedMachinesAmount = machineOptionsList.filter((machineOption) => machineOption.isChecked).length - - const title = `Machines (${checkedMachinesAmount}/${totalMachinesAmount})` - - return ( -
- - - {machineOptionsList.map((machineOption) => ( -
handleMachineOptionClick(machineOption.id)} - key={machineOption.id} - > - - {machineOption.id} -
- ))} -
-
- ) -} - -export const EarningMachineList = withStyles(styles)(EarningMachineListRaw) diff --git a/packages/web-app/src/modules/earn-views/mocks.ts b/packages/web-app/src/modules/earn-views/mocks.ts new file mode 100644 index 000000000..2e027e097 --- /dev/null +++ b/packages/web-app/src/modules/earn-views/mocks.ts @@ -0,0 +1,1243 @@ +export const getMockedEarningsPerMachine = (daysShowing: number) => { + const shouldShowAmPm = daysShowing === 1 + const shouldShowDateMonth = daysShowing === 7 + const earningsPerMachine24hours = { + 'cd6649d2-1374-4133-a0fd-783e05e7aa02': [ + { + timestamp: '2024-06-18T10:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T10:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T10:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T10:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T11:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T11:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T11:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T11:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T12:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T12:15:00.000Z', + earnings: 0.04214125125, + }, + { + timestamp: '2024-06-18T12:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T12:45:00.000Z', + earnings: 0.012131424125125, + }, + { + timestamp: '2024-06-18T13:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T13:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T13:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T13:45:00.000Z', + earnings: 0.05215215215, + }, + { + timestamp: '2024-06-18T14:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T14:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T14:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T14:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T15:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T15:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T15:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T15:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T16:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T16:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T16:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T16:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T17:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T17:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T17:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T17:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T18:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T18:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T18:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T18:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T19:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T19:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T19:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T19:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T20:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T20:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T20:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T20:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T21:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T21:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T21:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T21:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T23:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T23:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T23:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T23:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T00:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T00:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T00:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T00:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T01:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T01:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T01:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T01:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T02:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T02:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T02:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T02:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T03:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T03:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T03:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T03:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T04:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T04:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T04:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T04:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T05:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T05:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T05:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T05:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T06:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T06:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T06:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T06:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T07:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T07:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T07:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T07:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T08:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T08:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T08:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T08:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T09:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T09:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T09:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T09:45:00.000Z', + earnings: 0, + }, + ], + 'cdfkd234-1374-4133-a0fd-783e05egd24g': [ + { + timestamp: '2024-06-18T10:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T10:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T10:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T10:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T11:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T11:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T11:30:00.000Z', + earnings: 0.05215215215, + }, + { + timestamp: '2024-06-18T11:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T12:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T12:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T12:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T12:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T13:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T13:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T13:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T13:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T14:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T14:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T14:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T14:45:00.000Z', + earnings: 0.05215215215, + }, + { + timestamp: '2024-06-18T15:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T15:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T15:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T15:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T16:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T16:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T16:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T16:45:00.000Z', + earnings: 0.05215215215, + }, + { + timestamp: '2024-06-18T17:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T17:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T17:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T17:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T18:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T18:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T18:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T18:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T19:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T19:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T19:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T19:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T20:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T20:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T20:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T20:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T21:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T21:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T21:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T21:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T23:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T23:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T23:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T23:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T00:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T00:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T00:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T00:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T01:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T01:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T01:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T01:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T02:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T02:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T02:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T02:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T03:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T03:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T03:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T03:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T04:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T04:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T04:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T04:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T05:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T05:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T05:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T05:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T06:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T06:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T06:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T06:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T07:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T07:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T07:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T07:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T08:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T08:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T08:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T08:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T09:00:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T09:15:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T09:30:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-19T09:45:00.000Z', + earnings: 0, + }, + ], + } + const earningsPerMachine7days = { + 'cd6649d2-1374-4133-a0fd-783e05e7aa02': [ + { + timestamp: '2024-06-12T22:45:00.000Z', + earnings: 0.29999238912, + }, + { + timestamp: '2024-06-13T22:45:00.000Z', + earnings: 0.029999238912, + }, + { + timestamp: '2024-06-14T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-15T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-16T22:45:00.000Z', + earnings: 0.00125658384, + }, + { + timestamp: '2024-06-17T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0, + }, + ], + 'cdm649d2-1374-4133-a0fd-783e05e7aa02': [ + { + timestamp: '2024-06-12T22:45:00.000Z', + earnings: 0.5999238912, + }, + { + timestamp: '2024-06-13T22:45:00.000Z', + earnings: 0.029999238912, + }, + { + timestamp: '2024-06-14T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-15T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-16T22:45:00.000Z', + earnings: 0.10125658384, + }, + { + timestamp: '2024-06-17T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0, + }, + ], + 'cd664xd2-1374-4133-a0fd-783e05e7aa02': [ + { + timestamp: '2024-06-12T22:45:00.000Z', + earnings: 0.29999238912, + }, + { + timestamp: '2024-06-13T22:45:00.000Z', + earnings: 0.229999238912, + }, + { + timestamp: '2024-06-14T22:45:00.000Z', + earnings: 0.325325, + }, + { + timestamp: '2024-06-15T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-16T22:45:00.000Z', + earnings: 0.00125658384, + }, + { + timestamp: '2024-06-17T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0, + }, + ], + 'cd6649j2-1374-4133-a0fd-783e05e7aa02': [ + { + timestamp: '2024-06-12T22:45:00.000Z', + earnings: 0.29999238912, + }, + { + timestamp: '2024-06-13T22:45:00.000Z', + earnings: 0.021499238912, + }, + { + timestamp: '2024-06-14T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-15T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-16T22:45:00.000Z', + earnings: 0.00125658384, + }, + { + timestamp: '2024-06-17T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0.4324235, + }, + ], + 'gd6649d2-1374-4133-a0fd-783e05e7aa02': [ + { + timestamp: '2024-06-12T22:45:00.000Z', + earnings: 0.29999238912, + }, + { + timestamp: '2024-06-13T22:45:00.000Z', + earnings: 0.029999238912, + }, + { + timestamp: '2024-06-14T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-15T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-16T22:45:00.000Z', + earnings: 0.52125658384, + }, + { + timestamp: '2024-06-17T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0, + }, + ], + 'cd1649d2-1374-4133-a0fd-783e057aa02': [ + { + timestamp: '2024-06-12T22:45:00.000Z', + earnings: 0.29999238912, + }, + { + timestamp: '2024-06-13T22:45:00.000Z', + earnings: 0.029999238912, + }, + { + timestamp: '2024-06-14T22:45:00.000Z', + earnings: 0.5325325, + }, + { + timestamp: '2024-06-15T22:45:00.000Z', + earnings: 0.21551, + }, + { + timestamp: '2024-06-16T22:45:00.000Z', + earnings: 0.00125658384, + }, + { + timestamp: '2024-06-17T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0, + }, + ], + 'cdfkd234-1374-4133-a0fd-783e05egd24g': [ + { + timestamp: '2024-06-12T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-13T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-14T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-15T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-16T22:45:00.000Z', + earnings: 0.212414, + }, + { + timestamp: '2024-06-17T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0, + }, + ], + } + const earningsPerMachine30days = { + 'cd6649d2-1374-4133-a0fd-783e05e7aa02': [ + { + timestamp: '2024-05-20T22:45:00.000Z', + earnings: 0.100675274272, + }, + { + timestamp: '2024-05-21T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-22T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-23T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-24T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-25T22:45:00.000Z', + earnings: 0.4523523525352, + }, + { + timestamp: '2024-05-26T22:45:00.000Z', + earnings: 0.0000878523786068759, + }, + { + timestamp: '2024-05-27T22:45:00.000Z', + earnings: 0.0024540381142155914, + }, + { + timestamp: '2024-05-28T22:45:00.000Z', + earnings: 0.000239697393818121, + }, + { + timestamp: '2024-05-29T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-30T22:45:00.000Z', + earnings: 0.22224126002, + }, + { + timestamp: '2024-05-31T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-01T22:45:00.000Z', + earnings: 0.003241766201949881, + }, + { + timestamp: '2024-06-02T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-03T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-04T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-05T22:45:00.000Z', + earnings: 0.000216046054874071, + }, + { + timestamp: '2024-06-06T22:45:00.000Z', + earnings: 0.0011643950392236195, + }, + { + timestamp: '2024-06-07T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-08T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-09T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-10T22:45:00.000Z', + earnings: 0.00097026947760907, + }, + { + timestamp: '2024-06-11T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-12T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-13T22:45:00.000Z', + earnings: 0.029999238912, + }, + { + timestamp: '2024-06-14T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-15T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-16T22:45:00.000Z', + earnings: 0.00125658384, + }, + { + timestamp: '2024-06-17T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0, + }, + ], + 'cdfkd234-1374-4133-a0fd-783e05egd24g': [ + { + timestamp: '2024-05-20T22:45:00.000Z', + earnings: 0.000675274272, + }, + { + timestamp: '2024-05-21T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-22T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-23T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-24T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-25T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-26T22:45:00.000Z', + earnings: 0.0000878523786068759, + }, + { + timestamp: '2024-05-27T22:45:00.000Z', + earnings: 0.0024540381142155914, + }, + { + timestamp: '2024-05-28T22:45:00.000Z', + earnings: 0.000239697393818121, + }, + { + timestamp: '2024-05-29T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-30T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-05-31T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-01T22:45:00.000Z', + earnings: 0.003241766201949881, + }, + { + timestamp: '2024-06-02T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-03T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-04T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-05T22:45:00.000Z', + earnings: 0.000216046054874071, + }, + { + timestamp: '2024-06-06T22:45:00.000Z', + earnings: 0.0011643950392236195, + }, + { + timestamp: '2024-06-07T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-08T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-09T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-10T22:45:00.000Z', + earnings: 0.00097026947760907, + }, + { + timestamp: '2024-06-11T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-12T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-13T22:45:00.000Z', + earnings: 0.06235235253532, + }, + { + timestamp: '2024-06-14T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-15T22:45:00.000Z', + earnings: 0.241415626634, + }, + { + timestamp: '2024-06-16T22:45:00.000Z', + earnings: 0.00004124124, + }, + { + timestamp: '2024-06-17T22:45:00.000Z', + earnings: 0, + }, + { + timestamp: '2024-06-18T22:45:00.000Z', + earnings: 0, + }, + ], + } + if (shouldShowAmPm) { + return earningsPerMachine24hours + } else if (shouldShowDateMonth) { + return earningsPerMachine7days + } else { + return earningsPerMachine30days + } +}