Improve code quality

This commit is contained in:
enzoggqs 2022-12-12 14:20:17 -03:00
parent 87de79201c
commit 3e770d0a08

View File

@ -10,16 +10,13 @@ const props = defineProps({
tokenValue: Number, tokenValue: Number,
}); });
console.log(props.tokenValue);
console.log(props.pixTarget);
const qrCode = ref<string>(""); const qrCode = ref<string>("");
const qrCodePayload = ref<string>(""); const qrCodePayload = ref<string>("");
const pixQrCode = pix({ const pixQrCode = pix({
pixKey: props.pixTarget ?? "", pixKey: props.pixTarget ?? "",
value: props.tokenValue, value: props.tokenValue,
}); });
const pixIsValid = ref<number>(0); const isPixValid = ref<number>(0);
pixQrCode.base64QrCode().then((code: string) => { pixQrCode.base64QrCode().then((code: string) => {
qrCode.value = code; qrCode.value = code;
@ -33,10 +30,9 @@ const handleInputEvent = (event: any) => {
validatePix(value); validatePix(value);
}; };
const validatePix = async (value: any) => { const validatePix = async (e2eid: any) => {
console.log(value); if(e2eid == ''){
if(value == ''){ isPixValid.value = 0;
pixIsValid.value = 0;
return; return;
} }
var sellerPixKey = props.pixTarget; var sellerPixKey = props.pixTarget;
@ -44,22 +40,22 @@ const validatePix = async (value: any) => {
if(sellerPixKey && transactionValue){ if(sellerPixKey && transactionValue){
var body_req = { var body_req = {
e2e_id: value, e2e_id: e2eid,
pix_key: sellerPixKey, pix_key: sellerPixKey,
pix_value: transactionValue, pix_value: transactionValue,
}; };
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);
pixIsValid.value = 2; isPixValid.value = 2;
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);
pixIsValid.value = 1; isPixValid.value = 1;
} else { } else {
pixIsValid.value = 0; isPixValid.value = 0;
} }
}; };
</script> </script>
@ -91,7 +87,7 @@ const validatePix = async (value: any) => {
height="16" height="16"
class="pt-2 mb-5 cursor-pointer" class="pt-2 mb-5 cursor-pointer"
/> />
<span class="text-center text-xs text-start"> <span class="text-xs text-start">
<strong>ATENÇÃO!</strong> A transação será processada após inserir <strong>ATENÇÃO!</strong> A transação será processada após inserir
o código de autenticação. Caso contrário não conseguiremos comprovar o o código de autenticação. Caso contrário não conseguiremos comprovar o
seu depósito e não será possível transferir os tokens para sua seu depósito e não será possível transferir os tokens para sua
@ -105,10 +101,10 @@ const validatePix = async (value: any) => {
type="text" type="text"
placeholder="Digite o código do comprovante PIX" placeholder="Digite o código do comprovante PIX"
@input="debounce(handleInputEvent, 500)($event)" @input="debounce(handleInputEvent, 500)($event)"
class="text-md box-border w-full box-border p-2 h-6 mb-2" class="text-md w-full box-border p-2 h-6 mb-2 outline-none"
/> />
<div class="flex flex-col w-full" v-if="pixIsValid == 2"> <div class="custom-divide" v-if="isPixValid != 0"></div>
<div class="custom-divide"></div> <div class="flex flex-col w-full" v-if="isPixValid == 2">
<div class="flex items-center h-8"> <div class="flex items-center h-8">
<img <img
alt="Invalid Icon" alt="Invalid Icon"
@ -121,8 +117,7 @@ const validatePix = async (value: any) => {
> >
</div> </div>
</div> </div>
<div class="flex flex-col w-full" v-else-if="pixIsValid == 1"> <div class="flex flex-col w-full" v-else-if="isPixValid == 1">
<div class="custom-divide"></div>
<div class="flex items-center h-8"> <div class="flex items-center h-8">
<img <img
alt="Valid Icon" alt="Valid Icon"
@ -137,7 +132,7 @@ const validatePix = async (value: any) => {
</div> </div>
</div> </div>
<CustomButton <CustomButton
:is-disabled="!(pixIsValid == 1)" :is-disabled="isPixValid != 1"
:text="'Enviar para a rede'" :text="'Enviar para a rede'"
/> />
</div> </div>