diff --git a/src/components/QrCodeComponent.vue b/src/components/QrCodeComponent.vue index 7ed347a..cf94576 100644 --- a/src/components/QrCodeComponent.vue +++ b/src/components/QrCodeComponent.vue @@ -154,11 +154,6 @@ const validatePix = async (): Promise => { @button-clicked="emit('pixValidated', e2eId)" /> - diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 820d7c3..c92b1f9 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -2,7 +2,7 @@ import SearchComponent from "@/components/SearchComponent.vue"; import LoadingComponent from "@/components/LoadingComponent/LoadingComponent.vue"; import BuyConfirmedComponent from "@/components/BuyConfirmedComponent/BuyConfirmedComponent.vue"; -import { ref, onMounted } from "vue"; +import { ref, onMounted, watch } from "vue"; import { useEtherStore } from "@/store/ether"; import QrCodeComponent from "@/components/QrCodeComponent.vue"; import CustomModal from "@/components/CustomModal.vue"; @@ -11,6 +11,7 @@ import { addLock, releaseLock } from "@/blockchain/buyerMethods"; import { updateWalletStatus, listReleaseTransactionByWalletAddress, + checkUnreleasedLocks, } from "@/blockchain/wallet"; import { getNetworksLiquidity } from "@/blockchain/events"; import type { Event } from "ethers"; @@ -26,13 +27,13 @@ const etherStore = useEtherStore(); etherStore.setSellerView(false); // States -const { loadingLock, walletAddress } = storeToRefs(etherStore); +const { loadingLock, walletAddress, networkName} = storeToRefs(etherStore); const flowStep = ref(Step.Search); const pixTarget = ref(); const tokenAmount = ref(); -const _lockID = ref(""); +const lockID = ref(""); const loadingRelease = ref(false); -const showModal = ref(true); +const showModal = ref(false); const lastWalletReleaseTransactions = ref([]); const confirmBuyClick = async ( @@ -49,8 +50,8 @@ const confirmBuyClick = async ( etherStore.setLoadingLock(true); await addLock(selectedDeposit.seller, selectedDeposit.token, tokenValue) - .then((lockID) => { - _lockID.value = lockID; + .then((_lockID) => { + lockID.value = _lockID; }) .catch((err) => { console.log(err); @@ -65,12 +66,12 @@ const releaseTransaction = async (e2eId: string) => { flowStep.value = Step.List; loadingRelease.value = true; - if (_lockID.value && tokenAmount.value && pixTarget.value) { + if (lockID.value && tokenAmount.value && pixTarget.value) { const release = await releaseLock( pixTarget.value, tokenAmount.value, e2eId, - _lockID.value + lockID.value ); release.wait(); @@ -86,6 +87,31 @@ const releaseTransaction = async (e2eId: string) => { } }; +const checkForUnreleasedLocks = async () => { + const walletLocks = await checkUnreleasedLocks(walletAddress.value); + if (walletLocks) { + lockID.value = walletLocks.lockID; + tokenAmount.value = walletLocks.pix.value; + pixTarget.value = Number(walletLocks.pix.pixKey); + showModal.value = true; + } else { + flowStep.value = Step.Search; + showModal.value = false; + } +} + +if (walletAddress){ + await checkForUnreleasedLocks(); +} + +watch(walletAddress, async () => { + await checkForUnreleasedLocks(); +}); + +watch(networkName, async () => { + await checkForUnreleasedLocks(); +}); + onMounted(async () => { await getNetworksLiquidity(); });