Add logic to check for unreleased locks on homeview

This commit is contained in:
RcleydsonR 2023-02-10 16:27:55 -03:00
parent a5d72650ee
commit 2ea9f18cc1
2 changed files with 34 additions and 13 deletions

View File

@ -154,11 +154,6 @@ const validatePix = async (): Promise<void> => {
@button-clicked="emit('pixValidated', e2eId)"
/>
</div>
<CustomModal
v-if="showModal"
@close-modal="showModal = false"
:isRedirectModal="false"
/>
</div>
</template>

View File

@ -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>(Step.Search);
const pixTarget = ref<number>();
const tokenAmount = ref<number>();
const _lockID = ref<string>("");
const lockID = ref<string>("");
const loadingRelease = ref<boolean>(false);
const showModal = ref<boolean>(true);
const showModal = ref<boolean>(false);
const lastWalletReleaseTransactions = ref<Event[]>([]);
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();
});