From 3c4a629ed711d7feda5fb884370da83c05fb3075 Mon Sep 17 00:00:00 2001 From: brunoedcf Date: Thu, 19 Jan 2023 18:00:35 -0300 Subject: [PATCH] implemented lock and release in buyer's flow --- src/blockchain/buyerMethods.ts | 10 ++++++---- src/components/SearchComponent.vue | 5 ++++- src/views/HomeView.vue | 19 +++++-------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/blockchain/buyerMethods.ts b/src/blockchain/buyerMethods.ts index d5b843e..78a11fc 100644 --- a/src/blockchain/buyerMethods.ts +++ b/src/blockchain/buyerMethods.ts @@ -27,9 +27,11 @@ const addLock = async (depositId: BigNumber, amount: number): Promise => { [], [] ); - lock.wait(); - return lock; + const lock_rec = await lock.wait(); + const [t] = lock_rec.events; + + return t.args.lockID; }; // Release lock @@ -47,7 +49,7 @@ const releaseLock = async ( ["string", "uint256", "bytes32"], [ pixKey, - formatEther(String(amount)), + parseEther(String(amount)), ethers.utils.formatBytes32String(e2eId), ] ); @@ -69,7 +71,7 @@ const releaseLock = async ( sig.s, sig.v ); - release.wait(); + await release.wait(); return release; }; diff --git a/src/components/SearchComponent.vue b/src/components/SearchComponent.vue index e10581d..5c9da09 100644 --- a/src/components/SearchComponent.vue +++ b/src/components/SearchComponent.vue @@ -98,7 +98,10 @@ const verifyLiquidity = (): void => { const enableOrDisableConfirmButton = (): void => { if (selectedGoerliDeposit.value && networkName.value == NetworkEnum.ethereum) enableConfirmButton.value = true; - else if (selectedMumbaiDeposit.value && networkName.value == NetworkEnum.polygon) + else if ( + selectedMumbaiDeposit.value && + networkName.value == NetworkEnum.polygon + ) enableConfirmButton.value = true; else enableConfirmButton.value = false; }; diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index bf17508..c02ccad 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -28,8 +28,7 @@ const { loadingLock, walletAddress, locksAddedList } = storeToRefs(etherStore); const flowStep = ref(Step.Search); const pixTarget = ref(""); const tokenAmount = ref(); -const lockTransactionHash = ref(""); -const lockId = ref(""); +const _lockID = ref(""); const loadingRelease = ref(false); const lastWalletReleaseTransactions = ref([]); @@ -47,8 +46,8 @@ const confirmBuyClick = async ( etherStore.setLoadingLock(true); await addLock(selectedDeposit.depositID, tokenValue) - .then((lock) => { - lockTransactionHash.value = lock.transactionHash; + .then((lockID) => { + _lockID.value = lockID; }) .catch((err) => { console.log(err); @@ -63,20 +62,12 @@ const releaseTransaction = async (e2eId: string) => { flowStep.value = Step.List; loadingRelease.value = true; - const findLock = locksAddedList.value.find((element) => { - if (element.transactionHash === lockTransactionHash.value) { - lockId.value = element.args?.lockID; - return true; - } - return false; - }); - - if (findLock && tokenAmount.value) { + if (_lockID.value && tokenAmount.value) { const release = await releaseLock( pixTarget.value, tokenAmount.value, e2eId, - lockId.value + _lockID.value ); release.wait();