diff --git a/src/components/CustomButton/CustomButton.vue b/src/components/CustomButton/CustomButton.vue index d459688..1994747 100644 --- a/src/components/CustomButton/CustomButton.vue +++ b/src/components/CustomButton/CustomButton.vue @@ -21,6 +21,6 @@ const emit = defineEmits(["buttonClicked"]); diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 790a9a0..199fd68 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -8,7 +8,11 @@ import { useEtherStore } from "@/store/ether"; import QrCodeComponent from "@/components/QrCodeComponent.vue"; import CustomModal from "@/components/CustomModal/CustomModal.vue"; import { storeToRefs } from "pinia"; -import { addLock, releaseLock } from "@/blockchain/buyerMethods"; +import { + addLock, + releaseLock, + withdrawDeposit, +} from "@/blockchain/buyerMethods"; import { updateWalletStatus, listAllTransactionByWalletAddress, @@ -78,23 +82,48 @@ const releaseTransaction = async (e2eId: string) => { ); release.wait(); - await listAllTransactionByWalletAddress( - walletAddress.value.toLowerCase() - ).then((releaseTransactions) => { - if (releaseTransactions) - lastWalletTransactions.value = releaseTransactions; - }); - - const walletDeposits = await listValidDepositTransactionsByWalletAddress( - walletAddress.value - ); - depositList.value = walletDeposits; + await getWalletTransactions(); await updateWalletStatus(); loadingRelease.value = false; } }; +const getWalletTransactions = async () => { + etherStore.setLoadingWalletTransactions(true); + if (walletAddress.value) { + const walletDeposits = await listValidDepositTransactionsByWalletAddress( + walletAddress.value + ); + + const allUserTransactions = await listAllTransactionByWalletAddress( + walletAddress.value + ); + + if (walletDeposits) { + depositList.value = walletDeposits; + } + if (allUserTransactions) { + lastWalletTransactions.value = allUserTransactions; + } + } + etherStore.setLoadingWalletTransactions(false); +}; + +const callWithdraw = async (amount: string) => { + if (amount) { + etherStore.setLoadingWalletTransactions(true); + const withdraw = await withdrawDeposit(amount); + if (withdraw) { + console.log("Saque realizado!"); + await getWalletTransactions(); + } else { + console.log("Não foi possível realizar o saque!"); + } + etherStore.setLoadingWalletTransactions(false); + } +}; + const checkForUnreleasedLocks = async (): Promise => { const walletLocks = await checkUnreleasedLock(walletAddress.value); if (walletLocks) { @@ -149,16 +178,22 @@ onMounted(async () => { />
- - +
+ +
+ Gerenciar transações +
+ +
{ loadingWithdraw.value = true; const withdraw = await withdrawDeposit(amount); if (withdraw) { - alert("Saque realizado!"); - await updateRemaining(); + console.log("Saque realizado!"); + await getWalletTransactions(); loadingWithdraw.value = false; } else { - alert("Não foi possível realizar o saque!"); + console.log("Não foi possível realizar o saque!"); loadingWithdraw.value = false; } } }; -const updateRemaining = async () => { - const walletDeposits = await listValidDepositTransactionsByWalletAddress( - walletAddress.value - ); - depositList.value = walletDeposits; - - const allUserTransactions = await listAllTransactionByWalletAddress( - walletAddress.value - ); - transactionsList.value = allUserTransactions; -}; - const getWalletTransactions = async () => { etherStore.setLoadingWalletTransactions(true); if (walletAddress.value) {