diff --git a/package.json b/package.json index 54388ec..48b43b9 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "coverage": "vitest run --coverage", "build-only": "vite build", "type-check": "vue-tsc --skipLibCheck --noEmit", - "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --ignore-path .gitignore", + "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --ignore-path .gitignore --fix", "lint:fix": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore" }, "dependencies": { diff --git a/src/blockchain/addresses.ts b/src/blockchain/addresses.ts index c812e9f..6eb790f 100644 --- a/src/blockchain/addresses.ts +++ b/src/blockchain/addresses.ts @@ -58,11 +58,10 @@ export const getProviderByNetwork = (network: NetworkEnum) => { const chain = network === NetworkEnum.sepolia ? sepolia : rootstock; return createPublicClient({ chain, - transport: http(getProviderUrl(network)) + transport: http(getProviderUrl(network)), }); }; export const isPossibleNetwork = (networkChain: NetworkEnum): boolean => { return Number(networkChain) in NetworkEnum; }; - diff --git a/src/blockchain/events.ts b/src/blockchain/events.ts index 51d5270..95c795c 100644 --- a/src/blockchain/events.ts +++ b/src/blockchain/events.ts @@ -1,14 +1,16 @@ import { useUser } from "@/composables/useUser"; -import { formatEther, decodeEventLog, parseAbi, toHex, type PublicClient, type Address } from "viem"; +import { + formatEther, + decodeEventLog, + parseAbi, + toHex, + type PublicClient, +} from "viem"; import p2pix from "@/utils/smart_contract_files/P2PIX.json"; import { getContract } from "./provider"; import type { ValidDeposit } from "@/model/ValidDeposit"; -import { - getP2PixAddress, - getProviderByNetwork, - getTokenAddress, -} from "./addresses"; +import { getTokenAddress } from "./addresses"; import { NetworkEnum } from "@/model/NetworkEnum"; import type { UnreleasedLock } from "@/model/UnreleasedLock"; import type { Pix } from "@/model/Pix"; @@ -37,16 +39,17 @@ const getNetworksLiquidity = async (): Promise => { const getPixKey = async (seller: string, token: string): Promise => { const { address, abi, client } = await getContract(); - + const pixKeyHex = await client.readContract({ address, abi, - functionName: 'getPixTarget', - args: [seller, token] + functionName: "getPixTarget", + args: [seller, token], }); - + // Remove '0x' prefix and convert hex to UTF-8 string - const hexString = typeof pixKeyHex === 'string' ? pixKeyHex : toHex(pixKeyHex); + const hexString = + typeof pixKeyHex === "string" ? pixKeyHex : toHex(pixKeyHex); if (!hexString) throw new Error("PixKey not found"); const bytes = new Uint8Array( // @ts-ignore @@ -62,10 +65,10 @@ const getPixKey = async (seller: string, token: string): Promise => { const getValidDeposits = async ( token: string, network: NetworkEnum, - contractInfo?: { client: any, address: string } + contractInfo?: { client: any; address: string } ): Promise => { - let client:PublicClient, address, abi; - + let client: PublicClient, address, abi; + if (contractInfo) { ({ client, address } = contractInfo); abi = p2pix.abi; @@ -76,17 +79,17 @@ const getValidDeposits = async ( const depositLogs = await client.getLogs({ address, event: parseAbi([ - "event DepositAdded(address indexed seller, address token, uint256 amount)" + "event DepositAdded(address indexed seller, address token, uint256 amount)", ])[0], fromBlock: 0n, - toBlock: 'latest' + toBlock: "latest", }); if (!contractInfo) { // Get metamask provider contract ({ address, abi, client } = await getContract()); } - + const depositList: { [key: string]: ValidDeposit } = {}; for (const log of depositLogs) { @@ -94,19 +97,19 @@ const getValidDeposits = async ( const decoded = decodeEventLog({ abi, data: log.data, - topics: log.topics + topics: log.topics, }); - + // Get liquidity only for the selected token if (decoded?.args.token.toLowerCase() !== token.toLowerCase()) continue; - + const mappedBalance = await client.readContract({ address, abi, - functionName: 'getBalance', - args: [decoded.args.seller, token] + functionName: "getBalance", + args: [decoded.args.seller, token], }); - + let validDeposit: ValidDeposit | null = null; if (mappedBalance) { @@ -139,8 +142,8 @@ const getUnreleasedLockById = async ( const lock = await client.readContract({ address, abi, - functionName: 'mapLocks', - args: [BigInt(lockID)] + functionName: "mapLocks", + args: [BigInt(lockID)], }); const pixTarget = lock.pixTarget; diff --git a/src/blockchain/provider.ts b/src/blockchain/provider.ts index 3ae1380..5f14eac 100644 --- a/src/blockchain/provider.ts +++ b/src/blockchain/provider.ts @@ -13,8 +13,9 @@ const getPublicClient = (onlyRpcProvider = false) => { const user = useUser(); const rpcUrl = getProviderUrl(); return createPublicClient({ - chain: Number(user.networkName.value) === sepolia.id ? sepolia : rootstock, - transport: http(rpcUrl) + chain: + Number(user.networkName.value) === sepolia.id ? sepolia : rootstock, + transport: http(rpcUrl), }); } return publicClient; @@ -35,16 +36,17 @@ const getContract = async (onlyRpcProvider = false) => { const connectProvider = async (p: any): Promise => { console.log("Connecting to provider..."); const user = useUser(); - const chain = Number(user.networkName.value) === sepolia.id ? sepolia : rootstock; + const chain = + Number(user.networkName.value) === sepolia.id ? sepolia : rootstock; publicClient = createPublicClient({ chain, - transport: custom(p) + transport: custom(p), }); walletClient = createWalletClient({ chain, - transport: custom(p) + transport: custom(p), }); await updateWalletStatus(); diff --git a/src/blockchain/sellerMethods.ts b/src/blockchain/sellerMethods.ts index 3b6d714..a41ce6e 100644 --- a/src/blockchain/sellerMethods.ts +++ b/src/blockchain/sellerMethods.ts @@ -26,8 +26,8 @@ const approveTokens = async (participant: Participant): Promise => { const allowance = await publicClient.readContract({ address: tokenAddress, abi: mockToken.abi, - functionName: 'allowance', - args: [account, getP2PixAddress()] + functionName: "allowance", + args: [account, getP2PixAddress()], }); if (allowance < parseEther(participant.offer.toString())) { @@ -35,9 +35,9 @@ const approveTokens = async (participant: Participant): Promise => { const hash = await walletClient.writeContract({ address: tokenAddress, abi: mockToken.abi, - functionName: 'approve', + functionName: "approve", args: [getP2PixAddress(), parseEther(participant.offer.toString())], - account + account, }); await publicClient.waitForTransactionReceipt({ hash }); @@ -63,15 +63,15 @@ const addDeposit = async (): Promise => { const hash = await walletClient.writeContract({ address, abi, - functionName: 'deposit', + functionName: "deposit", args: [ sellerId.id, toHex("", { size: 32 }), getTokenAddress(user.selectedToken.value), parseEther(user.seller.value.offer), - true + true, ], - account + account, }); const receipt = await client.waitForTransactionReceipt({ hash }); diff --git a/src/blockchain/wallet.ts b/src/blockchain/wallet.ts index f30ceb5..8841718 100644 --- a/src/blockchain/wallet.ts +++ b/src/blockchain/wallet.ts @@ -1,16 +1,9 @@ -import { - decodeEventLog, - formatEther, - getAddress, - type Log, - parseAbi, -} from "viem"; +import { decodeEventLog, formatEther, type Log, parseAbi } from "viem"; import { useUser } from "@/composables/useUser"; import { getPublicClient, getWalletClient, getContract } from "./provider"; -import { getTokenAddress, isPossibleNetwork } from "./addresses"; +import { getTokenAddress } from "./addresses"; -import mockToken from "@/utils/smart_contract_files/MockToken.json"; import p2pix from "@/utils/smart_contract_files/P2PIX.json"; import { getValidDeposits } from "./events"; @@ -63,8 +56,8 @@ const getLockStatus = async (id: bigint): Promise => { const result = await client.readContract({ address, abi, - functionName: 'getLocksStatus', - args: [[id]] + functionName: "getLocksStatus", + args: [[id]], }); return result[1][0]; }; @@ -90,9 +83,7 @@ const filterLockStatus = async ( const tx: WalletTransaction = { token: args.token ? String(args.token) : "", blockNumber: Number(transaction.blockNumber), - amount: args.amount - ? Number(formatEther(args.amount)) - : -1, + amount: args.amount ? Number(formatEther(args.amount)) : -1, seller: args.seller ? String(args.seller) : "", buyer: args.buyer ? String(args.buyer) : "", event: decoded.eventName || "", @@ -116,53 +107,61 @@ const filterLockStatus = async ( export const listAllTransactionByWalletAddress = async ( walletAddress: string ): Promise => { - const { address, abi, client } = await getContract(true); + const { address, client } = await getContract(true); // Get deposits const depositLogs = await client.getLogs({ address, - event: parseAbi(['event DepositAdded(address indexed seller, address token, uint256 amount)'])[0], + event: parseAbi([ + "event DepositAdded(address indexed seller, address token, uint256 amount)", + ])[0], args: { - seller: walletAddress + seller: walletAddress, }, fromBlock: 0n, - toBlock: 'latest' + toBlock: "latest", }); console.log("Fetched all wallet deposits"); // Get locks const lockLogs = await client.getLogs({ address, - event: parseAbi(['event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)'])[0], + event: parseAbi([ + "event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)", + ])[0], args: { - buyer: walletAddress + buyer: walletAddress, }, fromBlock: 0n, - toBlock: 'latest' + toBlock: "latest", }); console.log("Fetched all wallet locks"); // Get released locks const releasedLogs = await client.getLogs({ address, - event: parseAbi(['event LockReleased(address indexed buyer, uint256 indexed lockID, string e2eId)'])[0], + event: parseAbi([ + "event LockReleased(address indexed buyer, uint256 indexed lockID, string e2eId)", + ])[0], args: { - buyer: walletAddress + buyer: walletAddress, }, fromBlock: 0n, - toBlock: 'latest' + toBlock: "latest", }); console.log("Fetched all wallet released locks"); // Get withdrawn deposits const withdrawnLogs = await client.getLogs({ address, - event: parseAbi(['event DepositWithdrawn(address indexed seller, address token, uint256 amount)'])[0], + event: parseAbi([ + "event DepositWithdrawn(address indexed seller, address token, uint256 amount)", + ])[0], args: { - seller: walletAddress + seller: walletAddress, }, fromBlock: 0n, - toBlock: 'latest' + toBlock: "latest", }); console.log("Fetched all wallet withdrawn deposits"); @@ -170,7 +169,7 @@ export const listAllTransactionByWalletAddress = async ( ...depositLogs, ...lockLogs, ...releasedLogs, - ...withdrawnLogs + ...withdrawnLogs, ].sort((a: Log, b: Log) => { return Number(b.blockNumber) - Number(a.blockNumber); }); @@ -182,16 +181,18 @@ export const listAllTransactionByWalletAddress = async ( export const listReleaseTransactionByWalletAddress = async ( walletAddress: string ) => { - const { address, abi, client } = await getContract(true); + const { address, client } = await getContract(true); const releasedLogs = await client.getLogs({ address, - event: parseAbi(['event LockReleased(address indexed buyer, uint256 indexed lockID, string e2eId)'])[0], + event: parseAbi([ + "event LockReleased(address indexed buyer, uint256 indexed lockID, string e2eId)", + ])[0], args: { - buyer: walletAddress + buyer: walletAddress, }, fromBlock: 0n, - toBlock: 'latest' + toBlock: "latest", }); return releasedLogs @@ -203,7 +204,7 @@ export const listReleaseTransactionByWalletAddress = async ( return decodeEventLog({ abi: p2pix.abi, data: log.data, - topics: log.topics + topics: log.topics, }); } catch (error) { console.error("Error decoding log", error); @@ -213,19 +214,19 @@ export const listReleaseTransactionByWalletAddress = async ( .filter((decoded: any) => decoded !== null); }; -const listLockTransactionByWalletAddress = async ( - walletAddress: string -) => { - const { address, abi, client } = await getContract(true); +const listLockTransactionByWalletAddress = async (walletAddress: string) => { + const { address, client } = await getContract(true); const lockLogs = await client.getLogs({ address, - event: parseAbi(['event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)'])[0], + event: parseAbi([ + "event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)", + ])[0], args: { - buyer: walletAddress + buyer: walletAddress, }, fromBlock: 0n, - toBlock: 'latest' + toBlock: "latest", }); return lockLogs @@ -237,7 +238,7 @@ const listLockTransactionByWalletAddress = async ( return decodeEventLog({ abi: p2pix.abi, data: log.data, - topics: log.topics + topics: log.topics, }); } catch (error) { console.error("Error decoding log", error); @@ -247,17 +248,17 @@ const listLockTransactionByWalletAddress = async ( .filter((decoded: any) => decoded !== null); }; -const listLockTransactionBySellerAddress = async ( - sellerAddress: string -) => { - const { address, abi, client } = await getContract(true); +const listLockTransactionBySellerAddress = async (sellerAddress: string) => { + const { address, client } = await getContract(true); console.log("Will get locks as seller", sellerAddress); const lockLogs = await client.getLogs({ address, - event: parseAbi(['event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)'])[0], + event: parseAbi([ + "event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)", + ])[0], fromBlock: 0n, - toBlock: 'latest' + toBlock: "latest", }); return lockLogs @@ -266,7 +267,7 @@ const listLockTransactionBySellerAddress = async ( return decodeEventLog({ abi: p2pix.abi, data: log.data, - topics: log.topics + topics: log.topics, }); } catch (error) { console.error("Error decoding log", error); @@ -275,7 +276,9 @@ const listLockTransactionBySellerAddress = async ( }) .filter((decoded: any) => decoded !== null) .filter( - (decoded: any) => decoded.args && decoded.args.seller && + (decoded: any) => + decoded.args && + decoded.args.seller && decoded.args.seller.toLowerCase() === sellerAddress.toLowerCase() ); }; @@ -297,8 +300,8 @@ export const checkUnreleasedLock = async ( const lockStatus = await client.readContract({ address, abi, - functionName: 'getLocksStatus', - args: [lockIds] + functionName: "getLocksStatus", + args: [lockIds], }); const unreleasedLockId = lockStatus[1].findIndex( @@ -311,8 +314,8 @@ export const checkUnreleasedLock = async ( const lock = await client.readContract({ address, abi, - functionName: 'mapLocks', - args: [lockID] + functionName: "mapLocks", + args: [lockID], }); const pixTarget = lock.pixTarget; @@ -340,8 +343,8 @@ export const getActiveLockAmount = async ( const lockStatus = await client.readContract({ address, abi, - functionName: 'getLocksStatus', - args: [lockIds] + functionName: "getLocksStatus", + args: [lockIds], }); let activeLockAmount = 0; @@ -351,8 +354,8 @@ export const getActiveLockAmount = async ( const lock = await client.readContract({ address, abi, - functionName: 'mapLocks', - args: [lockId] + functionName: "mapLocks", + args: [lockId], }); activeLockAmount += Number(formatEther(lock.amount)); } diff --git a/src/components/BuyConfirmedComponent/BuyConfirmedComponent.vue b/src/components/BuyConfirmedComponent/BuyConfirmedComponent.vue index c9cbc3b..50a88ac 100644 --- a/src/components/BuyConfirmedComponent/BuyConfirmedComponent.vue +++ b/src/components/BuyConfirmedComponent/BuyConfirmedComponent.vue @@ -9,7 +9,6 @@ import CustomButton from "@/components/CustomButton/CustomButton.vue"; import type { ValidDeposit } from "@/model/ValidDeposit"; import type { WalletTransaction } from "@/model/WalletTransaction"; import { useUser } from "@/composables/useUser"; -import { NetworkEnum } from "@/model/NetworkEnum"; import { onMounted, ref, watch } from "vue"; import ListingComponent from "../ListingComponent/ListingComponent.vue"; @@ -151,6 +150,8 @@ p { } input[type="number"] { + appearance: textfield; + -webkit-appearance: textfield; -moz-appearance: textfield; } diff --git a/src/components/ListingComponent/ListingComponent.vue b/src/components/ListingComponent/ListingComponent.vue index b07cdee..754d400 100644 --- a/src/components/ListingComponent/ListingComponent.vue +++ b/src/components/ListingComponent/ListingComponent.vue @@ -1,5 +1,4 @@