Skip to content

Commit

Permalink
[SDK] Fix: Remove and Prevent console.log (#5527)
Browse files Browse the repository at this point in the history
CNCT-2483

<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on removing `console.log` statements from various files to clean up the code and improve maintainability. It also modifies the linter configuration to adjust rules related to console usage.

### Detailed summary
- Removed `console.log` statements from multiple test and implementation files.
- Adjusted linter configuration to allow specific console warnings only.
- Updated `biome.json` to include new linter rules for console usage.
- Cleaned up unused imports related to `DEBUG` constants.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
gregfromstl committed Nov 26, 2024
1 parent cedd9c8 commit d3139b2
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 55 deletions.
34 changes: 27 additions & 7 deletions packages/thirdweb/biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,39 @@
"rules": {
"nursery": {
"noProcessEnv": "warn"
},
"suspicious": {
"noConsole": {
"level": "error",
"options": {
"allow": ["error", "warn"]
}
}
}
}
},
"overrides": [{
"include": ["src/**/*.test.ts","src/**/*.test.tsx", "src/stories/**"],
"linter": {
"rules": {
"nursery": {
"noProcessEnv": "off"
"overrides": [
{
"include": ["src/**/*.test.ts", "src/**/*.test.tsx", "src/stories/**"],
"linter": {
"rules": {
"nursery": {
"noProcessEnv": "off"
}
}
}
},
{
"include": ["src/cli/bin.ts", "src/cli/commands/**"],
"linter": {
"rules": {
"suspicious": {
"noConsole": "off"
}
}
}
}
}],
],
"files": {
"ignore": [
"src/crypto/aes/lib/md5.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ export async function zkDeployContractDeterministic(
});
}

console.log(
`deploying contract via create2 factory at: ${predictedAddress}`,
);

// deploy with create2 factory
const factory = getContract({
address: create2FactoryAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,9 @@ type BuyScreenContentProps = {
*/
function BuyScreenContent(props: BuyScreenContentProps) {
const { client, supportedDestinations, connectLocale, payOptions } = props;
console.log("BuyScreenContent");

const activeAccount = useActiveAccount();
const { payer, setPayer } = usePayerSetup();
console.log("payer", payer);

const [screen, setScreen] = useState<SelectedScreen>({
id: "main",
Expand Down Expand Up @@ -498,8 +496,6 @@ function BuyScreenContent(props: BuyScreenContentProps) {
);
}

console.log("SCREEN", screen.id);

return (
<Container animate="fadein">
<div>
Expand Down
12 changes: 0 additions & 12 deletions packages/thirdweb/src/storage/upload/mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ export async function uploadBatchMobile(
);
}, 30000);

xhr.upload.addEventListener("loadstart", () => {
console.log(`[${Date.now()}] [IPFS] Started`);
});

xhr.upload.addEventListener("progress", (event) => {
console.log(`[IPFS] Progress Event ${event.loaded}/${event.total}`);

clearTimeout(timer);

if (event.loaded < event.total) {
Expand All @@ -61,15 +55,10 @@ export async function uploadBatchMobile(
),
);
}, 30000);
} else {
console.log(
`[${Date.now()}] [IPFS] Uploaded files. Waiting for response.`,
);
}
});

xhr.addEventListener("load", () => {
console.log(`[${Date.now()}] [IPFS] Load`);
clearTimeout(timer);

if (xhr.status >= 200 && xhr.status < 300) {
Expand Down Expand Up @@ -102,7 +91,6 @@ export async function uploadBatchMobile(
});

xhr.addEventListener("error", () => {
console.log("[IPFS] Load");
clearTimeout(timer);

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe("sendEip712Transaction", () => {
platformFeeRecipient: TEST_ACCOUNT_A.address, // platformFeeRecipient
},
});
console.log("deployed address", address);
expect(address).toBeDefined();
expect(address.length).toBe(42);
});
Expand Down
9 changes: 0 additions & 9 deletions packages/thirdweb/src/wallets/smart/lib/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
formatUserOperationReceipt,
} from "../types.js";
import {
DEBUG,
ENTRYPOINT_ADDRESS_v0_6,
MANAGED_ACCOUNT_GAS_BUFFER,
getDefaultBundlerUrl,
Expand Down Expand Up @@ -267,10 +266,6 @@ async function sendBundlerRequest(args: {
}) {
const { options, operation, params } = args;

if (DEBUG) {
console.debug(`>>> sending ${operation} with payload:`, params);
}

const bundlerUrl = options.bundlerUrl ?? getDefaultBundlerUrl(options.chain);
const fetchWithHeaders = getClientFetch(options.client);
const response = await fetchWithHeaders(bundlerUrl, {
Expand Down Expand Up @@ -301,9 +296,5 @@ Code: ${code}`,
);
}

if (DEBUG) {
console.debug(`<<< ${operation} result:`, res);
}

return res.result;
}
3 changes: 0 additions & 3 deletions packages/thirdweb/src/wallets/smart/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import type { Chain } from "../../../chains/types.js";
import { getAddress } from "../../../utils/address.js";
import { getThirdwebDomains } from "../../../utils/domains.js";

// dev only
export const DEBUG = false;

export const DUMMY_SIGNATURE =
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";

Expand Down
10 changes: 1 addition & 9 deletions packages/thirdweb/src/wallets/smart/lib/paymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import type {
UserOperationV06,
UserOperationV07,
} from "../types.js";
import {
DEBUG,
ENTRYPOINT_ADDRESS_v0_6,
getDefaultBundlerUrl,
} from "./constants.js";
import { ENTRYPOINT_ADDRESS_v0_6, getDefaultBundlerUrl } from "./constants.js";
import { hexlifyUserOp } from "./utils.js";

/**
Expand Down Expand Up @@ -80,10 +76,6 @@ Code: ${code}`,
);
}

if (DEBUG) {
console.debug("Paymaster result:", res);
}

if (res.result) {
// some paymasters return a string, some return an object with more data
if (typeof res.result === "string") {
Expand Down
4 changes: 0 additions & 4 deletions packages/thirdweb/src/wallets/smart/smart-wallet-dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,10 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
to: smartAccount.address,
value: 0n,
});

console.log("Sending transaction...");
const receipt = await sendTransaction({
transaction: tx,
account: smartAccount,
});
console.log("Transaction sent:", receipt.transactionHash);
expect(receipt.transactionHash).toBeDefined();
});

Expand Down Expand Up @@ -127,7 +124,6 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
platformFeeRecipient: smartAccount.address, // platformFeeRecipient
},
});
console.log("deployed address", address);
expect(address).toBeDefined();
expect(address.length).toBe(42);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ describe.runIf(process.env.TW_SECRET_KEY).todo(
}),
account: account,
});
console.log(tx.transactionHash);
expect(tx.transactionHash.length).toBe(66);
});

Expand All @@ -168,7 +167,6 @@ describe.runIf(process.env.TW_SECRET_KEY).todo(
}),
account: account,
});
console.log(tx.transactionHash);
expect(tx.transactionHash.length).toBe(66);
});
},
Expand Down

0 comments on commit d3139b2

Please sign in to comment.