Format prices in daily stats

This commit is contained in:
Matthias 2021-02-03 07:53:38 +01:00
parent f6ea46712f
commit da3460ca0f
2 changed files with 9 additions and 4 deletions

View File

@ -17,6 +17,7 @@
import Vue from 'vue'; import Vue from 'vue';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import DailyChart from '@/components/charts/DailyChart.vue'; import DailyChart from '@/components/charts/DailyChart.vue';
import { formatPrice } from '@/shared/formatters';
export default Vue.extend({ export default Vue.extend({
name: 'DailyStats', name: 'DailyStats',
@ -28,8 +29,12 @@ export default Vue.extend({
dailyFields() { dailyFields() {
return [ return [
{ key: 'date', label: 'Day' }, { key: 'date', label: 'Day' },
{ key: 'abs_profit', label: 'Profit' }, { key: 'abs_profit', label: 'Profit', formatter: (value) => formatPrice(value) },
{ key: 'fiat_value', label: `In ${this.dailyStats.fiat_display_currency}` }, {
key: 'fiat_value',
label: `In ${this.dailyStats.fiat_display_currency}`,
formatter: (value) => formatPrice(value, 2),
},
{ key: 'trade_count', label: 'Trades' }, { key: 'trade_count', label: 'Trades' },
]; ];
}, },

View File

@ -5,8 +5,8 @@ export function formatPercent(value: number, decimals = 3): string {
return value ? `${(value * 100).toFixed(decimals)}%` : ''; return value ? `${(value * 100).toFixed(decimals)}%` : '';
} }
export function formatPrice(value: number): string { export function formatPrice(value: number, decimals = 8): string {
return value ? value.toFixed(8) : ''; return value ? value.toFixed(decimals) : '';
} }
export function dateFromString(datestring: string, format: string): Date { export function dateFromString(datestring: string, format: string): Date {