import React from "react"; import { PublicKey, SystemProgram } from "@solana/web3.js"; import { Address } from "components/common/Address"; import { Account, useAccountInfo, useAddressLookupTable, useFetchAccountInfo, } from "providers/accounts"; import { ClusterStatus, useCluster } from "providers/cluster"; import { addressLabel } from "utils/tx"; import { lamportsToSolString } from "utils"; type AccountValidator = (account: Account) => string | undefined; export const createFeePayerValidator = ( feeLamports: number ): AccountValidator => { return (account: Account): string | undefined => { if (account.lamports === 0) return "Account doesn't exist"; if (!account.owner.equals(SystemProgram.programId)) return "Only system-owned accounts can pay fees"; // TODO: Actually nonce accounts can pay fees too if (account.space > 0) return "Only unallocated accounts can pay fees"; if (account.lamports < feeLamports) { return "Insufficient funds for fees"; } return; }; }; export const programValidator = (account: Account): string | undefined => { if (account.lamports === 0) return "Account doesn't exist"; if (!account.executable) return "Only executable accounts can be invoked"; return; }; export function AddressFromLookupTableWithContext({ lookupTableKey, lookupTableIndex, }: { lookupTableKey: PublicKey; lookupTableIndex: number; }) { const lookupTable = useAddressLookupTable(lookupTableKey.toBase58()); const fetchAccountInfo = useFetchAccountInfo(); React.useEffect(() => { if (!lookupTable) fetchAccountInfo(lookupTableKey); }, [lookupTableKey, lookupTable, fetchAccountInfo]); let pubkey; if (!lookupTable) { return ( Loading ); } else if (typeof lookupTable === "string") { return