Add correct implementation to check unreleased lock using getLocksStatus abi function
This commit is contained in:
parent
c65a885309
commit
b181d380eb
@ -1,7 +1,7 @@
|
|||||||
import { useEtherStore } from "@/store/ether";
|
import { useEtherStore } from "@/store/ether";
|
||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||||
|
|
||||||
const getTokenAddress = (): string => {
|
const getTokenAddress = (network?: NetworkEnum): string => {
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
|
|
||||||
const possibleTokenAddresses: { [key: string]: string } = {
|
const possibleTokenAddresses: { [key: string]: string } = {
|
||||||
@ -9,10 +9,10 @@ const getTokenAddress = (): string => {
|
|||||||
Polygon: "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
|
Polygon: "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
|
||||||
};
|
};
|
||||||
|
|
||||||
return possibleTokenAddresses[etherStore.networkName];
|
return possibleTokenAddresses[network ? network : etherStore.networkName];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getP2PixAddress = (): string => {
|
const getP2PixAddress = (network?: NetworkEnum): string => {
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
|
|
||||||
const possibleP2PixAddresses: { [key: string]: string } = {
|
const possibleP2PixAddresses: { [key: string]: string } = {
|
||||||
@ -20,7 +20,7 @@ const getP2PixAddress = (): string => {
|
|||||||
Polygon: "0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00",
|
Polygon: "0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00",
|
||||||
};
|
};
|
||||||
|
|
||||||
return possibleP2PixAddresses[etherStore.networkName];
|
return possibleP2PixAddresses[network ? network : etherStore.networkName];
|
||||||
};
|
};
|
||||||
|
|
||||||
const getProviderUrl = (): string => {
|
const getProviderUrl = (): string => {
|
||||||
|
@ -5,6 +5,8 @@ import p2pix from "../utils/smart_contract_files/P2PIX.json";
|
|||||||
import { formatEther } from "ethers/lib/utils";
|
import { formatEther } from "ethers/lib/utils";
|
||||||
import { getContract } from "./provider";
|
import { getContract } from "./provider";
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
|
import { getP2PixAddress, getTokenAddress } from "./addresses";
|
||||||
|
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||||
|
|
||||||
const getNetworksLiquidity = async (): Promise<void> => {
|
const getNetworksLiquidity = async (): Promise<void> => {
|
||||||
const etherStore = useEtherStore();
|
const etherStore = useEtherStore();
|
||||||
@ -20,23 +22,23 @@ const getNetworksLiquidity = async (): Promise<void> => {
|
|||||||
); // mumbai provider
|
); // mumbai provider
|
||||||
|
|
||||||
const p2pContractGoerli = new ethers.Contract(
|
const p2pContractGoerli = new ethers.Contract(
|
||||||
"0x2414817FF64A114d91eCFA16a834d3fCf69103d4",
|
getP2PixAddress(NetworkEnum.ethereum),
|
||||||
p2pix.abi,
|
p2pix.abi,
|
||||||
goerliProvider
|
goerliProvider
|
||||||
);
|
);
|
||||||
const p2pContractMumbai = new ethers.Contract(
|
const p2pContractMumbai = new ethers.Contract(
|
||||||
"0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00",
|
getP2PixAddress(NetworkEnum.polygon),
|
||||||
p2pix.abi,
|
p2pix.abi,
|
||||||
mumbaiProvider
|
mumbaiProvider
|
||||||
);
|
);
|
||||||
|
|
||||||
const depositListGoerli = await getValidDeposits(
|
const depositListGoerli = await getValidDeposits(
|
||||||
"0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00",
|
getTokenAddress(NetworkEnum.ethereum),
|
||||||
p2pContractGoerli
|
p2pContractGoerli
|
||||||
);
|
);
|
||||||
|
|
||||||
const depositListMumbai = await getValidDeposits(
|
const depositListMumbai = await getValidDeposits(
|
||||||
"0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
|
getTokenAddress(NetworkEnum.polygon),
|
||||||
p2pContractMumbai
|
p2pContractMumbai
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ const listLockTransactionByWalletAddress = async (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkUnreleasedLocks = async (
|
const checkUnreleasedLock = async (
|
||||||
walletAddress: string
|
walletAddress: string
|
||||||
): Promise<UnreleasedLock | undefined> => {
|
): Promise<UnreleasedLock | undefined> => {
|
||||||
const p2pContract = getContract();
|
const p2pContract = getContract();
|
||||||
@ -124,18 +124,22 @@ const checkUnreleasedLocks = async (
|
|||||||
const lockStatus = await p2pContract.getLocksStatus(
|
const lockStatus = await p2pContract.getLocksStatus(
|
||||||
addedLocks.map((lock) => lock.args?.lockID)
|
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) {
|
console.log(lockStatus);
|
||||||
const lock = await p2pContract.mapLocks(unreleasedLockId);
|
if (unreleasedLockId != -1) {
|
||||||
|
const _lockID = lockStatus[0][unreleasedLockId];
|
||||||
|
const lock = await p2pContract.mapLocks(_lockID);
|
||||||
|
|
||||||
const pixTarget = lock.pixTarget;
|
const pixTarget = lock.pixTarget;
|
||||||
const amount = formatEther(lock?.amount);
|
const amount = formatEther(lock?.amount);
|
||||||
pixData.pixKey = pixTarget;
|
pixData.pixKey = String(Number(pixTarget));
|
||||||
pixData.value = Number(amount);
|
pixData.value = Number(amount);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
lockID: unreleasedLockId,
|
lockID: _lockID,
|
||||||
pix: pixData,
|
pix: pixData,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -148,5 +152,5 @@ export {
|
|||||||
listValidDepositTransactionsByWalletAddress,
|
listValidDepositTransactionsByWalletAddress,
|
||||||
listAllTransactionByWalletAddress,
|
listAllTransactionByWalletAddress,
|
||||||
listReleaseTransactionByWalletAddress,
|
listReleaseTransactionByWalletAddress,
|
||||||
checkUnreleasedLocks,
|
checkUnreleasedLock,
|
||||||
};
|
};
|
||||||
|
@ -169,7 +169,7 @@ onUnmounted(() => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<CustomModal
|
<CustomModal
|
||||||
v-if="showWarnModal && windowSize < 500"
|
v-if="showWarnModal && windowSize <= 500"
|
||||||
@close-modal="showWarnModal = false"
|
@close-modal="showWarnModal = false"
|
||||||
:isRedirectModal="false"
|
:isRedirectModal="false"
|
||||||
/>
|
/>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import SearchComponent from "@/components/SearchComponent.vue";
|
import SearchComponent from "@/components/SearchComponent.vue";
|
||||||
import LoadingComponent from "@/components/LoadingComponent/LoadingComponent.vue";
|
import LoadingComponent from "@/components/LoadingComponent/LoadingComponent.vue";
|
||||||
import BuyConfirmedComponent from "@/components/BuyConfirmedComponent/BuyConfirmedComponent.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 { useEtherStore } from "@/store/ether";
|
||||||
import QrCodeComponent from "@/components/QrCodeComponent.vue";
|
import QrCodeComponent from "@/components/QrCodeComponent.vue";
|
||||||
import CustomModal from "@/components/CustomModal/CustomModal.vue";
|
import CustomModal from "@/components/CustomModal/CustomModal.vue";
|
||||||
@ -11,6 +11,7 @@ import { addLock, releaseLock } from "@/blockchain/buyerMethods";
|
|||||||
import {
|
import {
|
||||||
updateWalletStatus,
|
updateWalletStatus,
|
||||||
listReleaseTransactionByWalletAddress,
|
listReleaseTransactionByWalletAddress,
|
||||||
|
checkUnreleasedLock,
|
||||||
} from "@/blockchain/wallet";
|
} from "@/blockchain/wallet";
|
||||||
import { getNetworksLiquidity } from "@/blockchain/events";
|
import { getNetworksLiquidity } from "@/blockchain/events";
|
||||||
import type { Event } from "ethers";
|
import type { Event } from "ethers";
|
||||||
@ -26,7 +27,7 @@ const etherStore = useEtherStore();
|
|||||||
etherStore.setSellerView(false);
|
etherStore.setSellerView(false);
|
||||||
|
|
||||||
// States
|
// States
|
||||||
const { loadingLock, walletAddress } = storeToRefs(etherStore);
|
const { loadingLock, walletAddress, networkName } = storeToRefs(etherStore);
|
||||||
const flowStep = ref<Step>(Step.Search);
|
const flowStep = ref<Step>(Step.Search);
|
||||||
const pixTarget = ref<number>();
|
const pixTarget = ref<number>();
|
||||||
const tokenAmount = ref<number>();
|
const tokenAmount = ref<number>();
|
||||||
@ -86,30 +87,31 @@ const releaseTransaction = async (e2eId: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// const checkForUnreleasedLocks = async () => {
|
const checkForUnreleasedLocks = async (): Promise<void> => {
|
||||||
// const walletLocks = await checkUnreleasedLocks(walletAddress.value);
|
const walletLocks = await checkUnreleasedLock(walletAddress.value);
|
||||||
// if (walletLocks) {
|
console.log(walletLocks);
|
||||||
// lockID.value = walletLocks.lockID;
|
if (walletLocks) {
|
||||||
// tokenAmount.value = walletLocks.pix.value;
|
lockID.value = walletLocks.lockID;
|
||||||
// pixTarget.value = Number(walletLocks.pix.pixKey);
|
tokenAmount.value = walletLocks.pix.value;
|
||||||
// showModal.value = true;
|
pixTarget.value = Number(walletLocks.pix.pixKey);
|
||||||
// } else {
|
showModal.value = true;
|
||||||
// flowStep.value = Step.Search;
|
} else {
|
||||||
// showModal.value = false;
|
flowStep.value = Step.Search;
|
||||||
// }
|
showModal.value = false;
|
||||||
// };
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// if (walletAddress) {
|
if (walletAddress.value) {
|
||||||
// await checkForUnreleasedLocks();
|
await checkForUnreleasedLocks();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// watch(walletAddress, async () => {
|
watch(walletAddress, async () => {
|
||||||
// await checkForUnreleasedLocks();
|
await checkForUnreleasedLocks();
|
||||||
// });
|
});
|
||||||
|
|
||||||
// watch(networkName, async () => {
|
watch(networkName, async () => {
|
||||||
// await checkForUnreleasedLocks();
|
if (walletAddress.value) await checkForUnreleasedLocks();
|
||||||
// });
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await getNetworksLiquidity();
|
await getNetworksLiquidity();
|
||||||
|
@ -23,7 +23,10 @@ const offerValue = ref<string>("");
|
|||||||
const pixKeyBuyer = ref<string>("");
|
const pixKeyBuyer = ref<string>("");
|
||||||
|
|
||||||
// Verificar tipagem
|
// Verificar tipagem
|
||||||
const approveOffer = async (args: { offer: string; postProcessedPixKey: string }) => {
|
const approveOffer = async (args: {
|
||||||
|
offer: string;
|
||||||
|
postProcessedPixKey: string;
|
||||||
|
}) => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
offerValue.value = args.offer;
|
offerValue.value = args.offer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user