Adjust linter errors.
This commit is contained in:
parent
9fa2b34a5d
commit
4908dff58b
@ -10,7 +10,7 @@
|
|||||||
"coverage": "vitest run --coverage",
|
"coverage": "vitest run --coverage",
|
||||||
"build-only": "vite build",
|
"build-only": "vite build",
|
||||||
"type-check": "vue-tsc --skipLibCheck --noEmit",
|
"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"
|
"lint:fix": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -58,11 +58,10 @@ export const getProviderByNetwork = (network: NetworkEnum) => {
|
|||||||
const chain = network === NetworkEnum.sepolia ? sepolia : rootstock;
|
const chain = network === NetworkEnum.sepolia ? sepolia : rootstock;
|
||||||
return createPublicClient({
|
return createPublicClient({
|
||||||
chain,
|
chain,
|
||||||
transport: http(getProviderUrl(network))
|
transport: http(getProviderUrl(network)),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isPossibleNetwork = (networkChain: NetworkEnum): boolean => {
|
export const isPossibleNetwork = (networkChain: NetworkEnum): boolean => {
|
||||||
return Number(networkChain) in NetworkEnum;
|
return Number(networkChain) in NetworkEnum;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
import { useUser } from "@/composables/useUser";
|
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 p2pix from "@/utils/smart_contract_files/P2PIX.json";
|
||||||
import { getContract } from "./provider";
|
import { getContract } from "./provider";
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
import {
|
import { getTokenAddress } from "./addresses";
|
||||||
getP2PixAddress,
|
|
||||||
getProviderByNetwork,
|
|
||||||
getTokenAddress,
|
|
||||||
} from "./addresses";
|
|
||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||||
import type { UnreleasedLock } from "@/model/UnreleasedLock";
|
import type { UnreleasedLock } from "@/model/UnreleasedLock";
|
||||||
import type { Pix } from "@/model/Pix";
|
import type { Pix } from "@/model/Pix";
|
||||||
@ -37,16 +39,17 @@ const getNetworksLiquidity = async (): Promise<void> => {
|
|||||||
|
|
||||||
const getPixKey = async (seller: string, token: string): Promise<string> => {
|
const getPixKey = async (seller: string, token: string): Promise<string> => {
|
||||||
const { address, abi, client } = await getContract();
|
const { address, abi, client } = await getContract();
|
||||||
|
|
||||||
const pixKeyHex = await client.readContract({
|
const pixKeyHex = await client.readContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: 'getPixTarget',
|
functionName: "getPixTarget",
|
||||||
args: [seller, token]
|
args: [seller, token],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove '0x' prefix and convert hex to UTF-8 string
|
// 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");
|
if (!hexString) throw new Error("PixKey not found");
|
||||||
const bytes = new Uint8Array(
|
const bytes = new Uint8Array(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -62,10 +65,10 @@ const getPixKey = async (seller: string, token: string): Promise<string> => {
|
|||||||
const getValidDeposits = async (
|
const getValidDeposits = async (
|
||||||
token: string,
|
token: string,
|
||||||
network: NetworkEnum,
|
network: NetworkEnum,
|
||||||
contractInfo?: { client: any, address: string }
|
contractInfo?: { client: any; address: string }
|
||||||
): Promise<ValidDeposit[]> => {
|
): Promise<ValidDeposit[]> => {
|
||||||
let client:PublicClient, address, abi;
|
let client: PublicClient, address, abi;
|
||||||
|
|
||||||
if (contractInfo) {
|
if (contractInfo) {
|
||||||
({ client, address } = contractInfo);
|
({ client, address } = contractInfo);
|
||||||
abi = p2pix.abi;
|
abi = p2pix.abi;
|
||||||
@ -76,17 +79,17 @@ const getValidDeposits = async (
|
|||||||
const depositLogs = await client.getLogs({
|
const depositLogs = await client.getLogs({
|
||||||
address,
|
address,
|
||||||
event: parseAbi([
|
event: parseAbi([
|
||||||
"event DepositAdded(address indexed seller, address token, uint256 amount)"
|
"event DepositAdded(address indexed seller, address token, uint256 amount)",
|
||||||
])[0],
|
])[0],
|
||||||
fromBlock: 0n,
|
fromBlock: 0n,
|
||||||
toBlock: 'latest'
|
toBlock: "latest",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!contractInfo) {
|
if (!contractInfo) {
|
||||||
// Get metamask provider contract
|
// Get metamask provider contract
|
||||||
({ address, abi, client } = await getContract());
|
({ address, abi, client } = await getContract());
|
||||||
}
|
}
|
||||||
|
|
||||||
const depositList: { [key: string]: ValidDeposit } = {};
|
const depositList: { [key: string]: ValidDeposit } = {};
|
||||||
|
|
||||||
for (const log of depositLogs) {
|
for (const log of depositLogs) {
|
||||||
@ -94,19 +97,19 @@ const getValidDeposits = async (
|
|||||||
const decoded = decodeEventLog({
|
const decoded = decodeEventLog({
|
||||||
abi,
|
abi,
|
||||||
data: log.data,
|
data: log.data,
|
||||||
topics: log.topics
|
topics: log.topics,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get liquidity only for the selected token
|
// Get liquidity only for the selected token
|
||||||
if (decoded?.args.token.toLowerCase() !== token.toLowerCase()) continue;
|
if (decoded?.args.token.toLowerCase() !== token.toLowerCase()) continue;
|
||||||
|
|
||||||
const mappedBalance = await client.readContract({
|
const mappedBalance = await client.readContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: 'getBalance',
|
functionName: "getBalance",
|
||||||
args: [decoded.args.seller, token]
|
args: [decoded.args.seller, token],
|
||||||
});
|
});
|
||||||
|
|
||||||
let validDeposit: ValidDeposit | null = null;
|
let validDeposit: ValidDeposit | null = null;
|
||||||
|
|
||||||
if (mappedBalance) {
|
if (mappedBalance) {
|
||||||
@ -139,8 +142,8 @@ const getUnreleasedLockById = async (
|
|||||||
const lock = await client.readContract({
|
const lock = await client.readContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: 'mapLocks',
|
functionName: "mapLocks",
|
||||||
args: [BigInt(lockID)]
|
args: [BigInt(lockID)],
|
||||||
});
|
});
|
||||||
|
|
||||||
const pixTarget = lock.pixTarget;
|
const pixTarget = lock.pixTarget;
|
||||||
|
@ -13,8 +13,9 @@ const getPublicClient = (onlyRpcProvider = false) => {
|
|||||||
const user = useUser();
|
const user = useUser();
|
||||||
const rpcUrl = getProviderUrl();
|
const rpcUrl = getProviderUrl();
|
||||||
return createPublicClient({
|
return createPublicClient({
|
||||||
chain: Number(user.networkName.value) === sepolia.id ? sepolia : rootstock,
|
chain:
|
||||||
transport: http(rpcUrl)
|
Number(user.networkName.value) === sepolia.id ? sepolia : rootstock,
|
||||||
|
transport: http(rpcUrl),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return publicClient;
|
return publicClient;
|
||||||
@ -35,16 +36,17 @@ const getContract = async (onlyRpcProvider = false) => {
|
|||||||
const connectProvider = async (p: any): Promise<void> => {
|
const connectProvider = async (p: any): Promise<void> => {
|
||||||
console.log("Connecting to provider...");
|
console.log("Connecting to provider...");
|
||||||
const user = useUser();
|
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({
|
publicClient = createPublicClient({
|
||||||
chain,
|
chain,
|
||||||
transport: custom(p)
|
transport: custom(p),
|
||||||
});
|
});
|
||||||
|
|
||||||
walletClient = createWalletClient({
|
walletClient = createWalletClient({
|
||||||
chain,
|
chain,
|
||||||
transport: custom(p)
|
transport: custom(p),
|
||||||
});
|
});
|
||||||
|
|
||||||
await updateWalletStatus();
|
await updateWalletStatus();
|
||||||
|
@ -26,8 +26,8 @@ const approveTokens = async (participant: Participant): Promise<any> => {
|
|||||||
const allowance = await publicClient.readContract({
|
const allowance = await publicClient.readContract({
|
||||||
address: tokenAddress,
|
address: tokenAddress,
|
||||||
abi: mockToken.abi,
|
abi: mockToken.abi,
|
||||||
functionName: 'allowance',
|
functionName: "allowance",
|
||||||
args: [account, getP2PixAddress()]
|
args: [account, getP2PixAddress()],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (allowance < parseEther(participant.offer.toString())) {
|
if (allowance < parseEther(participant.offer.toString())) {
|
||||||
@ -35,9 +35,9 @@ const approveTokens = async (participant: Participant): Promise<any> => {
|
|||||||
const hash = await walletClient.writeContract({
|
const hash = await walletClient.writeContract({
|
||||||
address: tokenAddress,
|
address: tokenAddress,
|
||||||
abi: mockToken.abi,
|
abi: mockToken.abi,
|
||||||
functionName: 'approve',
|
functionName: "approve",
|
||||||
args: [getP2PixAddress(), parseEther(participant.offer.toString())],
|
args: [getP2PixAddress(), parseEther(participant.offer.toString())],
|
||||||
account
|
account,
|
||||||
});
|
});
|
||||||
|
|
||||||
await publicClient.waitForTransactionReceipt({ hash });
|
await publicClient.waitForTransactionReceipt({ hash });
|
||||||
@ -63,15 +63,15 @@ const addDeposit = async (): Promise<any> => {
|
|||||||
const hash = await walletClient.writeContract({
|
const hash = await walletClient.writeContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: 'deposit',
|
functionName: "deposit",
|
||||||
args: [
|
args: [
|
||||||
sellerId.id,
|
sellerId.id,
|
||||||
toHex("", { size: 32 }),
|
toHex("", { size: 32 }),
|
||||||
getTokenAddress(user.selectedToken.value),
|
getTokenAddress(user.selectedToken.value),
|
||||||
parseEther(user.seller.value.offer),
|
parseEther(user.seller.value.offer),
|
||||||
true
|
true,
|
||||||
],
|
],
|
||||||
account
|
account,
|
||||||
});
|
});
|
||||||
|
|
||||||
const receipt = await client.waitForTransactionReceipt({ hash });
|
const receipt = await client.waitForTransactionReceipt({ hash });
|
||||||
|
@ -1,16 +1,9 @@
|
|||||||
import {
|
import { decodeEventLog, formatEther, type Log, parseAbi } from "viem";
|
||||||
decodeEventLog,
|
|
||||||
formatEther,
|
|
||||||
getAddress,
|
|
||||||
type Log,
|
|
||||||
parseAbi,
|
|
||||||
} from "viem";
|
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
|
|
||||||
import { getPublicClient, getWalletClient, getContract } from "./provider";
|
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 p2pix from "@/utils/smart_contract_files/P2PIX.json";
|
||||||
|
|
||||||
import { getValidDeposits } from "./events";
|
import { getValidDeposits } from "./events";
|
||||||
@ -63,8 +56,8 @@ const getLockStatus = async (id: bigint): Promise<number> => {
|
|||||||
const result = await client.readContract({
|
const result = await client.readContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: 'getLocksStatus',
|
functionName: "getLocksStatus",
|
||||||
args: [[id]]
|
args: [[id]],
|
||||||
});
|
});
|
||||||
return result[1][0];
|
return result[1][0];
|
||||||
};
|
};
|
||||||
@ -90,9 +83,7 @@ const filterLockStatus = async (
|
|||||||
const tx: WalletTransaction = {
|
const tx: WalletTransaction = {
|
||||||
token: args.token ? String(args.token) : "",
|
token: args.token ? String(args.token) : "",
|
||||||
blockNumber: Number(transaction.blockNumber),
|
blockNumber: Number(transaction.blockNumber),
|
||||||
amount: args.amount
|
amount: args.amount ? Number(formatEther(args.amount)) : -1,
|
||||||
? Number(formatEther(args.amount))
|
|
||||||
: -1,
|
|
||||||
seller: args.seller ? String(args.seller) : "",
|
seller: args.seller ? String(args.seller) : "",
|
||||||
buyer: args.buyer ? String(args.buyer) : "",
|
buyer: args.buyer ? String(args.buyer) : "",
|
||||||
event: decoded.eventName || "",
|
event: decoded.eventName || "",
|
||||||
@ -116,53 +107,61 @@ const filterLockStatus = async (
|
|||||||
export const listAllTransactionByWalletAddress = async (
|
export const listAllTransactionByWalletAddress = async (
|
||||||
walletAddress: string
|
walletAddress: string
|
||||||
): Promise<WalletTransaction[]> => {
|
): Promise<WalletTransaction[]> => {
|
||||||
const { address, abi, client } = await getContract(true);
|
const { address, client } = await getContract(true);
|
||||||
|
|
||||||
// Get deposits
|
// Get deposits
|
||||||
const depositLogs = await client.getLogs({
|
const depositLogs = await client.getLogs({
|
||||||
address,
|
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: {
|
args: {
|
||||||
seller: walletAddress
|
seller: walletAddress,
|
||||||
},
|
},
|
||||||
fromBlock: 0n,
|
fromBlock: 0n,
|
||||||
toBlock: 'latest'
|
toBlock: "latest",
|
||||||
});
|
});
|
||||||
console.log("Fetched all wallet deposits");
|
console.log("Fetched all wallet deposits");
|
||||||
|
|
||||||
// Get locks
|
// Get locks
|
||||||
const lockLogs = await client.getLogs({
|
const lockLogs = await client.getLogs({
|
||||||
address,
|
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: {
|
args: {
|
||||||
buyer: walletAddress
|
buyer: walletAddress,
|
||||||
},
|
},
|
||||||
fromBlock: 0n,
|
fromBlock: 0n,
|
||||||
toBlock: 'latest'
|
toBlock: "latest",
|
||||||
});
|
});
|
||||||
console.log("Fetched all wallet locks");
|
console.log("Fetched all wallet locks");
|
||||||
|
|
||||||
// Get released locks
|
// Get released locks
|
||||||
const releasedLogs = await client.getLogs({
|
const releasedLogs = await client.getLogs({
|
||||||
address,
|
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: {
|
args: {
|
||||||
buyer: walletAddress
|
buyer: walletAddress,
|
||||||
},
|
},
|
||||||
fromBlock: 0n,
|
fromBlock: 0n,
|
||||||
toBlock: 'latest'
|
toBlock: "latest",
|
||||||
});
|
});
|
||||||
console.log("Fetched all wallet released locks");
|
console.log("Fetched all wallet released locks");
|
||||||
|
|
||||||
// Get withdrawn deposits
|
// Get withdrawn deposits
|
||||||
const withdrawnLogs = await client.getLogs({
|
const withdrawnLogs = await client.getLogs({
|
||||||
address,
|
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: {
|
args: {
|
||||||
seller: walletAddress
|
seller: walletAddress,
|
||||||
},
|
},
|
||||||
fromBlock: 0n,
|
fromBlock: 0n,
|
||||||
toBlock: 'latest'
|
toBlock: "latest",
|
||||||
});
|
});
|
||||||
console.log("Fetched all wallet withdrawn deposits");
|
console.log("Fetched all wallet withdrawn deposits");
|
||||||
|
|
||||||
@ -170,7 +169,7 @@ export const listAllTransactionByWalletAddress = async (
|
|||||||
...depositLogs,
|
...depositLogs,
|
||||||
...lockLogs,
|
...lockLogs,
|
||||||
...releasedLogs,
|
...releasedLogs,
|
||||||
...withdrawnLogs
|
...withdrawnLogs,
|
||||||
].sort((a: Log, b: Log) => {
|
].sort((a: Log, b: Log) => {
|
||||||
return Number(b.blockNumber) - Number(a.blockNumber);
|
return Number(b.blockNumber) - Number(a.blockNumber);
|
||||||
});
|
});
|
||||||
@ -182,16 +181,18 @@ export const listAllTransactionByWalletAddress = async (
|
|||||||
export const listReleaseTransactionByWalletAddress = async (
|
export const listReleaseTransactionByWalletAddress = async (
|
||||||
walletAddress: string
|
walletAddress: string
|
||||||
) => {
|
) => {
|
||||||
const { address, abi, client } = await getContract(true);
|
const { address, client } = await getContract(true);
|
||||||
|
|
||||||
const releasedLogs = await client.getLogs({
|
const releasedLogs = await client.getLogs({
|
||||||
address,
|
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: {
|
args: {
|
||||||
buyer: walletAddress
|
buyer: walletAddress,
|
||||||
},
|
},
|
||||||
fromBlock: 0n,
|
fromBlock: 0n,
|
||||||
toBlock: 'latest'
|
toBlock: "latest",
|
||||||
});
|
});
|
||||||
|
|
||||||
return releasedLogs
|
return releasedLogs
|
||||||
@ -203,7 +204,7 @@ export const listReleaseTransactionByWalletAddress = async (
|
|||||||
return decodeEventLog({
|
return decodeEventLog({
|
||||||
abi: p2pix.abi,
|
abi: p2pix.abi,
|
||||||
data: log.data,
|
data: log.data,
|
||||||
topics: log.topics
|
topics: log.topics,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error decoding log", error);
|
console.error("Error decoding log", error);
|
||||||
@ -213,19 +214,19 @@ export const listReleaseTransactionByWalletAddress = async (
|
|||||||
.filter((decoded: any) => decoded !== null);
|
.filter((decoded: any) => decoded !== null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const listLockTransactionByWalletAddress = async (
|
const listLockTransactionByWalletAddress = async (walletAddress: string) => {
|
||||||
walletAddress: string
|
const { address, client } = await getContract(true);
|
||||||
) => {
|
|
||||||
const { address, abi, client } = await getContract(true);
|
|
||||||
|
|
||||||
const lockLogs = await client.getLogs({
|
const lockLogs = await client.getLogs({
|
||||||
address,
|
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: {
|
args: {
|
||||||
buyer: walletAddress
|
buyer: walletAddress,
|
||||||
},
|
},
|
||||||
fromBlock: 0n,
|
fromBlock: 0n,
|
||||||
toBlock: 'latest'
|
toBlock: "latest",
|
||||||
});
|
});
|
||||||
|
|
||||||
return lockLogs
|
return lockLogs
|
||||||
@ -237,7 +238,7 @@ const listLockTransactionByWalletAddress = async (
|
|||||||
return decodeEventLog({
|
return decodeEventLog({
|
||||||
abi: p2pix.abi,
|
abi: p2pix.abi,
|
||||||
data: log.data,
|
data: log.data,
|
||||||
topics: log.topics
|
topics: log.topics,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error decoding log", error);
|
console.error("Error decoding log", error);
|
||||||
@ -247,17 +248,17 @@ const listLockTransactionByWalletAddress = async (
|
|||||||
.filter((decoded: any) => decoded !== null);
|
.filter((decoded: any) => decoded !== null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const listLockTransactionBySellerAddress = async (
|
const listLockTransactionBySellerAddress = async (sellerAddress: string) => {
|
||||||
sellerAddress: string
|
const { address, client } = await getContract(true);
|
||||||
) => {
|
|
||||||
const { address, abi, client } = await getContract(true);
|
|
||||||
console.log("Will get locks as seller", sellerAddress);
|
console.log("Will get locks as seller", sellerAddress);
|
||||||
|
|
||||||
const lockLogs = await client.getLogs({
|
const lockLogs = await client.getLogs({
|
||||||
address,
|
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,
|
fromBlock: 0n,
|
||||||
toBlock: 'latest'
|
toBlock: "latest",
|
||||||
});
|
});
|
||||||
|
|
||||||
return lockLogs
|
return lockLogs
|
||||||
@ -266,7 +267,7 @@ const listLockTransactionBySellerAddress = async (
|
|||||||
return decodeEventLog({
|
return decodeEventLog({
|
||||||
abi: p2pix.abi,
|
abi: p2pix.abi,
|
||||||
data: log.data,
|
data: log.data,
|
||||||
topics: log.topics
|
topics: log.topics,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error decoding log", error);
|
console.error("Error decoding log", error);
|
||||||
@ -275,7 +276,9 @@ const listLockTransactionBySellerAddress = async (
|
|||||||
})
|
})
|
||||||
.filter((decoded: any) => decoded !== null)
|
.filter((decoded: any) => decoded !== null)
|
||||||
.filter(
|
.filter(
|
||||||
(decoded: any) => decoded.args && decoded.args.seller &&
|
(decoded: any) =>
|
||||||
|
decoded.args &&
|
||||||
|
decoded.args.seller &&
|
||||||
decoded.args.seller.toLowerCase() === sellerAddress.toLowerCase()
|
decoded.args.seller.toLowerCase() === sellerAddress.toLowerCase()
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -297,8 +300,8 @@ export const checkUnreleasedLock = async (
|
|||||||
const lockStatus = await client.readContract({
|
const lockStatus = await client.readContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: 'getLocksStatus',
|
functionName: "getLocksStatus",
|
||||||
args: [lockIds]
|
args: [lockIds],
|
||||||
});
|
});
|
||||||
|
|
||||||
const unreleasedLockId = lockStatus[1].findIndex(
|
const unreleasedLockId = lockStatus[1].findIndex(
|
||||||
@ -311,8 +314,8 @@ export const checkUnreleasedLock = async (
|
|||||||
const lock = await client.readContract({
|
const lock = await client.readContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: 'mapLocks',
|
functionName: "mapLocks",
|
||||||
args: [lockID]
|
args: [lockID],
|
||||||
});
|
});
|
||||||
|
|
||||||
const pixTarget = lock.pixTarget;
|
const pixTarget = lock.pixTarget;
|
||||||
@ -340,8 +343,8 @@ export const getActiveLockAmount = async (
|
|||||||
const lockStatus = await client.readContract({
|
const lockStatus = await client.readContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: 'getLocksStatus',
|
functionName: "getLocksStatus",
|
||||||
args: [lockIds]
|
args: [lockIds],
|
||||||
});
|
});
|
||||||
|
|
||||||
let activeLockAmount = 0;
|
let activeLockAmount = 0;
|
||||||
@ -351,8 +354,8 @@ export const getActiveLockAmount = async (
|
|||||||
const lock = await client.readContract({
|
const lock = await client.readContract({
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
functionName: 'mapLocks',
|
functionName: "mapLocks",
|
||||||
args: [lockId]
|
args: [lockId],
|
||||||
});
|
});
|
||||||
activeLockAmount += Number(formatEther(lock.amount));
|
activeLockAmount += Number(formatEther(lock.amount));
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
|||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
import type { WalletTransaction } from "@/model/WalletTransaction";
|
import type { WalletTransaction } from "@/model/WalletTransaction";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
|
||||||
import { onMounted, ref, watch } from "vue";
|
import { onMounted, ref, watch } from "vue";
|
||||||
import ListingComponent from "../ListingComponent/ListingComponent.vue";
|
import ListingComponent from "../ListingComponent/ListingComponent.vue";
|
||||||
|
|
||||||
@ -151,6 +150,8 @@ p {
|
|||||||
}
|
}
|
||||||
|
|
||||||
input[type="number"] {
|
input[type="number"] {
|
||||||
|
appearance: textfield;
|
||||||
|
-webkit-appearance: textfield;
|
||||||
-moz-appearance: textfield;
|
-moz-appearance: textfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { withdrawDeposit } from "@/blockchain/buyerMethods";
|
|
||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
import type { WalletTransaction } from "@/model/WalletTransaction";
|
import type { WalletTransaction } from "@/model/WalletTransaction";
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
import { describe, expect, beforeEach } from "vitest";
|
||||||
import { mount } from "@vue/test-utils";
|
import { mount } from "@vue/test-utils";
|
||||||
import ListingComponent from "../ListingComponent.vue";
|
import ListingComponent from "../ListingComponent.vue";
|
||||||
import SpinnerComponent from "../../SpinnerComponent.vue";
|
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import { MockValidDeposits } from "@/model/mock/ValidDepositMock";
|
import { MockValidDeposits } from "@/model/mock/ValidDepositMock";
|
||||||
import { MockWalletTransactions } from "@/model/mock/WalletTransactionMock";
|
import { MockWalletTransactions } from "@/model/mock/WalletTransactionMock";
|
||||||
|
@ -2,14 +2,6 @@
|
|||||||
import { onMounted, onUnmounted, ref } from "vue";
|
import { onMounted, onUnmounted, ref } from "vue";
|
||||||
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
||||||
import CustomModal from "@/components//CustomModal/CustomModal.vue";
|
import CustomModal from "@/components//CustomModal/CustomModal.vue";
|
||||||
import QRCode from "qrcode";
|
|
||||||
|
|
||||||
// props and store references
|
|
||||||
const props = defineProps({
|
|
||||||
sellerId: String,
|
|
||||||
amount: Number,
|
|
||||||
qrcode: String,
|
|
||||||
});
|
|
||||||
|
|
||||||
const windowSize = ref<number>(window.innerWidth);
|
const windowSize = ref<number>(window.innerWidth);
|
||||||
const qrCode = ref<string>("");
|
const qrCode = ref<string>("");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import SpinnerComponent from "@/components/SpinnerComponent.vue";
|
import SpinnerComponent from "@/components/SpinnerComponent.vue";
|
||||||
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import { ref, computed } from "vue";
|
import { ref, computed } from "vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
||||||
import { pixFormatValidation, postProcessKey } from "@/utils/pixKeyFormat";
|
import { postProcessKey } from "@/utils/pixKeyFormat";
|
||||||
import { TokenEnum } from "@/model/NetworkEnum";
|
import { TokenEnum } from "@/model/NetworkEnum";
|
||||||
import { getTokenImage } from "@/utils/imagesPath";
|
import { getTokenImage } from "@/utils/imagesPath";
|
||||||
import { useOnboard } from "@web3-onboard/vue";
|
import { useOnboard } from "@web3-onboard/vue";
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from "vue";
|
import { ref } from "vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import SpinnerComponent from "@/components/SpinnerComponent.vue";
|
|
||||||
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
import CustomButton from "@/components/CustomButton/CustomButton.vue";
|
||||||
import { debounce } from "@/utils/debounce";
|
import { debounce } from "@/utils/debounce";
|
||||||
import { decimalCount } from "@/utils/decimalCount";
|
import { decimalCount } from "@/utils/decimalCount";
|
||||||
@ -153,6 +152,8 @@ const handleInputEvent = (event: any): void => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
input[type="number"] {
|
input[type="number"] {
|
||||||
|
appearance: textfield;
|
||||||
|
-webkit-appearance: textfield;
|
||||||
-moz-appearance: textfield;
|
-moz-appearance: textfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,8 @@ p {
|
|||||||
}
|
}
|
||||||
|
|
||||||
input[type="number"] {
|
input[type="number"] {
|
||||||
|
appearance: textfield;
|
||||||
|
-webkit-appearance: textfield;
|
||||||
-moz-appearance: textfield;
|
-moz-appearance: textfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch, onMounted, watchEffect } from "vue";
|
import { ref, computed, watch, onMounted } from "vue";
|
||||||
import { useOnboard } from "@web3-onboard/vue";
|
import { useOnboard } from "@web3-onboard/vue";
|
||||||
import { Networks } from "../model/Networks";
|
import { Networks } from "../model/Networks";
|
||||||
import { NetworkEnum } from "../model/NetworkEnum";
|
import { NetworkEnum } from "../model/NetworkEnum";
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { useRouter } from "vue-router";
|
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import { onClickOutside } from "@vueuse/core";
|
import { onClickOutside } from "@vueuse/core";
|
||||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
import { describe, it, expect, beforeEach } from "vitest";
|
||||||
import { mount } from "@vue/test-utils";
|
import { mount } from "@vue/test-utils";
|
||||||
import TopBar from "../TopBar.vue";
|
import TopBar from "../TopBar.vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
|
@ -1,74 +1,73 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from "vue";
|
||||||
import { NetworkEnum, TokenEnum } from "../model/NetworkEnum"
|
import { NetworkEnum, TokenEnum } from "../model/NetworkEnum";
|
||||||
import type { ValidDeposit } from "@/model/ValidDeposit"
|
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||||
import type { Participant } from "../utils/bbPay"
|
import type { Participant } from "../utils/bbPay";
|
||||||
|
|
||||||
const walletAddress = ref("")
|
const walletAddress = ref("");
|
||||||
const balance = ref("")
|
const balance = ref("");
|
||||||
const networkName = ref(NetworkEnum.sepolia)
|
const networkName = ref(NetworkEnum.sepolia);
|
||||||
const selectedToken = ref(TokenEnum.BRZ)
|
const selectedToken = ref(TokenEnum.BRZ);
|
||||||
const loadingLock = ref(false)
|
const loadingLock = ref(false);
|
||||||
const sellerView = ref(false)
|
const sellerView = ref(false);
|
||||||
const depositsValidList = ref<ValidDeposit[]>([])
|
const depositsValidList = ref<ValidDeposit[]>([]);
|
||||||
const loadingWalletTransactions = ref(false)
|
const loadingWalletTransactions = ref(false);
|
||||||
const loadingNetworkLiquidity = ref(false)
|
const loadingNetworkLiquidity = ref(false);
|
||||||
const seller = ref<Participant>({} as Participant)
|
const seller = ref<Participant>({} as Participant);
|
||||||
const sellerId = ref("")
|
const sellerId = ref("");
|
||||||
|
|
||||||
export function useUser() {
|
export function useUser() {
|
||||||
|
|
||||||
// Actions become regular functions
|
// Actions become regular functions
|
||||||
const setWalletAddress = (address: string) => {
|
const setWalletAddress = (address: string) => {
|
||||||
walletAddress.value = address
|
walletAddress.value = address;
|
||||||
}
|
};
|
||||||
|
|
||||||
const setBalance = (newBalance: string) => {
|
const setBalance = (newBalance: string) => {
|
||||||
balance.value = newBalance
|
balance.value = newBalance;
|
||||||
}
|
};
|
||||||
|
|
||||||
const setSelectedToken = (token: TokenEnum) => {
|
const setSelectedToken = (token: TokenEnum) => {
|
||||||
selectedToken.value = token
|
selectedToken.value = token;
|
||||||
}
|
};
|
||||||
|
|
||||||
const setNetworkId = (network: NetworkEnum) => {
|
const setNetworkId = (network: NetworkEnum) => {
|
||||||
console.log("setNetworkId", network)
|
console.log("setNetworkId", network);
|
||||||
networkName.value = Number(network)
|
networkName.value = Number(network);
|
||||||
}
|
};
|
||||||
|
|
||||||
const setLoadingLock = (isLoading: boolean) => {
|
const setLoadingLock = (isLoading: boolean) => {
|
||||||
loadingLock.value = isLoading
|
loadingLock.value = isLoading;
|
||||||
}
|
};
|
||||||
|
|
||||||
const setSellerView = (view: boolean) => {
|
const setSellerView = (view: boolean) => {
|
||||||
sellerView.value = view
|
sellerView.value = view;
|
||||||
}
|
};
|
||||||
|
|
||||||
const setDepositsValidList = (deposits: ValidDeposit[]) => {
|
const setDepositsValidList = (deposits: ValidDeposit[]) => {
|
||||||
depositsValidList.value = deposits
|
depositsValidList.value = deposits;
|
||||||
}
|
};
|
||||||
|
|
||||||
const setLoadingWalletTransactions = (isLoading: boolean) => {
|
const setLoadingWalletTransactions = (isLoading: boolean) => {
|
||||||
loadingWalletTransactions.value = isLoading
|
loadingWalletTransactions.value = isLoading;
|
||||||
}
|
};
|
||||||
|
|
||||||
const setLoadingNetworkLiquidity = (isLoading: boolean) => {
|
const setLoadingNetworkLiquidity = (isLoading: boolean) => {
|
||||||
loadingNetworkLiquidity.value = isLoading
|
loadingNetworkLiquidity.value = isLoading;
|
||||||
}
|
};
|
||||||
|
|
||||||
const setSeller = (newSeller: Participant) => {
|
const setSeller = (newSeller: Participant) => {
|
||||||
seller.value = newSeller
|
seller.value = newSeller;
|
||||||
}
|
};
|
||||||
|
|
||||||
const setSellerId = (id: string) => {
|
const setSellerId = (id: string) => {
|
||||||
sellerId.value = id
|
sellerId.value = id;
|
||||||
}
|
};
|
||||||
|
|
||||||
// Getters become computed or regular functions
|
// Getters become computed or regular functions
|
||||||
const getValidDepositByWalletAddress = (address: string) => {
|
const getValidDepositByWalletAddress = (address: string) => {
|
||||||
return depositsValidList.value
|
return depositsValidList.value
|
||||||
.filter((deposit) => deposit.seller == address)
|
.filter((deposit) => deposit.seller == address)
|
||||||
.sort((a, b) => b.blockNumber - a.blockNumber)
|
.sort((a, b) => b.blockNumber - a.blockNumber);
|
||||||
}
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// State
|
// State
|
||||||
@ -98,6 +97,6 @@ export function useUser() {
|
|||||||
setSellerId,
|
setSellerId,
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
getValidDepositByWalletAddress
|
getValidDepositByWalletAddress,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,10 @@ const showModal = ref<boolean>(false);
|
|||||||
const showBuyAlert = ref<boolean>(false);
|
const showBuyAlert = ref<boolean>(false);
|
||||||
const paramLockID = window.history.state?.lockID;
|
const paramLockID = window.history.state?.lockID;
|
||||||
|
|
||||||
const confirmBuyClick = async (selectedDeposit: ValidDeposit, tokenValue: number) => {
|
const confirmBuyClick = async (
|
||||||
|
selectedDeposit: ValidDeposit,
|
||||||
|
tokenValue: number
|
||||||
|
) => {
|
||||||
pixTarget.value = selectedDeposit.pixKey;
|
pixTarget.value = selectedDeposit.pixKey;
|
||||||
tokenAmount.value = tokenValue;
|
tokenAmount.value = tokenValue;
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, watch } from "vue";
|
import { ref } from "vue";
|
||||||
|
|
||||||
import SellerComponent from "@/components/SellerSteps/SellerComponent.vue";
|
import SellerComponent from "@/components/SellerSteps/SellerComponent.vue";
|
||||||
import SearchComponent from "@/components/SearchComponent.vue";
|
|
||||||
import SendNetwork from "@/components/SellerSteps/SendNetwork.vue";
|
import SendNetwork from "@/components/SellerSteps/SendNetwork.vue";
|
||||||
import SellerSearchComponent from "@/components/SellerSteps/SellerSearchComponent.vue";
|
|
||||||
import LoadingComponent from "@/components/LoadingComponent/LoadingComponent.vue";
|
import LoadingComponent from "@/components/LoadingComponent/LoadingComponent.vue";
|
||||||
import { useUser } from "@/composables/useUser";
|
import { useUser } from "@/composables/useUser";
|
||||||
import { approveTokens, addDeposit } from "@/blockchain/sellerMethods";
|
import { approveTokens, addDeposit } from "@/blockchain/sellerMethods";
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
],
|
],
|
||||||
"preserveValueImports": false,
|
"preserveValueImports": false,
|
||||||
"importsNotUsedAsValues": "remove",
|
"importsNotUsedAsValues": "remove",
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": false
|
||||||
},
|
},
|
||||||
"references": [
|
"references": [
|
||||||
{
|
{
|
||||||
@ -38,4 +38,4 @@
|
|||||||
"node_modules",
|
"node_modules",
|
||||||
"./node_modules"
|
"./node_modules"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -36,6 +36,9 @@ export default defineConfig({
|
|||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
||||||
|
"viem/errors": fileURLToPath(
|
||||||
|
new URL("./node_modules/viem/errors", import.meta.url)
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user