frequi_origin/src/components/general/ProfitPill.vue

68 lines
2.0 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>
<script 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
2022-07-07 18:44:19 +00:00
import { defineComponent, computed } from 'vue';
2021-09-04 08:46:53 +00:00
2022-04-19 18:32:58 +00:00
export default defineComponent({
name: 'ProfitPill',
components: { ProfitSymbol },
props: {
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 },
},
setup(props) {
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
2022-04-19 18:32:58 +00:00
const profitString = computed((): string => {
if (props.profitRatio !== undefined && props.profitAbs !== undefined) {
return `(${formatPrice(props.profitAbs, 3)})`;
2022-05-09 05:10:34 +00:00
} else if (props.profitAbs !== undefined) {
return `${formatPrice(props.profitAbs, 3)}`;
2022-04-19 18:32:58 +00:00
}
return '';
});
return { profitString, isProfitable, formatPercent };
},
});
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>