ForceExitForm -> script setup

This commit is contained in:
Matthias 2023-02-15 07:05:27 +01:00
parent 3884bc3f68
commit 9b009e8158

View File

@ -60,85 +60,70 @@
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { useBotStore } from '@/stores/ftbotwrapper'; import { useBotStore } from '@/stores/ftbotwrapper';
import { ForceSellPayload, Trade } from '@/types'; import { ForceSellPayload, Trade } from '@/types';
import { defineComponent, ref, computed } from 'vue'; import { ref, computed } from 'vue';
export default defineComponent({ const props = defineProps({
name: 'ForceExitForm', trade: {
props: { type: Object as () => Trade,
trade: { required: true,
type: Object as () => Trade,
required: true,
},
modelValue: { required: true, default: false, type: Boolean },
}, },
emits: ['update:modelValue'], modelValue: { required: true, default: false, type: Boolean },
setup(props, { emit }) { });
const botStore = useBotStore(); const emit = defineEmits(['update:modelValue']);
const botStore = useBotStore();
const form = ref<HTMLFormElement>(); const form = ref<HTMLFormElement>();
const amount = ref<number | undefined>(undefined); const amount = ref<number | undefined>(undefined);
const ordertype = ref('limit'); const ordertype = ref('limit');
const checkFormValidity = () => { const checkFormValidity = () => {
const valid = form.value?.checkValidity(); const valid = form.value?.checkValidity();
return valid; return valid;
}; };
const model = computed({ const model = computed({
get() { get() {
return props.modelValue; return props.modelValue;
}, },
set(value: boolean) { set(value: boolean) {
emit('update:modelValue', value); emit('update:modelValue', value);
},
});
const handleSubmit = () => {
// Exit when the form isn't valid
if (!checkFormValidity()) {
return;
}
// call forceentry
const payload: ForceSellPayload = { tradeid: String(props.trade.trade_id) };
if (ordertype.value) {
payload.ordertype = ordertype.value;
}
if (amount.value) {
payload.amount = amount.value;
}
botStore.activeBot.forceexit(payload);
model.value = false;
};
const resetForm = () => {
amount.value = props.trade.amount;
if (botStore.activeBot.botApiVersion > 1.1) {
ordertype.value =
botStore.activeBot.botState?.order_types?.force_exit ||
botStore.activeBot.botState?.order_types?.exit ||
'limit';
}
};
const handleEntry = () => {
// Trigger submit handler
handleSubmit();
};
return {
handleSubmit,
botStore,
form,
handleEntry,
resetForm,
amount,
ordertype,
model,
};
}, },
}); });
const handleSubmit = () => {
// Exit when the form isn't valid
if (!checkFormValidity()) {
return;
}
// call forceentry
const payload: ForceSellPayload = { tradeid: String(props.trade.trade_id) };
if (ordertype.value) {
payload.ordertype = ordertype.value;
}
if (amount.value) {
payload.amount = amount.value;
}
botStore.activeBot.forceexit(payload);
model.value = false;
};
const resetForm = () => {
amount.value = props.trade.amount;
if (botStore.activeBot.botApiVersion > 1.1) {
ordertype.value =
botStore.activeBot.botState?.order_types?.force_exit ||
botStore.activeBot.botState?.order_types?.exit ||
'limit';
}
};
const handleEntry = () => {
// Trigger submit handler
handleSubmit();
};
</script> </script>