frequi_origin/src/components/general/ProfitPill.vue

61 lines
1.7 KiB
Vue
Raw Normal View History

2021-09-04 08:46:53 +00:00
<template>
<div
2022-10-30 13:26:23 +00:00
class="d-flex justify-content-between align-items-center profit-pill ps-2 pe-1"
2021-09-04 09:10:13 +00:00
:class="isProfitable ? 'profit-pill-profit' : ''"
2021-09-04 08:46:53 +00:00
:title="profitDesc"
>
2022-11-30 18:48:46 +00:00
<profit-symbol :profit="(profitRatio || profitAbs) ?? 0" />
2021-10-24 13:11:55 +00:00
<div class="d-flex justify-content-center align-items-center flex-grow-1">
{{ profitRatio !== undefined ? formatPercent(profitRatio, 2) : '' }}
<span
v-if="profitString"
class="ms-1"
2021-10-24 13:11:55 +00:00
:class="profitRatio ? 'small' : ''"
:title="stakeCurrency"
>{{ profitString }}</span
>
</div>
2021-09-04 08:46:53 +00:00
</div>
</template>
2023-02-28 19:43:10 +00:00
<script setup lang="ts">
2022-04-19 18:32:58 +00:00
import { formatPercent, formatPrice } from '@/shared/formatters';
2021-09-04 08:46:53 +00:00
2021-12-17 18:40:15 +00:00
import ProfitSymbol from '@/components/general/ProfitSymbol.vue';
2021-10-24 13:11:55 +00:00
2023-02-28 19:43:10 +00:00
import { computed } from 'vue';
2021-09-04 08:46:53 +00:00
2023-02-28 19:43:10 +00:00
const props = defineProps({
profitRatio: { required: false, default: undefined, type: Number },
profitAbs: { required: false, default: undefined, type: Number },
stakeCurrency: { required: true, type: String },
profitDesc: { required: false, default: '', type: String },
});
const isProfitable = computed(() => {
return (
(props.profitRatio !== undefined && props.profitRatio > 0) ||
(props.profitRatio === undefined && props.profitAbs !== undefined && props.profitAbs > 0)
);
});
2021-09-04 08:46:53 +00:00
2023-02-28 19:43:10 +00:00
const profitString = computed((): string => {
if (props.profitRatio !== undefined && props.profitAbs !== undefined) {
return `(${formatPrice(props.profitAbs, 3)})`;
} else if (props.profitAbs !== undefined) {
return `${formatPrice(props.profitAbs, 3)}`;
}
return '';
2022-04-19 18:32:58 +00:00
});
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>