From da3460ca0f3089ff3a81ff53bf44f1bbd812a858 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 3 Feb 2021 07:53:38 +0100 Subject: [PATCH] Format prices in daily stats --- src/components/ftbot/DailyStats.vue | 9 +++++++-- src/shared/formatters.ts | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/ftbot/DailyStats.vue b/src/components/ftbot/DailyStats.vue index 62b34b6c..f2b2aa74 100644 --- a/src/components/ftbot/DailyStats.vue +++ b/src/components/ftbot/DailyStats.vue @@ -17,6 +17,7 @@ import Vue from 'vue'; import { mapActions, mapState } from 'vuex'; import DailyChart from '@/components/charts/DailyChart.vue'; +import { formatPrice } from '@/shared/formatters'; export default Vue.extend({ name: 'DailyStats', @@ -28,8 +29,12 @@ export default Vue.extend({ dailyFields() { return [ { key: 'date', label: 'Day' }, - { key: 'abs_profit', label: 'Profit' }, - { key: 'fiat_value', label: `In ${this.dailyStats.fiat_display_currency}` }, + { key: 'abs_profit', label: 'Profit', formatter: (value) => formatPrice(value) }, + { + key: 'fiat_value', + label: `In ${this.dailyStats.fiat_display_currency}`, + formatter: (value) => formatPrice(value, 2), + }, { key: 'trade_count', label: 'Trades' }, ]; }, diff --git a/src/shared/formatters.ts b/src/shared/formatters.ts index 0ecebb06..dd9574b9 100644 --- a/src/shared/formatters.ts +++ b/src/shared/formatters.ts @@ -5,8 +5,8 @@ export function formatPercent(value: number, decimals = 3): string { return value ? `${(value * 100).toFixed(decimals)}%` : ''; } -export function formatPrice(value: number): string { - return value ? value.toFixed(8) : ''; +export function formatPrice(value: number, decimals = 8): string { + return value ? value.toFixed(decimals) : ''; } export function dateFromString(datestring: string, format: string): Date {