implemented lock and release in buyer's flow

This commit is contained in:
brunoedcf 2023-01-19 18:00:35 -03:00
parent ff9c7f83b5
commit 3c4a629ed7
3 changed files with 15 additions and 19 deletions

View File

@ -27,9 +27,11 @@ const addLock = async (depositId: BigNumber, amount: number): Promise<any> => {
[], [],
[] []
); );
lock.wait();
return lock; const lock_rec = await lock.wait();
const [t] = lock_rec.events;
return t.args.lockID;
}; };
// Release lock // Release lock
@ -47,7 +49,7 @@ const releaseLock = async (
["string", "uint256", "bytes32"], ["string", "uint256", "bytes32"],
[ [
pixKey, pixKey,
formatEther(String(amount)), parseEther(String(amount)),
ethers.utils.formatBytes32String(e2eId), ethers.utils.formatBytes32String(e2eId),
] ]
); );
@ -69,7 +71,7 @@ const releaseLock = async (
sig.s, sig.s,
sig.v sig.v
); );
release.wait(); await release.wait();
return release; return release;
}; };

View File

@ -98,7 +98,10 @@ const verifyLiquidity = (): void => {
const enableOrDisableConfirmButton = (): void => { const enableOrDisableConfirmButton = (): void => {
if (selectedGoerliDeposit.value && networkName.value == NetworkEnum.ethereum) if (selectedGoerliDeposit.value && networkName.value == NetworkEnum.ethereum)
enableConfirmButton.value = true; enableConfirmButton.value = true;
else if (selectedMumbaiDeposit.value && networkName.value == NetworkEnum.polygon) else if (
selectedMumbaiDeposit.value &&
networkName.value == NetworkEnum.polygon
)
enableConfirmButton.value = true; enableConfirmButton.value = true;
else enableConfirmButton.value = false; else enableConfirmButton.value = false;
}; };

View File

@ -28,8 +28,7 @@ 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 tokenAmount = ref<number>(); const tokenAmount = ref<number>();
const lockTransactionHash = ref<string>(""); const _lockID = ref<string>("");
const lockId = ref<string>("");
const loadingRelease = ref<boolean>(false); const loadingRelease = ref<boolean>(false);
const lastWalletReleaseTransactions = ref<Event[]>([]); const lastWalletReleaseTransactions = ref<Event[]>([]);
@ -47,8 +46,8 @@ const confirmBuyClick = async (
etherStore.setLoadingLock(true); etherStore.setLoadingLock(true);
await addLock(selectedDeposit.depositID, tokenValue) await addLock(selectedDeposit.depositID, tokenValue)
.then((lock) => { .then((lockID) => {
lockTransactionHash.value = lock.transactionHash; _lockID.value = lockID;
}) })
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
@ -63,20 +62,12 @@ const releaseTransaction = async (e2eId: string) => {
flowStep.value = Step.List; flowStep.value = Step.List;
loadingRelease.value = true; loadingRelease.value = true;
const findLock = locksAddedList.value.find((element) => { if (_lockID.value && tokenAmount.value) {
if (element.transactionHash === lockTransactionHash.value) {
lockId.value = element.args?.lockID;
return true;
}
return false;
});
if (findLock && tokenAmount.value) {
const release = await releaseLock( const release = await releaseLock(
pixTarget.value, pixTarget.value,
tokenAmount.value, tokenAmount.value,
e2eId, e2eId,
lockId.value _lockID.value
); );
release.wait(); release.wait();