frequi_origin/src/components/general/ProfitPill.vue

63 lines
1.6 KiB
Vue
Raw Normal View History

2021-09-04 08:46:53 +00:00
<template>
<div
2021-09-18 14:45:11 +00:00
class="d-flex justify-content-center align-items-center profit-pill px-2"
2021-09-04 09:10:13 +00:00
:class="isProfitable ? 'profit-pill-profit' : ''"
2021-09-04 08:46:53 +00:00
:title="profitDesc"
>
{{ profitRatio !== undefined ? formatPercent(profitRatio, 2) : '' }}
2021-10-11 18:58:13 +00:00
<span
v-if="profitString"
class="ml-1"
:class="profitRatio ? 'small' : ''"
:title="stakeCurrency"
>{{ profitString }}</span
>
2021-09-04 08:46:53 +00:00
</div>
</template>
<script lang="ts">
import { formatPercent, formatPrice, timestampms } from '@/shared/formatters';
import { Component, Prop, Vue } from 'vue-property-decorator';
@Component({})
export default class ProfitPill extends Vue {
2021-09-04 09:10:13 +00:00
@Prop({ required: false, default: undefined, type: Number }) profitRatio?: number;
2021-09-04 08:46:53 +00:00
2021-10-11 18:58:13 +00:00
@Prop({ required: false, default: undefined, type: Number }) profitAbs?: number;
2021-09-04 08:46:53 +00:00
@Prop({ required: true, type: String }) stakeCurrency!: string;
2021-09-04 09:10:13 +00:00
@Prop({ required: false, default: '', type: String }) profitDesc!: string;
2021-09-04 08:46:53 +00:00
formatPercent = formatPercent;
timestampms = timestampms;
formatPrice = formatPrice;
2021-09-04 09:10:13 +00:00
get isProfitable() {
return (
(this.profitRatio !== undefined && this.profitRatio > 0) ||
2021-10-11 18:58:13 +00:00
(this.profitRatio === undefined && this.profitAbs !== undefined && this.profitAbs > 0)
2021-09-04 09:10:13 +00:00
);
}
2021-10-11 18:58:13 +00:00
get profitString(): string {
if (this.profitRatio !== undefined && this.profitAbs !== undefined) {
return `(${formatPrice(this.profitAbs, 3)})`;
}
return '';
}
2021-09-04 08:46:53 +00:00
}
</script>
<style scoped lang="scss">
.profit-pill {
2021-09-04 09:20:55 +00:00
background: $color-loss;
2021-09-04 08:46:53 +00:00
border-radius: 6px;
}
.profit-pill-profit {
2021-09-04 09:20:55 +00:00
background: $color-profit;
2021-09-04 08:46:53 +00:00
}
</style>