emit e2eid from buy step to home view
This commit is contained in:
parent
409f22a8cf
commit
4aec263463
@ -1,23 +1,17 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import CustomButton from "@/components/CustomButton.vue";
|
import CustomButton from "@/components/CustomButton.vue";
|
||||||
import { useEtherStore } from "@/store/ether";
|
import { useEtherStore } from "@/store/ether";
|
||||||
import { storeToRefs } from "pinia";
|
|
||||||
import blockchain from "../utils/blockchain";
|
import blockchain from "../utils/blockchain";
|
||||||
// Store reference
|
|
||||||
const etherStore = useEtherStore();
|
|
||||||
|
|
||||||
const { walletAddress } = storeToRefs(etherStore);
|
|
||||||
|
|
||||||
const lastDeposits = await blockchain.listTransactionByWalletAddress(walletAddress.value.toLowerCase())
|
|
||||||
|
|
||||||
const openEtherscanUrl = (url: string) => {
|
|
||||||
window.open(url, "_blank")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// props and store references
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
lastWalletTransactions: Array,
|
||||||
tokenAmmount: Number,
|
tokenAmmount: Number,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const openEtherscanUrl = (url: string) => {
|
||||||
|
window.open(url, "_blank");
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -70,10 +64,31 @@ const props = defineProps({
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="blur-container">
|
<div class="blur-container">
|
||||||
<div class="flex flex-row justify-between w-full bg-white p-5 rounded-lg" v-for="deposit in lastDeposits" :key="deposit?.blockNumber">
|
<div
|
||||||
<p class="last-deposit-info">{{blockchain.formatBigNumber(deposit?.args.amount)}} BRZ</p>
|
class="flex flex-row justify-between w-full bg-white p-5 rounded-lg"
|
||||||
<p class="last-deposit-info">{{deposit?.event == 'DepositAdded' ? 'Depósito' : deposit?.event == 'LockAdded' ? 'Reserva' : 'Compra'}}</p>
|
v-for="deposit in lastWalletTransactions"
|
||||||
<div class="flex gap-2 cursor-pointer items-center" @click="openEtherscanUrl(`https://etherscan.io/tx/${deposit?.transactionHash}`)">
|
:key="deposit?.blockNumber"
|
||||||
|
>
|
||||||
|
<p class="last-deposit-info">
|
||||||
|
{{ blockchain.formatBigNumber(deposit?.args.amount) }} BRZ
|
||||||
|
</p>
|
||||||
|
<p class="last-deposit-info">
|
||||||
|
{{
|
||||||
|
deposit?.event == "DepositAdded"
|
||||||
|
? "Depósito"
|
||||||
|
: deposit?.event == "LockAdded"
|
||||||
|
? "Reserva"
|
||||||
|
: "Compra"
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
class="flex gap-2 cursor-pointer items-center"
|
||||||
|
@click="
|
||||||
|
openEtherscanUrl(
|
||||||
|
`https://etherscan.io/tx/${deposit?.transactionHash}`
|
||||||
|
)
|
||||||
|
"
|
||||||
|
>
|
||||||
<p class="last-deposit-info">Etherscan</p>
|
<p class="last-deposit-info">Etherscan</p>
|
||||||
<img alt="Redirect image" src="@/assets/redirect.svg" />
|
<img alt="Redirect image" src="@/assets/redirect.svg" />
|
||||||
</div>
|
</div>
|
||||||
@ -82,11 +97,13 @@ const props = defineProps({
|
|||||||
type="button"
|
type="button"
|
||||||
class="text-white mt-2"
|
class="text-white mt-2"
|
||||||
@click="() => {}"
|
@click="() => {}"
|
||||||
v-if="(lastDeposits?.length != 0)"
|
v-if="lastWalletTransactions?.length != 0"
|
||||||
>
|
>
|
||||||
Carregar mais
|
Carregar mais
|
||||||
</button>
|
</button>
|
||||||
<p class="font-bold" v-if="(lastDeposits?.length == 0)">Não há nenhuma transação anterior</p>
|
<p class="font-bold" v-if="lastWalletTransactions?.length == 0">
|
||||||
|
Não há nenhuma transação anterior
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -97,7 +114,7 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
@apply text-gray-900
|
@apply text-gray-900;
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-container {
|
.text-container {
|
||||||
@ -116,7 +133,7 @@ p {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.last-deposit-info {
|
.last-deposit-info {
|
||||||
@apply font-medium text-base
|
@apply font-medium text-base;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="number"] {
|
input[type="number"] {
|
||||||
|
@ -5,6 +5,7 @@ import { debounce } from "@/utils/debounce";
|
|||||||
import CustomButton from "./CustomButton.vue";
|
import CustomButton from "./CustomButton.vue";
|
||||||
import api from "../services/index";
|
import api from "../services/index";
|
||||||
|
|
||||||
|
// props and store references
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
pixTarget: String,
|
pixTarget: String,
|
||||||
tokenValue: Number,
|
tokenValue: Number,
|
||||||
@ -12,13 +13,17 @@ const props = defineProps({
|
|||||||
|
|
||||||
const qrCode = ref<string>("");
|
const qrCode = ref<string>("");
|
||||||
const qrCodePayload = ref<string>("");
|
const qrCodePayload = ref<string>("");
|
||||||
|
const isPixValid = ref<boolean>(false);
|
||||||
|
const isCodeInputEmpty = ref<boolean>(true);
|
||||||
|
const e2eId = ref<string>("");
|
||||||
|
|
||||||
|
// Emits
|
||||||
|
const emit = defineEmits(["pixValidated"]);
|
||||||
|
|
||||||
const pixQrCode = pix({
|
const pixQrCode = pix({
|
||||||
pixKey: props.pixTarget ?? "",
|
pixKey: props.pixTarget ?? "",
|
||||||
value: props.tokenValue,
|
value: props.tokenValue,
|
||||||
});
|
});
|
||||||
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;
|
||||||
});
|
});
|
||||||
@ -27,12 +32,12 @@ qrCodePayload.value = pixQrCode.payload();
|
|||||||
|
|
||||||
const handleInputEvent = (event: any) => {
|
const handleInputEvent = (event: any) => {
|
||||||
const { value } = event.target;
|
const { value } = event.target;
|
||||||
|
e2eId.value = value;
|
||||||
validatePix(value);
|
validatePix();
|
||||||
};
|
};
|
||||||
|
|
||||||
const validatePix = async (e2eid: any) => {
|
const validatePix = async () => {
|
||||||
if (e2eid == "") {
|
if (e2eId.value == "") {
|
||||||
isPixValid.value = false;
|
isPixValid.value = false;
|
||||||
isCodeInputEmpty.value = true;
|
isCodeInputEmpty.value = true;
|
||||||
return;
|
return;
|
||||||
@ -42,7 +47,7 @@ const validatePix = async (e2eid: any) => {
|
|||||||
|
|
||||||
if (sellerPixKey && transactionValue) {
|
if (sellerPixKey && transactionValue) {
|
||||||
var body_req = {
|
var body_req = {
|
||||||
e2e_id: e2eid,
|
e2e_id: e2eId.value,
|
||||||
pix_key: sellerPixKey,
|
pix_key: sellerPixKey,
|
||||||
pix_value: transactionValue,
|
pix_value: transactionValue,
|
||||||
};
|
};
|
||||||
@ -64,6 +69,7 @@ const validatePix = async (e2eid: any) => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="page">
|
<div class="page">
|
||||||
|
<h2>{{e2eId}}</h2>
|
||||||
<div class="text-container">
|
<div class="text-container">
|
||||||
<span class="text font-extrabold text-2xl max-w-[30rem]">
|
<span class="text font-extrabold text-2xl max-w-[30rem]">
|
||||||
Utilize o QR Code ou copie o código para realizar o Pix
|
Utilize o QR Code ou copie o código para realizar o Pix
|
||||||
@ -141,6 +147,7 @@ const validatePix = async (e2eid: any) => {
|
|||||||
<CustomButton
|
<CustomButton
|
||||||
:is-disabled="isPixValid == false"
|
:is-disabled="isPixValid == false"
|
||||||
:text="'Enviar para a rede'"
|
:text="'Enviar para a rede'"
|
||||||
|
@button-clicked="emit('pixValidated', e2eId)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -222,6 +222,7 @@ const addLock = async (depositId: Number, amount: Number) => {
|
|||||||
lock.wait();
|
lock.wait();
|
||||||
|
|
||||||
updateLockAddedEvents();
|
updateLockAddedEvents();
|
||||||
|
return lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get specific lock data by its ID
|
// Get specific lock data by its ID
|
||||||
@ -270,6 +271,7 @@ const releaseLock = async (
|
|||||||
release.wait();
|
release.wait();
|
||||||
|
|
||||||
updateLockReleasedEvents();
|
updateLockReleasedEvents();
|
||||||
|
return release
|
||||||
};
|
};
|
||||||
|
|
||||||
// Formatting methods
|
// Formatting methods
|
||||||
|
@ -21,10 +21,11 @@ enum Step {
|
|||||||
|
|
||||||
// States
|
// States
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
const { loadingLock, walletAddress } = storeToRefs(etherStore);
|
const { loadingLock, walletAddress, locksAddedList } = storeToRefs(etherStore);
|
||||||
const flowStep = ref<Step>(Step.Search);
|
const flowStep = ref<Step>(Step.Search);
|
||||||
const pixTarget = ref<string>("");
|
const pixTarget = ref<string>("");
|
||||||
const tokenAmmount = ref<number>();
|
const tokenAmount = ref<number>();
|
||||||
|
const lockTransactionHash = ref<string>("");
|
||||||
const loadingRelease = ref<Boolean>(false);
|
const loadingRelease = ref<Boolean>(false);
|
||||||
const lastWalletTransactions = ref<any[] | undefined>([]);
|
const lastWalletTransactions = ref<any[] | undefined>([]);
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ const confirmBuyClick = async ({ selectedDeposit, tokenValue }: any) => {
|
|||||||
await blockchain
|
await blockchain
|
||||||
.mapDeposits(depositId)
|
.mapDeposits(depositId)
|
||||||
.then((deposit) => (depositDetail = deposit));
|
.then((deposit) => (depositDetail = deposit));
|
||||||
tokenAmmount.value = tokenValue;
|
tokenAmount.value = tokenValue;
|
||||||
pixTarget.value = depositDetail?.pixTarget;
|
pixTarget.value = depositDetail?.pixTarget;
|
||||||
|
|
||||||
// Makes lock with deposit ID and the Amount
|
// Makes lock with deposit ID and the Amount
|
||||||
@ -44,7 +45,12 @@ const confirmBuyClick = async ({ selectedDeposit, tokenValue }: any) => {
|
|||||||
flowStep.value = Step.Buy;
|
flowStep.value = Step.Buy;
|
||||||
etherStore.setLoadingLock(true);
|
etherStore.setLoadingLock(true);
|
||||||
|
|
||||||
await blockchain.addLock(depositId, tokenValue).catch(() => {
|
await blockchain.addLock(depositId, tokenValue)
|
||||||
|
.then((lock) => {
|
||||||
|
console.log(lock)
|
||||||
|
lockTransactionHash.value = lock.hash
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
flowStep.value = Step.Search;
|
flowStep.value = Step.Search;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -67,17 +73,24 @@ const confirmBuyClick = async ({ selectedDeposit, tokenValue }: any) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const releaseTransaction = async ({ pixE2Eid }: any) => {
|
const releaseTransaction = async ({ e2eId }: any) => {
|
||||||
console.log("release: ", pixE2Eid);
|
console.log(e2eId);
|
||||||
flowStep.value = Step.List;
|
flowStep.value = Step.List;
|
||||||
loadingRelease.value = true;
|
loadingRelease.value = true;
|
||||||
|
console.log(lockTransactionHash.value);
|
||||||
|
console.log(locksAddedList.value);
|
||||||
|
|
||||||
|
// make lock release
|
||||||
|
// need to find lockId
|
||||||
|
// const release = await blockchain.releaseLock(pixTarget.value, String(tokenAmount.value), Number(e2eId), lockTransactionHash.value)
|
||||||
|
// console.log(release);
|
||||||
|
|
||||||
lastWalletTransactions.value =
|
lastWalletTransactions.value =
|
||||||
await blockchain.listTransactionByWalletAddress(
|
await blockchain.listTransactionByWalletAddress(
|
||||||
walletAddress.value.toLowerCase()
|
walletAddress.value.toLowerCase()
|
||||||
);
|
);
|
||||||
|
|
||||||
setTimeout(() => (loadingRelease.value = false), 2000);
|
loadingRelease.value = false
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -89,7 +102,7 @@ const releaseTransaction = async ({ pixE2Eid }: any) => {
|
|||||||
<div v-if="flowStep == Step.Buy">
|
<div v-if="flowStep == Step.Buy">
|
||||||
<QrCodeComponent
|
<QrCodeComponent
|
||||||
:pixTarget="pixTarget"
|
:pixTarget="pixTarget"
|
||||||
:tokenValue="tokenAmmount"
|
:tokenValue="tokenAmount"
|
||||||
@pix-validated="releaseTransaction"
|
@pix-validated="releaseTransaction"
|
||||||
v-if="!loadingLock"
|
v-if="!loadingLock"
|
||||||
/>
|
/>
|
||||||
@ -99,7 +112,7 @@ const releaseTransaction = async ({ pixE2Eid }: any) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="flowStep == Step.List">
|
<div v-if="flowStep == Step.List">
|
||||||
<ListComponent v-if="!loadingRelease" :tokenAmmount="tokenAmmount" />
|
<ListComponent v-if="!loadingRelease" :tokenAmount="tokenAmount" :last-wallet-transactions="lastWalletTransactions" />
|
||||||
<ValidationComponent
|
<ValidationComponent
|
||||||
v-if="loadingRelease"
|
v-if="loadingRelease"
|
||||||
:message="'A transação está sendo enviada para a rede. Em breve os tokens serão depositados em sua carteira.'"
|
:message="'A transação está sendo enviada para a rede. Em breve os tokens serão depositados em sua carteira.'"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user