diff --git a/.env.example b/.env.example deleted file mode 100644 index 30d4d77..0000000 --- a/.env.example +++ /dev/null @@ -1,3 +0,0 @@ -VITE_API_URL=http://localhost:8000/ -VITE_GOERLI_API_URL={GOERLI_API_URL_ALCHEMY} -VITE_MUMBAI_API_URL={MUMBAI_API_URL_ALCHEMY} \ No newline at end of file diff --git a/src/blockchain/__tests__/addresses.spec.ts b/src/blockchain/__tests__/addresses.spec.ts index 8bb306c..843e1f1 100644 --- a/src/blockchain/__tests__/addresses.spec.ts +++ b/src/blockchain/__tests__/addresses.spec.ts @@ -33,7 +33,7 @@ describe("addresses.ts functions", () => { const etherStore = useEtherStore(); etherStore.setNetworkName(NetworkEnum.ethereum); expect(getTokenAddress()).toBe( - "0x294003F602c321627152c6b7DED3EAb5bEa853Ee" + "0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00" ); }); @@ -41,13 +41,13 @@ describe("addresses.ts functions", () => { const etherStore = useEtherStore(); etherStore.setNetworkName(NetworkEnum.polygon); expect(getTokenAddress()).toBe( - "0x294003F602c321627152c6b7DED3EAb5bEa853Ee" + "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29" ); }); it("getTokenAddress Default", () => { expect(getTokenAddress()).toBe( - "0x294003F602c321627152c6b7DED3EAb5bEa853Ee" + "0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00" ); }); @@ -55,7 +55,7 @@ describe("addresses.ts functions", () => { const etherStore = useEtherStore(); etherStore.setNetworkName(NetworkEnum.ethereum); expect(getP2PixAddress()).toBe( - "0x5f3EFA9A90532914545CEf527C530658af87e196" + "0xefa5cE4351cda51192509cf8De7d8881ADAE95DD" ); }); @@ -63,13 +63,13 @@ describe("addresses.ts functions", () => { const etherStore = useEtherStore(); etherStore.setNetworkName(NetworkEnum.polygon); expect(getP2PixAddress()).toBe( - "0x5f3EFA9A90532914545CEf527C530658af87e196" + "0xA9258eBb157E4cf5e756b77FDD0DF09C2F73240b" ); }); it("getP2PixAddress Default", () => { expect(getP2PixAddress()).toBe( - "0x5f3EFA9A90532914545CEf527C530658af87e196" + "0xefa5cE4351cda51192509cf8De7d8881ADAE95DD" ); }); @@ -102,9 +102,3 @@ describe("addresses.ts functions", () => { expect(isPossibleNetwork("0x55")).toBe(false); }); }); - -describe("addresses.ts Unset Store", () => { - it("getProviderUrl Unset", () => { - expect(getProviderUrl()).toBe(undefined); - }); -}); diff --git a/src/blockchain/addresses.ts b/src/blockchain/addresses.ts index 8fc74fe..53b647c 100644 --- a/src/blockchain/addresses.ts +++ b/src/blockchain/addresses.ts @@ -5,8 +5,8 @@ const getTokenAddress = (): string => { const etherStore = useEtherStore(); const possibleTokenAddresses: { [key: string]: string } = { - Ethereum: "0x294003F602c321627152c6b7DED3EAb5bEa853Ee", - Polygon: "0x294003F602c321627152c6b7DED3EAb5bEa853Ee", + Ethereum: "0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00", + Polygon: "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29", }; return possibleTokenAddresses[etherStore.networkName]; @@ -16,8 +16,8 @@ const getP2PixAddress = (): string => { const etherStore = useEtherStore(); const possibleP2PixAddresses: { [key: string]: string } = { - Ethereum: "0x5f3EFA9A90532914545CEf527C530658af87e196", - Polygon: "0x5f3EFA9A90532914545CEf527C530658af87e196", + Ethereum: "0xefa5cE4351cda51192509cf8De7d8881ADAE95DD", + Polygon: "0xA9258eBb157E4cf5e756b77FDD0DF09C2F73240b", }; return possibleP2PixAddresses[etherStore.networkName]; diff --git a/src/blockchain/buyerMethods.ts b/src/blockchain/buyerMethods.ts index 92cc2a8..f8a06f1 100644 --- a/src/blockchain/buyerMethods.ts +++ b/src/blockchain/buyerMethods.ts @@ -9,7 +9,8 @@ import { BigNumber, ethers } from "ethers"; import { parseEther } from "ethers/lib/utils"; const addLock = async ( - depositId: BigNumber, + seller: string, + token: string, amount: number ): Promise => { const etherStore = useEtherStore(); @@ -17,7 +18,8 @@ const addLock = async ( const p2pContract = getContract(); const lock = await p2pContract.lock( - depositId, // BigNumber + seller, + token, etherStore.walletAddress, // String "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" (Example) ethers.constants.AddressZero, // String "0x0000000000000000000000000000000000000000" 0, @@ -29,11 +31,11 @@ const addLock = async ( const lock_rec = await lock.wait(); const [t] = lock_rec.events; - return t.args.lockID; + return String(t.args.lockID); }; const releaseLock = async ( - pixKey: string, + pixKey: number, amount: number, e2eId: string, lockId: string @@ -43,7 +45,7 @@ const releaseLock = async ( ); const messageToSign = ethers.utils.solidityKeccak256( - ["string", "uint256", "bytes32"], + ["uint160", "uint256", "bytes32"], [ pixKey, parseEther(String(amount)), @@ -61,7 +63,7 @@ const releaseLock = async ( const p2pContract = new ethers.Contract(getP2PixAddress(), p2pix.abi, signer); const release = await p2pContract.release( - lockId, + BigNumber.from(lockId), ethers.constants.AddressZero, ethers.utils.formatBytes32String(e2eId), sig.r, @@ -82,10 +84,13 @@ const cancelDeposit = async (depositId: BigNumber): Promise => { return cancel; }; -const withdrawDeposit = async (depositId: BigNumber): Promise => { +const withdrawDeposit = async ( + depositId: BigNumber, + amount: string +): Promise => { const contract = getContract(); - const withdraw = await contract.withdraw(depositId, []); + const withdraw = await contract.withdraw(depositId, amount, []); await withdraw.wait(); return withdraw; diff --git a/src/blockchain/events.ts b/src/blockchain/events.ts index 0e5558e..2a3b226 100644 --- a/src/blockchain/events.ts +++ b/src/blockchain/events.ts @@ -20,19 +20,25 @@ const getNetworksLiquidity = async (): Promise => { ); // mumbai provider const p2pContractGoerli = new ethers.Contract( - "0x5f3EFA9A90532914545CEf527C530658af87e196", + "0xefa5cE4351cda51192509cf8De7d8881ADAE95DD", p2pix.abi, goerliProvider ); const p2pContractMumbai = new ethers.Contract( - "0x5f3EFA9A90532914545CEf527C530658af87e196", + "0xA9258eBb157E4cf5e756b77FDD0DF09C2F73240b", p2pix.abi, mumbaiProvider ); - const depositListGoerli = await getValidDeposits(p2pContractGoerli); + const depositListGoerli = await getValidDeposits( + "0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00", + p2pContractGoerli + ); - const depositListMumbai = await getValidDeposits(p2pContractMumbai); + const depositListMumbai = await getValidDeposits( + "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29", + p2pContractMumbai + ); etherStore.setDepositsValidListGoerli(depositListGoerli); console.log(depositListGoerli); @@ -42,6 +48,7 @@ const getNetworksLiquidity = async (): Promise => { }; const getValidDeposits = async ( + token: string, contract?: Contract ): Promise => { let p2pContract: Contract; @@ -56,29 +63,41 @@ const getValidDeposits = async ( const eventsDeposits = await p2pContract.queryFilter(filterDeposits); if (!contract) p2pContract = getContract(); // get metamask provider contract + const depositList: { [key: string]: ValidDeposit } = {}; - const depositList = await Promise.all( + await Promise.all( eventsDeposits.map(async (deposit) => { - const mappedDeposit = await p2pContract.mapDeposits( - deposit.args?.depositID + // Get liquidity only for the selected token + if (deposit.args?.token != token) return null; + + const mappedBalance = await p2pContract.getBalance( + deposit.args?.seller, + token ); + + const mappedPixTarget = await p2pContract.getPixTarget( + deposit.args?.seller, + token + ); + let validDeposit: ValidDeposit | null = null; - if (mappedDeposit.valid) { + if (mappedBalance._hex) { validDeposit = { + token: token, blockNumber: deposit.blockNumber, - depositID: deposit.args?.depositID, - remaining: Number(formatEther(mappedDeposit.remaining)), - seller: mappedDeposit.seller, - pixKey: mappedDeposit.pixTarget, + remaining: Number(formatEther(mappedBalance._hex)), + seller: deposit.args?.seller, + pixKey: Number(mappedPixTarget._hex), }; } - return validDeposit; + if (validDeposit) + depositList[deposit.args?.seller + token] = validDeposit; }) ); - return depositList.filter((deposit) => deposit) as ValidDeposit[]; + return Object.values(depositList); }; export { getValidDeposits, getNetworksLiquidity }; diff --git a/src/blockchain/sellerMethods.ts b/src/blockchain/sellerMethods.ts index 6385f7f..1fd1c0e 100644 --- a/src/blockchain/sellerMethods.ts +++ b/src/blockchain/sellerMethods.ts @@ -22,7 +22,6 @@ const approveTokens = async (tokenQty: string): Promise => { ); await apprv.wait(); - console.log(apprv); return apprv; }; @@ -33,6 +32,7 @@ const addDeposit = async (tokenQty: string, pixKey: string): Promise => { getTokenAddress(), parseEther(tokenQty), pixKey, + true, ethers.utils.formatBytes32String("") ); diff --git a/src/blockchain/wallet.ts b/src/blockchain/wallet.ts index 4f8bf29..6aa2035 100644 --- a/src/blockchain/wallet.ts +++ b/src/blockchain/wallet.ts @@ -35,7 +35,7 @@ const updateWalletStatus = async (): Promise => { const listValidDepositTransactionsByWalletAddress = async ( walletAddress: string ): Promise => { - const walletDeposits = await getValidDeposits(); + const walletDeposits = await getValidDeposits(getTokenAddress()); if (walletDeposits) { return walletDeposits @@ -51,7 +51,7 @@ const listValidDepositTransactionsByWalletAddress = async ( const listAllTransactionByWalletAddress = async ( walletAddress: string ): Promise => { - const p2pContract = getContract(); + const p2pContract = getContract(true); const filterDeposits = p2pContract.filters.DepositAdded([walletAddress]); const eventsDeposits = await p2pContract.queryFilter(filterDeposits); diff --git a/src/components/CustomModal.vue b/src/components/CustomModal.vue index 8d0e70d..983805d 100644 --- a/src/components/CustomModal.vue +++ b/src/components/CustomModal.vue @@ -1,10 +1,13 @@ - + \ No newline at end of file + diff --git a/src/components/ListingComponent/ListingComponent.vue b/src/components/ListingComponent/ListingComponent.vue index 7d903ea..4f17529 100644 --- a/src/components/ListingComponent/ListingComponent.vue +++ b/src/components/ListingComponent/ListingComponent.vue @@ -16,11 +16,17 @@ const etherStore = useEtherStore(); const itemsToShow = ref<(Event | ValidDeposit)[]>([]); +const getExplorer = (): string => { + return etherStore.networkName == NetworkEnum.ethereum + ? "Etherscan" + : "Polygonscan"; +}; + // Methods const isValidDeposit = ( deposit: Event | ValidDeposit ): deposit is ValidDeposit => { - return (deposit as ValidDeposit).depositID !== undefined; + return (deposit as ValidDeposit).token !== undefined; }; const showInitialItems = (): void => { @@ -48,8 +54,8 @@ const getEventName = (event: string | undefined): string => { const possibleEventName: { [key: string]: string } = { DepositAdded: "Oferta", - LockAdded: "Compra", - LockReleased: "Reserva", + LockAdded: "Reserva", + LockReleased: "Compra", }; return possibleEventName[event]; @@ -72,7 +78,7 @@ watch(props, async (): Promise => { }); //emits -const emit = defineEmits(["cancelDeposit", "withdrawDeposit"]); +const emit = defineEmits(["withdrawDeposit"]); // initial itemsToShow valueb showInitialItems(); @@ -109,7 +115,7 @@ showInitialItems(); class="flex gap-2 cursor-pointer items-center justify-self-center" @click="openEtherscanUrl((item as Event)?.transactionHash)" > - Etherscan + {{ getExplorer() }} Redirect image @@ -122,19 +128,10 @@ showInitialItems();
-
- Cancelar -
-
Withdraw image diff --git a/src/components/ListingComponent/__tests__/ListingComponent.spec.ts b/src/components/ListingComponent/__tests__/ListingComponent.spec.ts index 382a3fc..d7312f1 100644 --- a/src/components/ListingComponent/__tests__/ListingComponent.spec.ts +++ b/src/components/ListingComponent/__tests__/ListingComponent.spec.ts @@ -10,6 +10,17 @@ describe("ListingComponent.vue", () => { setActivePinia(createPinia()); }); + test("Test Message when an empty array is received", () => { + const wrapper = mount(ListingComponent, { + props: { + walletTransactions: [], + isManageMode: true, + }, + }); + + expect(wrapper.html()).toContain("Não há nenhuma transação anterior"); + }); + test("Test Headers on List in Manage Mode", () => { const wrapper = mount(ListingComponent, { props: { @@ -20,7 +31,6 @@ describe("ListingComponent.vue", () => { expect(wrapper.html()).toContain("Valor"); expect(wrapper.html()).toContain("Data"); - expect(wrapper.html()).toContain("Cancelar oferta"); expect(wrapper.html()).toContain("Retirar tokens"); }); @@ -70,20 +80,6 @@ describe("ListingComponent.vue", () => { expect(elements).toHaveLength(5); }); - test("Test cancel offer button emit", async () => { - const wrapper = mount(ListingComponent, { - props: { - walletTransactions: MockValidDeposits, - isManageMode: true, - }, - }); - wrapper.vm.$emit("cancelDeposit"); - - await wrapper.vm.$nextTick(); - - expect(wrapper.emitted("cancelDeposit")).toBeTruthy(); - }); - test("Test withdraw offer button emit", async () => { const wrapper = mount(ListingComponent, { props: { diff --git a/src/components/LoadingComponent.vue b/src/components/LoadingComponent/LoadingComponent.vue similarity index 100% rename from src/components/LoadingComponent.vue rename to src/components/LoadingComponent/LoadingComponent.vue diff --git a/src/components/LoadingComponent/__tests__/LoadingComponent.spec.ts b/src/components/LoadingComponent/__tests__/LoadingComponent.spec.ts new file mode 100644 index 0000000..8864a65 --- /dev/null +++ b/src/components/LoadingComponent/__tests__/LoadingComponent.spec.ts @@ -0,0 +1,27 @@ +import { mount } from "@vue/test-utils"; +import LoadingComponent from "../LoadingComponent.vue"; + +describe("Loading.vue", () => { + test("Test loading content with received props", () => { + const wrapper = mount(LoadingComponent, { + props: { + title: "MockTitle", + message: "MockMessage", + }, + }); + + expect(wrapper.html()).toContain("MockTitle"); + expect(wrapper.html()).toContain("MockMessage"); + }); + + test("Test default text if props title isnt passed", () => { + const wrapper = mount(LoadingComponent, { + props: { + message: "MockMessage", + }, + }); + + expect(wrapper.html()).toContain("Confirme em sua carteira"); + expect(wrapper.html()).toContain("MockMessage"); + }); +}); diff --git a/src/components/QrCodeComponent.vue b/src/components/QrCodeComponent.vue index e6fc5d3..343a21b 100644 --- a/src/components/QrCodeComponent.vue +++ b/src/components/QrCodeComponent.vue @@ -154,10 +154,7 @@ const validatePix = async (): Promise => { @button-clicked="emit('pixValidated', e2eId)" />
- +
diff --git a/src/components/SearchComponent.vue b/src/components/SearchComponent.vue index b3efe26..2dbadc1 100644 --- a/src/components/SearchComponent.vue +++ b/src/components/SearchComponent.vue @@ -107,8 +107,13 @@ const enableOrDisableConfirmButton = (): void => { }; watch(networkName, (): void => { + verifyLiquidity(); enableOrDisableConfirmButton(); }); + +watch(walletAddress, (): void => { + verifyLiquidity(); +});