diff --git a/eslint.config.js b/eslint.config.js index 340d125..5c7595b 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -11,6 +11,7 @@ export default [ { argsIgnorePattern: "^_" }, ], "@typescript-eslint/no-explicit-any": "warn", + "no-console": ["error", { allow: ["warn", "error", "info"] }], }, }, { diff --git a/src/components/ContractDashboard.tsx b/src/components/ContractDashboard.tsx index 6ddc387..dfc0ec9 100644 --- a/src/components/ContractDashboard.tsx +++ b/src/components/ContractDashboard.tsx @@ -17,22 +17,22 @@ export const ContractDashboard = () => { const handleTransferAdmin = () => { // Calls the transfer_admin function added to the contract - console.log("Initiating admin transfer transaction..."); + logger.debug("Initiating admin transfer transaction..."); }; const handlePause = () => { // Multi-sig pause escalation path - console.log("Initiating Level 1 emergency pause (2-of-3 required)..."); + logger.debug("Initiating Level 1 emergency pause (2-of-3 required)..."); }; const handleVerify = () => { // Invokes deterministic build and ABI signature checks via Stellar Expert - console.log("Verifying ABI signature and WASM hash on Stellar Expert..."); + logger.debug("Verifying ABI signature and WASM hash on Stellar Expert..."); }; const handleUpgrade = () => { // Automates proxy contract implementation swap - console.log("Simulating upgrade to next implementation..."); + logger.debug("Simulating upgrade to next implementation..."); }; return ( diff --git a/src/pages/BatchMultiCall.tsx b/src/pages/BatchMultiCall.tsx index 70e8417..10f4369 100644 --- a/src/pages/BatchMultiCall.tsx +++ b/src/pages/BatchMultiCall.tsx @@ -404,6 +404,12 @@ export default function BatchMultiCall() { > Export as JSON + + diff --git a/src/services/export.ts b/src/services/export.ts index 6bf9404..43c63ac 100644 --- a/src/services/export.ts +++ b/src/services/export.ts @@ -1,5 +1,6 @@ import JSZip from "jszip"; import { SandboxFile } from "./webcontainer"; +import { logger } from "../utils/logger"; export async function exportAsZip( files: Map, @@ -40,7 +41,7 @@ export function createShareableUrl(sandboxId: string): string { export function copySandboxUrl(sandboxId: string): void { const url = createShareableUrl(sandboxId); navigator.clipboard.writeText(url).then(() => { - console.log("Sandbox URL copied to clipboard:", url); + logger.debug("Sandbox URL copied to clipboard:", url); }); } diff --git a/src/services/webcontainer.ts b/src/services/webcontainer.ts index dfd93f0..6a69e1f 100644 --- a/src/services/webcontainer.ts +++ b/src/services/webcontainer.ts @@ -1,4 +1,5 @@ import { WebContainer } from "@webcontainer/api"; +import { logger } from "../utils/logger"; export interface SandboxFile { path: string; @@ -77,7 +78,7 @@ EXPLORER_CONTRACT_ID=CABCD1234567890ABCD1234567890ABCD1234567890ABCD1234567890AB export async function initWebContainer(): Promise { try { const container = await WebContainer.boot(); - console.log("WebContainer initialized"); + logger.debug("WebContainer initialized"); return container; } catch (error) { console.error("Failed to initialize WebContainer:", error); diff --git a/src/utils/logger.ts b/src/utils/logger.ts new file mode 100644 index 0000000..dfec3f4 --- /dev/null +++ b/src/utils/logger.ts @@ -0,0 +1,35 @@ +/** + * Lightweight logger that is silent in production builds. + * + * Usage: + * import { logger } from '@/utils/logger'; + * logger.debug('fetched', data); // only printed when import.meta.env.DEV === true + * logger.warn('something odd'); // always printed (maps to console.warn) + * logger.error('fatal', err); // always printed (maps to console.error) + */ + +const isDev = import.meta.env.DEV; + +/* eslint-disable no-console */ +export const logger = { + /** Debug-level messages — silenced in production. */ + debug: (...args: unknown[]): void => { + if (isDev) console.log(...args); + }, + + /** Informational messages — silenced in production. */ + info: (...args: unknown[]): void => { + if (isDev) console.info(...args); + }, + + /** Warnings — always visible. */ + warn: (...args: unknown[]): void => { + console.warn(...args); + }, + + /** Errors — always visible. */ + error: (...args: unknown[]): void => { + console.error(...args); + }, +}; +/* eslint-enable no-console */