frequi_origin/src/components/general/ProfitPill.vue

69 lines
1.9 KiB
Vue
Raw Normal View History

2021-09-04 08:46:53 +00:00
<template>
<div
2021-10-24 13:11:55 +00:00
class="d-flex justify-content-between align-items-center profit-pill pl-2 pr-1"
2021-09-04 09:10:13 +00:00
:class="isProfitable ? 'profit-pill-profit' : ''"
2021-09-04 08:46:53 +00:00
:title="profitDesc"
>
2021-10-24 13:11:55 +00:00
<profit-symbol :profit="profitRatio || profitAbs" />
<div class="d-flex justify-content-center align-items-center flex-grow-1">
{{ profitRatio !== undefined ? formatPercent(profitRatio, 2) : '' }}
<span
v-if="profitString"
class="ml-1"
:class="profitRatio ? 'small' : ''"
:title="stakeCurrency"
>{{ profitString }}</span
>
</div>
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';
2021-10-24 13:11:55 +00:00
import ProfitSymbol from '@/components/ftbot/ProfitSymbol.vue';
@Component({ components: { ProfitSymbol } })
2021-09-04 08:46:53 +00:00
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-10-24 07:24:22 +00:00
border: 2px solid $color-loss;
2021-09-04 08:46:53 +00:00
border-radius: 6px;
}
.profit-pill-profit {
2021-10-24 07:24:22 +00:00
border: 2px solid $color-profit;
2021-09-04 08:46:53 +00:00
}
</style>