Add correct implementation to check unreleased lock using getLocksStatus abi function

This commit is contained in:
RcleydsonR 2023-02-15 15:14:47 -03:00
parent c65a885309
commit b181d380eb
6 changed files with 51 additions and 40 deletions

View File

@ -1,7 +1,7 @@
import { useEtherStore } from "@/store/ether";
import { NetworkEnum } from "@/model/NetworkEnum";
const getTokenAddress = (): string => {
const getTokenAddress = (network?: NetworkEnum): string => {
const etherStore = useEtherStore();
const possibleTokenAddresses: { [key: string]: string } = {
@ -9,10 +9,10 @@ const getTokenAddress = (): string => {
Polygon: "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
};
return possibleTokenAddresses[etherStore.networkName];
return possibleTokenAddresses[network ? network : etherStore.networkName];
};
const getP2PixAddress = (): string => {
const getP2PixAddress = (network?: NetworkEnum): string => {
const etherStore = useEtherStore();
const possibleP2PixAddresses: { [key: string]: string } = {
@ -20,7 +20,7 @@ const getP2PixAddress = (): string => {
Polygon: "0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00",
};
return possibleP2PixAddresses[etherStore.networkName];
return possibleP2PixAddresses[network ? network : etherStore.networkName];
};
const getProviderUrl = (): string => {

View File

@ -5,6 +5,8 @@ import p2pix from "../utils/smart_contract_files/P2PIX.json";
import { formatEther } from "ethers/lib/utils";
import { getContract } from "./provider";
import type { ValidDeposit } from "@/model/ValidDeposit";
import { getP2PixAddress, getTokenAddress } from "./addresses";
import { NetworkEnum } from "@/model/NetworkEnum";
const getNetworksLiquidity = async (): Promise<void> => {
const etherStore = useEtherStore();
@ -20,23 +22,23 @@ const getNetworksLiquidity = async (): Promise<void> => {
); // mumbai provider
const p2pContractGoerli = new ethers.Contract(
"0x2414817FF64A114d91eCFA16a834d3fCf69103d4",
getP2PixAddress(NetworkEnum.ethereum),
p2pix.abi,
goerliProvider
);
const p2pContractMumbai = new ethers.Contract(
"0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00",
getP2PixAddress(NetworkEnum.polygon),
p2pix.abi,
mumbaiProvider
);
const depositListGoerli = await getValidDeposits(
"0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00",
getTokenAddress(NetworkEnum.ethereum),
p2pContractGoerli
);
const depositListMumbai = await getValidDeposits(
"0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
getTokenAddress(NetworkEnum.polygon),
p2pContractMumbai
);

View File

@ -112,7 +112,7 @@ const listLockTransactionByWalletAddress = async (
});
};
const checkUnreleasedLocks = async (
const checkUnreleasedLock = async (
walletAddress: string
): Promise<UnreleasedLock | undefined> => {
const p2pContract = getContract();
@ -124,18 +124,22 @@ const checkUnreleasedLocks = async (
const lockStatus = await p2pContract.getLocksStatus(
addedLocks.map((lock) => lock.args?.lockID)
);
const unreleasedLockId = lockStatus.find((lock: any) => lock.status);
const unreleasedLockId = lockStatus[1].findIndex(
(lockStatus: number) => lockStatus == 1
);
if (unreleasedLockId) {
const lock = await p2pContract.mapLocks(unreleasedLockId);
console.log(lockStatus);
if (unreleasedLockId != -1) {
const _lockID = lockStatus[0][unreleasedLockId];
const lock = await p2pContract.mapLocks(_lockID);
const pixTarget = lock.pixTarget;
const amount = formatEther(lock?.amount);
pixData.pixKey = pixTarget;
pixData.pixKey = String(Number(pixTarget));
pixData.value = Number(amount);
return {
lockID: unreleasedLockId,
lockID: _lockID,
pix: pixData,
};
}
@ -148,5 +152,5 @@ export {
listValidDepositTransactionsByWalletAddress,
listAllTransactionByWalletAddress,
listReleaseTransactionByWalletAddress,
checkUnreleasedLocks,
checkUnreleasedLock,
};

View File

@ -169,7 +169,7 @@ onUnmounted(() => {
/>
</div>
<CustomModal
v-if="showWarnModal && windowSize < 500"
v-if="showWarnModal && windowSize <= 500"
@close-modal="showWarnModal = false"
:isRedirectModal="false"
/>

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/CustomModal.vue";
@ -11,6 +11,7 @@ import { addLock, releaseLock } from "@/blockchain/buyerMethods";
import {
updateWalletStatus,
listReleaseTransactionByWalletAddress,
checkUnreleasedLock,
} from "@/blockchain/wallet";
import { getNetworksLiquidity } from "@/blockchain/events";
import type { Event } from "ethers";
@ -26,7 +27,7 @@ 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>();
@ -86,30 +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;
// }
// };
const checkForUnreleasedLocks = async (): Promise<void> => {
const walletLocks = await checkUnreleasedLock(walletAddress.value);
console.log(walletLocks);
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();
// }
if (walletAddress.value) {
await checkForUnreleasedLocks();
}
// watch(walletAddress, async () => {
// await checkForUnreleasedLocks();
// });
watch(walletAddress, async () => {
await checkForUnreleasedLocks();
});
// watch(networkName, async () => {
// await checkForUnreleasedLocks();
// });
watch(networkName, async () => {
if (walletAddress.value) await checkForUnreleasedLocks();
});
onMounted(async () => {
await getNetworksLiquidity();

View File

@ -23,7 +23,10 @@ const offerValue = ref<string>("");
const pixKeyBuyer = ref<string>("");
// Verificar tipagem
const approveOffer = async (args: { offer: string; postProcessedPixKey: string }) => {
const approveOffer = async (args: {
offer: string;
postProcessedPixKey: string;
}) => {
loading.value = true;
try {
offerValue.value = args.offer;