refactor: clean up code formatting and improve readability across multiple components

- Standardized the use of quotes and spacing in various files.
- Removed unnecessary line breaks and trailing spaces in components.
- Improved the structure of computed properties and methods for better clarity.
- Enhanced the consistency of prop definitions and emit events in Vue components.
- Updated the GraphQL composable to streamline error handling and data processing.
- Refactored network configuration files for better organization and readability.
- Cleaned up model files by removing redundant lines and ensuring consistent formatting.
- Adjusted router configuration for improved readability.
- Enhanced utility functions for better maintainability and clarity.
This commit is contained in:
2026-05-04 20:04:19 -03:00
committed by hueso
parent c481d9d0a5
commit d63cb8c6d3
52 changed files with 1645 additions and 1606 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,11 @@
import { getContract } from "./provider";
import { ChainContract } from "viem";
import {
parseEther,
type Address,
type TransactionReceipt,
} from "viem";
import { parseEther, type Address, type TransactionReceipt } from "viem";
export const addLock = async (
sellerAddress: Address,
tokenAddress: Address,
amount: number
amount: number,
): Promise<bigint> => {
const { address, abi, wallet, client, account } = await getContract();
const parsedAmount = parseEther(amount.toString());
@@ -36,7 +32,7 @@ export const addLock = async (
export const withdrawDeposit = async (
amount: string,
token: Address
token: Address,
): Promise<boolean> => {
const { address, abi, wallet, client, account } = await getContract();
@@ -49,7 +45,7 @@ export const withdrawDeposit = async (
abi,
functionName: "withdraw",
args: [token, parseEther(amount), []],
account
account,
});
const hash = await wallet.writeContract(request);
@@ -60,8 +56,8 @@ export const withdrawDeposit = async (
export const releaseLock = async (
lockID: bigint,
pixTimestamp: `0x${string}`&{lenght:34},
signature: `0x${string}`
pixTimestamp: `0x${string}` & { lenght: 34 },
signature: `0x${string}`,
): Promise<TransactionReceipt> => {
const { address, abi, wallet, client, account } = await getContract();
@@ -74,7 +70,7 @@ export const releaseLock = async (
abi,
functionName: "release",
args: [BigInt(lockID), pixTimestamp, signature],
account
account,
});
const hash = await wallet.writeContract(request);

View File

@@ -3,7 +3,7 @@ import { formatEther, toHex, stringToHex } from "viem";
import type { PublicClient, Address } from "viem";
import { Networks } from "@/config/networks";
import { getContract } from "./provider";
import { p2PixAbi } from "./abi"
import { p2PixAbi } from "./abi";
import type { ValidDeposit } from "@/model/ValidDeposit";
import type { NetworkConfig } from "@/model/NetworkEnum";
import type { UnreleasedLock } from "@/model/UnreleasedLock";
@@ -18,7 +18,7 @@ const getNetworksLiquidity = async (): Promise<void> => {
for (const network of Object.values(Networks)) {
const deposits = await getValidDeposits(
user.network.value.tokens[user.selectedToken.value].address,
network
network,
);
if (deposits) depositLists.push(deposits);
}
@@ -30,7 +30,7 @@ const getNetworksLiquidity = async (): Promise<void> => {
const getParticipantID = async (
seller: Address,
token: Address
token: Address,
): Promise<string> => {
const { address, abi, client } = await getContract();
@@ -51,7 +51,7 @@ const getParticipantID = async (
hexString
.slice(2)
.match(/.{1,2}/g)!
.map((byte: string) => parseInt(byte, 16))
.map((byte: string) => parseInt(byte, 16)),
);
// Remove null bytes from the end of the string
return new TextDecoder().decode(bytes).replace(/\0/g, "");
@@ -60,7 +60,7 @@ const getParticipantID = async (
const getValidDeposits = async (
token: Address,
network: NetworkConfig,
contractInfo?: { client: PublicClient; address: Address }
contractInfo?: { client: PublicClient; address: Address },
): Promise<ValidDeposit[]> => {
let client: PublicClient, abi;
@@ -84,7 +84,7 @@ const getValidDeposits = async (
`,
};
const depositLogs = await fetch( network.subgraphUrls[0], {
const depositLogs = await fetch(network.subgraphUrls[0], {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -104,7 +104,7 @@ const getValidDeposits = async (
acc[deposit.seller] = true;
return acc;
},
{} as Record<Address, boolean>
{} as Record<Address, boolean>,
);
if (!contractInfo) {
@@ -147,11 +147,11 @@ const getValidDeposits = async (
};
const getUnreleasedLockById = async (
lockID: bigint
lockID: bigint,
): Promise<UnreleasedLock> => {
const { address, abi, client } = await getContract();
const [ , , , amount, token, seller ] = await client.readContract({
const [, , , amount, token, seller] = await client.readContract({
address,
abi,
functionName: "mapLocks",

View File

@@ -15,14 +15,14 @@ import type { ChainContract } from "viem";
let walletClient: WalletClient | null = null;
const getPublicClient = (): PublicClient => {
const user = useUser();
const rpcUrl = (user.network.value as NetworkConfig).rpcUrls.default.http[0];
const chain = user.network.value;
const user = useUser();
const rpcUrl = (user.network.value as NetworkConfig).rpcUrls.default.http[0];
const chain = user.network.value;
return createPublicClient({
chain,
transport: http(rpcUrl),
});
return createPublicClient({
chain,
transport: http(rpcUrl),
});
};
const getWalletClient = (): WalletClient | null => {
@@ -32,7 +32,8 @@ const getWalletClient = (): WalletClient | null => {
const getContract = async (onlyRpcProvider = false) => {
const client = getPublicClient();
const user = useUser();
const address = (user.network.value.contracts?.p2pix as ChainContract).address;
const address = (user.network.value.contracts?.p2pix as ChainContract)
.address;
const abi = p2PixAbi;
const wallet = onlyRpcProvider ? null : getWalletClient();

View File

@@ -7,7 +7,7 @@ import type { Participant } from "@/utils/bbPay";
import type { Address } from "viem";
const getP2PixAddress = (): Address => {
const user = useUser();
const user = useUser();
return (user.network.value.contracts?.p2pix as ChainContract).address;
};
@@ -24,7 +24,8 @@ const approveTokens = async (participant: Participant): Promise<any> => {
const [account] = await walletClient.getAddresses();
// Get token address
const tokenAddress = user.network.value.tokens[user.selectedToken.value].address;
const tokenAddress =
user.network.value.tokens[user.selectedToken.value].address;
// Check if the token is already approved
const allowance = await publicClient.readContract({
@@ -34,7 +35,7 @@ const approveTokens = async (participant: Participant): Promise<any> => {
args: [account, getP2PixAddress()],
});
if ( allowance < parseEther(participant.offer.toString()) ) {
if (allowance < parseEther(participant.offer.toString())) {
// Approve tokens
const chain = user.network.value;
const hash = await walletClient.writeContract({

View File

@@ -30,12 +30,12 @@ export const updateWalletStatus = async (): Promise<void> => {
};
export const listValidDepositTransactionsByWalletAddress = async (
walletAddress: Address
walletAddress: Address,
): Promise<ValidDeposit[]> => {
const user = useUser();
const walletDeposits = await getValidDeposits(
user.network.value.tokens[user.selectedToken.value].address,
user.network.value
user.network.value,
);
if (walletDeposits) {
return walletDeposits
@@ -50,7 +50,7 @@ export const listValidDepositTransactionsByWalletAddress = async (
const getLockStatus = async (id: bigint): Promise<LockStatus> => {
const { address, abi, client } = await getContract();
const [ sortedIDs , status ] = await client.readContract({
const [sortedIDs, status] = await client.readContract({
address,
abi,
functionName: "getLocksStatus",
@@ -60,7 +60,7 @@ const getLockStatus = async (id: bigint): Promise<LockStatus> => {
};
export const listAllTransactionByWalletAddress = async (
walletAddress: Address
walletAddress: Address,
): Promise<WalletTransaction[]> => {
const user = useUser();
@@ -199,7 +199,7 @@ export const listAllTransactionByWalletAddress = async (
// get wallet's release transactions
export const listReleaseTransactionByWalletAddress = async (
walletAddress: Address
walletAddress: Address,
) => {
const user = useUser();
const network = user.network.value;
@@ -403,7 +403,7 @@ const listLockTransactionBySellerAddress = async (sellerAddress: Address) => {
};
export const checkUnreleasedLock = async (
walletAddress: Address
walletAddress: Address,
): Promise<UnreleasedLock | undefined> => {
const { address, abi, client } = await getContract();
const addedLocks = await listLockTransactionByWalletAddress(walletAddress);
@@ -412,7 +412,7 @@ export const checkUnreleasedLock = async (
const lockIds = addedLocks.map((lock: any) => lock.args.lockID);
const [ sortedIDs, status ] = await client.readContract({
const [sortedIDs, status] = await client.readContract({
address,
abi,
functionName: "getLocksStatus",
@@ -420,15 +420,15 @@ export const checkUnreleasedLock = async (
});
const unreleasedLockId = status.findIndex(
(status: LockStatus) => status == LockStatus.Active
(status: LockStatus) => status == LockStatus.Active,
);
if (unreleasedLockId !== -1)
return getUnreleasedLockById(sortedIDs[unreleasedLockId]);
};
export const getActiveLockAmount = async (
walletAddress: Address
walletAddress: Address,
): Promise<number> => {
const { address, abi, client } = await getContract(true);
const lockSeller = await listLockTransactionBySellerAddress(walletAddress);
@@ -437,7 +437,7 @@ export const getActiveLockAmount = async (
const lockIds = lockSeller.map((lock: any) => lock.args.lockID);
const [ sortedIDs, status ] = await client.readContract({
const [sortedIDs, status] = await client.readContract({
address,
abi,
functionName: "getLocksStatus",
@@ -450,7 +450,7 @@ export const getActiveLockAmount = async (
abi,
functionName: "mapLocks",
args: [BigInt(id)],
})
}),
);
const mapLocksResults = await client.multicall({