Stronger typings💪

This commit is contained in:
hueso
2025-06-29 18:19:30 -03:00
parent 2370051243
commit dd351acb2e
24 changed files with 2424 additions and 12561 deletions

View File

@@ -1,4 +1,4 @@
import p2pix from "@/utils/smart_contract_files/P2PIX.json";
import { p2PixAbi } from "./abi";
import { updateWalletStatus } from "./wallet";
import { getProviderUrl, getP2PixAddress } from "./addresses";
import {
@@ -12,11 +12,9 @@ import {
import { sepolia, rootstock } from "viem/chains";
import { useUser } from "@/composables/useUser";
let publicClient: PublicClient | null = null;
let walletClient: WalletClient | null = null;
const getPublicClient = (onlyRpcProvider = false): PublicClient | null => {
if (onlyRpcProvider) {
const getPublicClient = (): PublicClient => {
const user = useUser();
const rpcUrl = getProviderUrl();
return createPublicClient({
@@ -24,8 +22,6 @@ const getPublicClient = (onlyRpcProvider = false): PublicClient | null => {
Number(user.networkName.value) === sepolia.id ? sepolia : rootstock,
transport: http(rpcUrl),
});
}
return publicClient;
};
const getWalletClient = (): WalletClient | null => {
@@ -33,16 +29,16 @@ const getWalletClient = (): WalletClient | null => {
};
const getContract = async (onlyRpcProvider = false) => {
const client = getPublicClient(onlyRpcProvider);
const client = getPublicClient();
const address = getP2PixAddress();
const abi = p2pix.abi;
const wallet = getWalletClient();
const abi = p2PixAbi;
const wallet = onlyRpcProvider ? null : getWalletClient();
if (!client) {
throw new Error("Public client not initialized");
}
const [account] = wallet ? await wallet.getAddresses() : [""];
const [account] = wallet ? await wallet.getAddresses() : [null];
return { address, abi, client, wallet, account };
};
@@ -52,11 +48,6 @@ const connectProvider = async (p: any): Promise<void> => {
const chain =
Number(user.networkName.value) === sepolia.id ? sepolia : rootstock;
publicClient = createPublicClient({
chain,
transport: custom(p),
});
const [account] = await p!.request({ method: "eth_requestAccounts" });
walletClient = createWalletClient({