Add correct implementation to check unreleased lock using getLocksStatus abi function
This commit is contained in:
@@ -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 => {
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user