composition: some more components

This commit is contained in:
Matthias 2022-04-19 20:32:58 +02:00
parent b272c73e89
commit fe3075e6d3
3 changed files with 68 additions and 74 deletions

View File

@ -99,29 +99,25 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
import { formatPercent, formatPriceCurrency, formatPrice, timestampms } from '@/shared/formatters'; import { formatPercent, formatPriceCurrency, formatPrice, timestampms } from '@/shared/formatters';
import ValuePair from '@/components/general/ValuePair.vue'; import ValuePair from '@/components/general/ValuePair.vue';
import TradeProfit from '@/components/ftbot/TradeProfit.vue'; import TradeProfit from '@/components/ftbot/TradeProfit.vue';
import DateTimeTZ from '@/components/general/DateTimeTZ.vue'; import DateTimeTZ from '@/components/general/DateTimeTZ.vue';
import { Trade } from '@/types'; import { Trade } from '@/types';
@Component({ import { defineComponent } from '@vue/composition-api';
export default defineComponent({
name: 'TradeDetail',
components: { ValuePair, TradeProfit, DateTimeTZ }, components: { ValuePair, TradeProfit, DateTimeTZ },
}) props: {
export default class TradeDetail extends Vue { trade: { required: true, type: Object as () => Trade },
@Prop({ type: Object, required: true }) trade!: Trade; stakeCurrency: { required: true, type: String },
},
@Prop({ type: String, required: true }) stakeCurrency!: string; setup() {
return { timestampms, formatPercent, formatPrice, formatPriceCurrency };
timestampms = timestampms; },
});
formatPercent = formatPercent;
formatPrice = formatPrice;
formatPriceCurrency = formatPriceCurrency;
}
</script> </script>
<style scoped> <style scoped>
.detail-header { .detail-header {

View File

@ -4,38 +4,39 @@
<script lang="ts"> <script lang="ts">
import { timestampms, timestampmsWithTimezone, timestampToDateString } from '@/shared/formatters'; import { timestampms, timestampmsWithTimezone, timestampToDateString } from '@/shared/formatters';
import { Component, Prop, Vue } from 'vue-property-decorator';
@Component({}) import { defineComponent, computed } from '@vue/composition-api';
export default class DateTimeTZ extends Vue {
@Prop({ required: true, type: Number }) date!: number;
@Prop({ required: false, type: Boolean, default: false }) showTimezone!: boolean; export default defineComponent({
name: 'DateTimeTZ',
@Prop({ required: false, type: Boolean, default: false }) dateOnly!: boolean; props: {
date: { required: true, type: Number },
timestampms = timestampms; showTimezone: { required: false, type: Boolean, default: false },
dateOnly: { required: false, type: Boolean, default: false },
get formattedDate(): string { },
if (this.dateOnly) { setup(props) {
return timestampToDateString(this.date); const formattedDate = computed((): string => {
if (props.dateOnly) {
return timestampToDateString(props.date);
} }
if (this.showTimezone) { if (props.showTimezone) {
return timestampmsWithTimezone(this.date); return timestampmsWithTimezone(props.date);
}
return timestampms(this.date);
} }
return timestampms(props.date);
});
get timezoneTooltip(): string { const timezoneTooltip = computed((): string => {
const time1 = timestampmsWithTimezone(this.date); const time1 = timestampmsWithTimezone(props.date);
const timeUTC = timestampmsWithTimezone(this.date, 'UTC'); const timeUTC = timestampmsWithTimezone(props.date, 'UTC');
if (time1 === timeUTC) { if (time1 === timeUTC) {
return timeUTC; return timeUTC;
} }
return `${time1}\n${timeUTC}`; return `${time1}\n${timeUTC}`;
} });
} return { formattedDate, timezoneTooltip };
},
});
</script> </script>
<style scoped></style> <style scoped></style>

View File

@ -20,41 +20,38 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { formatPercent, formatPrice, timestampms } from '@/shared/formatters'; import { formatPercent, formatPrice } from '@/shared/formatters';
import { Component, Prop, Vue } from 'vue-property-decorator';
import ProfitSymbol from '@/components/general/ProfitSymbol.vue'; import ProfitSymbol from '@/components/general/ProfitSymbol.vue';
@Component({ components: { ProfitSymbol } }) import { defineComponent, computed } from '@vue/composition-api';
export default class ProfitPill extends Vue {
@Prop({ required: false, default: undefined, type: Number }) profitRatio?: number;
@Prop({ required: false, default: undefined, type: Number }) profitAbs?: number; export default defineComponent({
name: 'ProfitPill',
@Prop({ required: true, type: String }) stakeCurrency!: string; components: { ProfitSymbol },
props: {
@Prop({ required: false, default: '', type: String }) profitDesc!: string; profitRatio: { required: false, default: undefined, type: Number },
profitAbs: { required: false, default: undefined, type: Number },
formatPercent = formatPercent; stakeCurrency: { required: true, type: String },
profitDesc: { required: false, default: '', type: String },
timestampms = timestampms; },
setup(props) {
formatPrice = formatPrice; const isProfitable = computed(() => {
get isProfitable() {
return ( return (
(this.profitRatio !== undefined && this.profitRatio > 0) || (props.profitRatio !== undefined && props.profitRatio > 0) ||
(this.profitRatio === undefined && this.profitAbs !== undefined && this.profitAbs > 0) (props.profitRatio === undefined && props.profitAbs !== undefined && props.profitAbs > 0)
); );
} });
get profitString(): string { const profitString = computed((): string => {
if (this.profitRatio !== undefined && this.profitAbs !== undefined) { if (props.profitRatio !== undefined && props.profitAbs !== undefined) {
return `(${formatPrice(this.profitAbs, 3)})`; return `(${formatPrice(props.profitAbs, 3)})`;
} }
return ''; return '';
} });
} return { profitString, isProfitable, formatPercent };
},
});
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">