frequi_origin/src/components/ftbot/ForceBuyForm.vue

131 lines
3.1 KiB
Vue
Raw Normal View History

2020-05-14 16:10:57 +00:00
<template>
<div>
<b-modal
id="forcebuy-modal"
ref="modal"
title="Force buying a pair"
@show="resetForm"
@hidden="resetForm"
@ok="handleBuy"
>
<form ref="form" @submit.stop.prevent="handleSubmit">
<b-form-group label="Pair" label-for="pair-input" invalid-feedback="Pair is required">
<b-form-input
id="pair-input"
v-model="pair"
required
2020-08-31 15:43:44 +00:00
@keydown.enter.native="handleBuy"
2020-05-14 16:10:57 +00:00
></b-form-input>
</b-form-group>
<b-form-group
label="*Price [optional]"
label-for="price-input"
invalid-feedback="Price must be empty or a positive number"
>
<b-form-input
id="price-input"
v-model="price"
type="number"
step="0.00000001"
2020-08-31 15:43:44 +00:00
@keydown.enter.native="handleBuy"
2020-05-14 16:10:57 +00:00
></b-form-input>
</b-form-group>
2021-11-24 19:19:34 +00:00
<b-form-group
v-if="botApiVersion > 1.1"
label="*OrderType"
label-for="ordertype-input"
invalid-feedback="OrderType"
>
<b-select
v-model="ordertype"
class="ml-2"
:options="['market', 'limit']"
style="min-width: 7em"
size="sm"
>
</b-select>
</b-form-group>
2020-05-14 16:10:57 +00:00
</form>
</b-modal>
</div>
</template>
2020-08-09 13:11:47 +00:00
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { namespace } from 'vuex-class';
2021-11-24 19:19:34 +00:00
import { BotState, ForcebuyPayload } from '@/types';
import { BotStoreGetters } from '@/store/modules/ftbot';
import StoreModules from '@/store/storeSubModules';
2020-08-09 13:11:47 +00:00
const ftbot = namespace(StoreModules.ftbot);
2020-08-09 13:11:47 +00:00
@Component({})
export default class ForceBuyForm extends Vue {
pair = '';
price = null;
2021-11-24 19:19:34 +00:00
ordertype?: string = '';
2020-08-09 13:19:16 +00:00
$refs!: {
form: HTMLFormElement;
};
2021-11-24 19:19:34 +00:00
@ftbot.Getter [BotStoreGetters.botState]?: BotState;
@ftbot.Getter [BotStoreGetters.botApiVersion]: number;
2020-09-08 13:45:01 +00:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2020-08-09 13:11:47 +00:00
@ftbot.Action forcebuy!: (payload: ForcebuyPayload) => Promise<string>;
2020-05-14 16:10:57 +00:00
created() {
2020-08-17 05:17:10 +00:00
this.$bvModal.show('forcebuy-modal');
2020-08-09 13:11:47 +00:00
}
close() {
this.$emit('close');
}
checkFormValidity() {
const valid = this.$refs.form.checkValidity();
return valid;
}
handleBuy(bvModalEvt) {
// Prevent modal from closing
bvModalEvt.preventDefault();
// Trigger submit handler
this.handleSubmit();
}
resetForm() {
2021-11-24 19:19:34 +00:00
console.log('resetForm');
2020-08-09 13:11:47 +00:00
this.pair = '';
this.price = null;
2021-11-24 19:19:34 +00:00
if (this.botApiVersion > 1.1) {
this.ordertype = this.botState?.order_types?.forcebuy || this.botState?.order_types?.buy;
}
2020-08-09 13:11:47 +00:00
}
2020-05-14 16:10:57 +00:00
2020-08-09 13:11:47 +00:00
handleSubmit() {
// Exit when the form isn't valid
if (!this.checkFormValidity()) {
return;
}
// call forcebuy
const payload: ForcebuyPayload = { pair: this.pair };
if (this.price) {
payload.price = Number(this.price);
}
2021-11-24 19:19:34 +00:00
if (this.ordertype) {
payload.ordertype = this.ordertype;
}
2020-08-09 13:11:47 +00:00
this.forcebuy(payload);
this.$nextTick(() => {
this.$bvModal.hide('forcebuy-modal');
});
}
}
2020-05-14 16:10:57 +00:00
</script>