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
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">
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-04-19 18:32:58 +00:00
import { defineComponent, computed } from '@vue/composition-api';
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>