refactor: standardize quote styles to single quotes across all files
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
import { getContract } from "./provider";
|
||||
import { ChainContract } from "viem";
|
||||
import { parseEther, type Address, type TransactionReceipt } from "viem";
|
||||
import { getContract } from './provider';
|
||||
import { ChainContract } from 'viem';
|
||||
import { parseEther, type Address, type TransactionReceipt } from 'viem';
|
||||
|
||||
export const addLock = async (
|
||||
sellerAddress: Address,
|
||||
@@ -11,13 +11,13 @@ export const addLock = async (
|
||||
const parsedAmount = parseEther(amount.toString());
|
||||
|
||||
if (!wallet) {
|
||||
throw new Error("Wallet not connected");
|
||||
throw new Error('Wallet not connected');
|
||||
}
|
||||
|
||||
const { result, request } = await client.simulateContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: "lock",
|
||||
functionName: 'lock',
|
||||
args: [sellerAddress, tokenAddress, parsedAmount, [], []],
|
||||
account,
|
||||
});
|
||||
@@ -25,7 +25,7 @@ export const addLock = async (
|
||||
const receipt = await client.waitForTransactionReceipt({ hash });
|
||||
|
||||
if (!receipt.status)
|
||||
throw new Error("Transaction failed: " + receipt.transactionHash);
|
||||
throw new Error('Transaction failed: ' + receipt.transactionHash);
|
||||
|
||||
return result;
|
||||
};
|
||||
@@ -37,13 +37,13 @@ export const withdrawDeposit = async (
|
||||
const { address, abi, wallet, client, account } = await getContract();
|
||||
|
||||
if (!wallet) {
|
||||
throw new Error("Wallet not connected");
|
||||
throw new Error('Wallet not connected');
|
||||
}
|
||||
|
||||
const { request } = await client.simulateContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: "withdraw",
|
||||
functionName: 'withdraw',
|
||||
args: [token, parseEther(amount), []],
|
||||
account,
|
||||
});
|
||||
@@ -51,7 +51,7 @@ export const withdrawDeposit = async (
|
||||
const hash = await wallet.writeContract(request);
|
||||
const receipt = await client.waitForTransactionReceipt({ hash });
|
||||
|
||||
return receipt.status === "success";
|
||||
return receipt.status === 'success';
|
||||
};
|
||||
|
||||
export const releaseLock = async (
|
||||
@@ -62,13 +62,13 @@ export const releaseLock = async (
|
||||
const { address, abi, wallet, client, account } = await getContract();
|
||||
|
||||
if (!wallet) {
|
||||
throw new Error("Wallet not connected");
|
||||
throw new Error('Wallet not connected');
|
||||
}
|
||||
|
||||
const { request } = await client.simulateContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: "release",
|
||||
functionName: 'release',
|
||||
args: [BigInt(lockID), pixTimestamp, signature],
|
||||
account,
|
||||
});
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { useUser } from "@/composables/useUser";
|
||||
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 type { ValidDeposit } from "@/model/ValidDeposit";
|
||||
import type { NetworkConfig } from "@/model/NetworkEnum";
|
||||
import type { UnreleasedLock } from "@/model/UnreleasedLock";
|
||||
import { ChainContract } from "viem";
|
||||
import { useUser } from '@/composables/useUser';
|
||||
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 type { ValidDeposit } from '@/model/ValidDeposit';
|
||||
import type { NetworkConfig } from '@/model/NetworkEnum';
|
||||
import type { UnreleasedLock } from '@/model/UnreleasedLock';
|
||||
import { ChainContract } from 'viem';
|
||||
|
||||
const getNetworksLiquidity = async (): Promise<void> => {
|
||||
const user = useUser();
|
||||
@@ -37,16 +37,16 @@ const getParticipantID = async (
|
||||
const participantIDHex = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: "getPixTarget",
|
||||
functionName: 'getPixTarget',
|
||||
args: [seller, token],
|
||||
});
|
||||
|
||||
// Remove '0x' prefix and convert hex to UTF-8 string
|
||||
const hexString =
|
||||
typeof participantIDHex === "string"
|
||||
typeof participantIDHex === 'string'
|
||||
? participantIDHex
|
||||
: toHex(participantIDHex as bigint);
|
||||
if (!hexString) throw new Error("Participant ID not found");
|
||||
if (!hexString) throw new Error('Participant ID not found');
|
||||
const bytes = new Uint8Array(
|
||||
hexString
|
||||
.slice(2)
|
||||
@@ -54,7 +54,7 @@ const getParticipantID = async (
|
||||
.map((byte: string) => parseInt(byte, 16)),
|
||||
);
|
||||
// Remove null bytes from the end of the string
|
||||
return new TextDecoder().decode(bytes).replace(/\0/g, "");
|
||||
return new TextDecoder().decode(bytes).replace(/\0/g, '');
|
||||
};
|
||||
|
||||
const getValidDeposits = async (
|
||||
@@ -85,9 +85,9 @@ const getValidDeposits = async (
|
||||
};
|
||||
|
||||
const depositLogs = await fetch(network.subgraphUrls[0], {
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
@@ -95,7 +95,7 @@ const getValidDeposits = async (
|
||||
// remove doubles from sellers list
|
||||
const depositData = await depositLogs.json();
|
||||
if (!depositData.data) {
|
||||
console.error("Error fetching deposit logs");
|
||||
console.error('Error fetching deposit logs');
|
||||
return [];
|
||||
}
|
||||
const depositAddeds = depositData.data.depositAddeds;
|
||||
@@ -119,7 +119,7 @@ const getValidDeposits = async (
|
||||
const balanceCalls = sellersList.map((seller) => ({
|
||||
address: (network.contracts?.p2pix as ChainContract).address,
|
||||
abi,
|
||||
functionName: "getBalance",
|
||||
functionName: 'getBalance',
|
||||
args: [seller, token],
|
||||
}));
|
||||
|
||||
@@ -138,7 +138,7 @@ const getValidDeposits = async (
|
||||
remaining: Number(formatEther(mappedBalance.result as bigint)),
|
||||
seller,
|
||||
network,
|
||||
participantID: "",
|
||||
participantID: '',
|
||||
};
|
||||
depositList[seller + token] = validDeposit;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ const getUnreleasedLockById = async (
|
||||
const [, , , amount, token, seller] = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: "mapLocks",
|
||||
functionName: 'mapLocks',
|
||||
args: [lockID],
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { p2PixAbi } from "./abi";
|
||||
import { updateWalletStatus } from "./wallet";
|
||||
import { p2PixAbi } from './abi';
|
||||
import { updateWalletStatus } from './wallet';
|
||||
import {
|
||||
createPublicClient,
|
||||
createWalletClient,
|
||||
@@ -7,10 +7,10 @@ import {
|
||||
http,
|
||||
PublicClient,
|
||||
WalletClient,
|
||||
} from "viem";
|
||||
import { useUser } from "@/composables/useUser";
|
||||
import type { NetworkConfig } from "@/model/NetworkEnum";
|
||||
import type { ChainContract } from "viem";
|
||||
} from 'viem';
|
||||
import { useUser } from '@/composables/useUser';
|
||||
import type { NetworkConfig } from '@/model/NetworkEnum';
|
||||
import type { ChainContract } from 'viem';
|
||||
|
||||
let walletClient: WalletClient | null = null;
|
||||
|
||||
@@ -38,7 +38,7 @@ const getContract = async (onlyRpcProvider = false) => {
|
||||
const wallet = onlyRpcProvider ? null : getWalletClient();
|
||||
|
||||
if (!client) {
|
||||
throw new Error("Public client not initialized");
|
||||
throw new Error('Public client not initialized');
|
||||
}
|
||||
|
||||
const [account] = wallet ? await wallet.getAddresses() : [null];
|
||||
@@ -50,7 +50,7 @@ const connectProvider = async (p: any): Promise<void> => {
|
||||
const user = useUser();
|
||||
const chain = user.network.value;
|
||||
|
||||
const [account] = await p!.request({ method: "eth_requestAccounts" });
|
||||
const [account] = await p!.request({ method: 'eth_requestAccounts' });
|
||||
|
||||
walletClient = createWalletClient({
|
||||
account,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { getContract, getPublicClient, getWalletClient } from "./provider";
|
||||
import { parseEther, toHex, ChainContract } from "viem";
|
||||
import { mockTokenAbi } from "./abi";
|
||||
import { useUser } from "@/composables/useUser";
|
||||
import { createParticipant } from "@/utils/bbPay";
|
||||
import type { Participant } from "@/utils/bbPay";
|
||||
import type { Address } from "viem";
|
||||
import { getContract, getPublicClient, getWalletClient } from './provider';
|
||||
import { parseEther, toHex, ChainContract } from 'viem';
|
||||
import { mockTokenAbi } from './abi';
|
||||
import { useUser } from '@/composables/useUser';
|
||||
import { createParticipant } from '@/utils/bbPay';
|
||||
import type { Participant } from '@/utils/bbPay';
|
||||
import type { Address } from 'viem';
|
||||
|
||||
const getP2PixAddress = (): Address => {
|
||||
const user = useUser();
|
||||
@@ -17,7 +17,7 @@ const approveTokens = async (participant: Participant): Promise<any> => {
|
||||
const walletClient = getWalletClient();
|
||||
|
||||
if (!publicClient || !walletClient) {
|
||||
throw new Error("Clients not initialized");
|
||||
throw new Error('Clients not initialized');
|
||||
}
|
||||
|
||||
user.setSeller(participant);
|
||||
@@ -31,7 +31,7 @@ const approveTokens = async (participant: Participant): Promise<any> => {
|
||||
const allowance = await publicClient.readContract({
|
||||
address: tokenAddress,
|
||||
abi: mockTokenAbi,
|
||||
functionName: "allowance",
|
||||
functionName: 'allowance',
|
||||
args: [account, getP2PixAddress()],
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ const approveTokens = async (participant: Participant): Promise<any> => {
|
||||
const hash = await walletClient.writeContract({
|
||||
address: tokenAddress,
|
||||
abi: mockTokenAbi,
|
||||
functionName: "approve",
|
||||
functionName: 'approve',
|
||||
args: [getP2PixAddress(), parseEther(participant.offer.toString())],
|
||||
account,
|
||||
chain,
|
||||
@@ -59,7 +59,7 @@ const addDeposit = async (): Promise<any> => {
|
||||
const user = useUser();
|
||||
|
||||
if (!walletClient) {
|
||||
throw new Error("Wallet client not initialized");
|
||||
throw new Error('Wallet client not initialized');
|
||||
}
|
||||
|
||||
const [account] = await walletClient.getAddresses();
|
||||
@@ -67,16 +67,16 @@ const addDeposit = async (): Promise<any> => {
|
||||
const sellerId = await createParticipant(user.seller.value);
|
||||
user.setSellerId(sellerId.id);
|
||||
if (!sellerId.id) {
|
||||
throw new Error("Failed to create participant");
|
||||
throw new Error('Failed to create participant');
|
||||
}
|
||||
const chain = user.network.value;
|
||||
const hash = await walletClient.writeContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: "deposit",
|
||||
functionName: 'deposit',
|
||||
args: [
|
||||
user.network.value.id + "-" + sellerId.id,
|
||||
toHex("", { size: 32 }),
|
||||
user.network.value.id + '-' + sellerId.id,
|
||||
toHex('', { size: 32 }),
|
||||
user.network.value.tokens[user.selectedToken.value].address,
|
||||
parseEther(user.seller.value.offer.toString()),
|
||||
true,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { formatEther, type Address } from "viem";
|
||||
import { useUser } from "@/composables/useUser";
|
||||
import { formatEther, type Address } from 'viem';
|
||||
import { useUser } from '@/composables/useUser';
|
||||
|
||||
import { getPublicClient, getWalletClient, getContract } from "./provider";
|
||||
import { getPublicClient, getWalletClient, getContract } from './provider';
|
||||
|
||||
import { getValidDeposits, getUnreleasedLockById } from "./events";
|
||||
import { getValidDeposits, getUnreleasedLockById } from './events';
|
||||
|
||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||
import type { WalletTransaction } from "@/model/WalletTransaction";
|
||||
import type { UnreleasedLock } from "@/model/UnreleasedLock";
|
||||
import { LockStatus } from "@/model/LockStatus";
|
||||
import type { ValidDeposit } from '@/model/ValidDeposit';
|
||||
import type { WalletTransaction } from '@/model/WalletTransaction';
|
||||
import type { UnreleasedLock } from '@/model/UnreleasedLock';
|
||||
import { LockStatus } from '@/model/LockStatus';
|
||||
|
||||
export const updateWalletStatus = async (): Promise<void> => {
|
||||
const user = useUser();
|
||||
@@ -17,7 +17,7 @@ export const updateWalletStatus = async (): Promise<void> => {
|
||||
const walletClient = getWalletClient();
|
||||
|
||||
if (!publicClient || !walletClient) {
|
||||
console.error("Client not initialized");
|
||||
console.error('Client not initialized');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ const getLockStatus = async (id: bigint): Promise<LockStatus> => {
|
||||
const [sortedIDs, status] = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: "getLocksStatus",
|
||||
functionName: 'getLocksStatus',
|
||||
args: [[id]],
|
||||
});
|
||||
return status[0];
|
||||
@@ -109,9 +109,9 @@ export const listAllTransactionByWalletAddress = async (
|
||||
};
|
||||
|
||||
const response = await fetch(network.subgraphUrls[0], {
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(subgraphQuery),
|
||||
});
|
||||
@@ -129,8 +129,8 @@ export const listAllTransactionByWalletAddress = async (
|
||||
blockTimestamp: parseInt(deposit.blockTimestamp),
|
||||
amount: parseFloat(formatEther(BigInt(deposit.amount))),
|
||||
seller: deposit.seller,
|
||||
buyer: "",
|
||||
event: "DepositAdded",
|
||||
buyer: '',
|
||||
event: 'DepositAdded',
|
||||
lockStatus: undefined,
|
||||
transactionHash: deposit.transactionHash,
|
||||
});
|
||||
@@ -150,7 +150,7 @@ export const listAllTransactionByWalletAddress = async (
|
||||
amount: parseFloat(formatEther(BigInt(lock.amount))),
|
||||
seller: lock.seller,
|
||||
buyer: lock.buyer,
|
||||
event: "LockAdded",
|
||||
event: 'LockAdded',
|
||||
lockStatus: lockStatus,
|
||||
transactionHash: lock.transactionHash,
|
||||
transactionID: lock.lockID.toString(),
|
||||
@@ -166,9 +166,9 @@ export const listAllTransactionByWalletAddress = async (
|
||||
blockNumber: parseInt(release.blockNumber),
|
||||
blockTimestamp: parseInt(release.blockTimestamp),
|
||||
amount: -1, // Amount not available in this event
|
||||
seller: "",
|
||||
seller: '',
|
||||
buyer: release.buyer,
|
||||
event: "LockReleased",
|
||||
event: 'LockReleased',
|
||||
lockStatus: undefined,
|
||||
transactionHash: release.transactionHash,
|
||||
transactionID: release.lockId.toString(),
|
||||
@@ -185,8 +185,8 @@ export const listAllTransactionByWalletAddress = async (
|
||||
blockTimestamp: parseInt(withdrawal.blockTimestamp),
|
||||
amount: parseFloat(formatEther(BigInt(withdrawal.amount))),
|
||||
seller: withdrawal.seller,
|
||||
buyer: "",
|
||||
event: "DepositWithdrawn",
|
||||
buyer: '',
|
||||
event: 'DepositWithdrawn',
|
||||
lockStatus: undefined,
|
||||
transactionHash: withdrawal.transactionHash,
|
||||
});
|
||||
@@ -222,9 +222,9 @@ export const listReleaseTransactionByWalletAddress = async (
|
||||
|
||||
// Fetch data from subgraph
|
||||
const response = await fetch(network.subgraphUrls[0], {
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(subgraphQuery),
|
||||
});
|
||||
@@ -245,7 +245,7 @@ export const listReleaseTransactionByWalletAddress = async (
|
||||
try {
|
||||
// Create a structure similar to the decoded event log
|
||||
return {
|
||||
eventName: "LockReleased",
|
||||
eventName: 'LockReleased',
|
||||
args: {
|
||||
buyer: release.buyer,
|
||||
lockID: BigInt(release.lockId),
|
||||
@@ -256,7 +256,7 @@ export const listReleaseTransactionByWalletAddress = async (
|
||||
transactionHash: release.transactionHash,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error processing subgraph data", error);
|
||||
console.error('Error processing subgraph data', error);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
@@ -287,9 +287,9 @@ const listLockTransactionByWalletAddress = async (walletAddress: Address) => {
|
||||
try {
|
||||
// Fetch data from subgraph
|
||||
const response = await fetch(network.subgraphUrls[0], {
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(subgraphQuery),
|
||||
});
|
||||
@@ -309,7 +309,7 @@ const listLockTransactionByWalletAddress = async (walletAddress: Address) => {
|
||||
try {
|
||||
// Create a structure similar to the decoded event log
|
||||
return {
|
||||
eventName: "LockAdded",
|
||||
eventName: 'LockAdded',
|
||||
args: {
|
||||
buyer: lock.buyer,
|
||||
lockID: BigInt(lock.lockID),
|
||||
@@ -322,13 +322,13 @@ const listLockTransactionByWalletAddress = async (walletAddress: Address) => {
|
||||
transactionHash: lock.transactionHash,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error processing subgraph data", error);
|
||||
console.error('Error processing subgraph data', error);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter((decoded: any) => decoded !== null);
|
||||
} catch (error) {
|
||||
console.error("Error fetching from subgraph:", error);
|
||||
console.error('Error fetching from subgraph:', error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -356,9 +356,9 @@ const listLockTransactionBySellerAddress = async (sellerAddress: Address) => {
|
||||
try {
|
||||
// Fetch data from subgraph
|
||||
const response = await fetch(network.subgraphUrls[0], {
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(subgraphQuery),
|
||||
});
|
||||
@@ -378,7 +378,7 @@ const listLockTransactionBySellerAddress = async (sellerAddress: Address) => {
|
||||
try {
|
||||
// Create a structure similar to the decoded event log
|
||||
return {
|
||||
eventName: "LockAdded",
|
||||
eventName: 'LockAdded',
|
||||
args: {
|
||||
buyer: lock.buyer,
|
||||
lockID: BigInt(lock.lockID),
|
||||
@@ -391,13 +391,13 @@ const listLockTransactionBySellerAddress = async (sellerAddress: Address) => {
|
||||
transactionHash: lock.transactionHash,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error processing subgraph data", error);
|
||||
console.error('Error processing subgraph data', error);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter((decoded: any) => decoded !== null);
|
||||
} catch (error) {
|
||||
console.error("Error fetching from subgraph:", error);
|
||||
console.error('Error fetching from subgraph:', error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
@@ -415,7 +415,7 @@ export const checkUnreleasedLock = async (
|
||||
const [sortedIDs, status] = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: "getLocksStatus",
|
||||
functionName: 'getLocksStatus',
|
||||
args: [lockIds],
|
||||
});
|
||||
|
||||
@@ -440,7 +440,7 @@ export const getActiveLockAmount = async (
|
||||
const [sortedIDs, status] = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: "getLocksStatus",
|
||||
functionName: 'getLocksStatus',
|
||||
args: [lockIds],
|
||||
});
|
||||
|
||||
@@ -448,7 +448,7 @@ export const getActiveLockAmount = async (
|
||||
client.readContract({
|
||||
address: address,
|
||||
abi,
|
||||
functionName: "mapLocks",
|
||||
functionName: 'mapLocks',
|
||||
args: [BigInt(id)],
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user