Change var isPixValid to bool instead of number

This commit is contained in:
enzoggqs 2022-12-12 14:29:58 -03:00
parent 86ee697b14
commit ce6aced739

View File

@ -16,7 +16,8 @@ const pixQrCode = pix({
pixKey: props.pixTarget ?? "", pixKey: props.pixTarget ?? "",
value: props.tokenValue, value: props.tokenValue,
}); });
const isPixValid = ref<number>(0); const isPixValid = ref<boolean>(false);
const isCodeInputEmpty = ref<boolean>(true);
pixQrCode.base64QrCode().then((code: string) => { pixQrCode.base64QrCode().then((code: string) => {
qrCode.value = code; qrCode.value = code;
@ -34,7 +35,8 @@ const handleInputEvent = (event: any) => {
const validatePix = async (e2eid: any) => { const validatePix = async (e2eid: any) => {
if(e2eid == ''){ if(e2eid == ''){
isPixValid.value = 0; isPixValid.value = false;
isCodeInputEmpty.value = true;
return; return;
} }
var sellerPixKey = props.pixTarget; var sellerPixKey = props.pixTarget;
@ -49,15 +51,18 @@ const validatePix = async (e2eid: any) => {
var resp = await api.post("http://localhost:8000/validate_pix", body_req) var resp = await api.post("http://localhost:8000/validate_pix", body_req)
.catch((reason: Error) => { .catch((reason: Error) => {
console.log('entrou no erro', reason); console.log('entrou no erro', reason);
isPixValid.value = 2; isPixValid.value = false;
isCodeInputEmpty.value = false;
return; return;
}); });
console.log("🚀 ~ file: QrCodeForm.vue:47 ~ validatePix ~ resp", resp); console.log("🚀 ~ file: QrCodeForm.vue:47 ~ validatePix ~ resp", resp);
console.log(resp.status); console.log(resp.status);
isPixValid.value = 1; isCodeInputEmpty.value = false;
isPixValid.value = true;
} else { } else {
isPixValid.value = 0; isCodeInputEmpty.value = false;
isPixValid.value = false;
} }
}; };
</script> </script>
@ -107,8 +112,8 @@ const validatePix = async (e2eid: any) => {
@input="debounce(handleInputEvent, 500)($event)" @input="debounce(handleInputEvent, 500)($event)"
class="text-md w-full box-border p-2 h-6 mb-2 outline-none" class="text-md w-full box-border p-2 h-6 mb-2 outline-none"
/> />
<div class="custom-divide" v-if="isPixValid != 0"></div> <div class="custom-divide" v-if="!isCodeInputEmpty"></div>
<div class="flex flex-col w-full" v-if="isPixValid == 2"> <div class="flex flex-col w-full" v-if="!isPixValid && !isCodeInputEmpty">
<div class="flex items-center h-8"> <div class="flex items-center h-8">
<img <img
alt="Invalid Icon" alt="Invalid Icon"
@ -121,7 +126,7 @@ const validatePix = async (e2eid: any) => {
> >
</div> </div>
</div> </div>
<div class="flex flex-col w-full" v-else-if="isPixValid == 1"> <div class="flex flex-col w-full" v-else-if="isPixValid == true">
<div class="flex items-center h-8"> <div class="flex items-center h-8">
<img <img
alt="Valid Icon" alt="Valid Icon"
@ -136,7 +141,7 @@ const validatePix = async (e2eid: any) => {
</div> </div>
</div> </div>
<CustomButton <CustomButton
:is-disabled="isPixValid != 1" :is-disabled="isPixValid == false"
:text="'Enviar para a rede'" :text="'Enviar para a rede'"
/> />
</div> </div>