From 8761fe6102d215933b0e585f68dd753daeb83e68 Mon Sep 17 00:00:00 2001 From: kumaryash90 Date: Fri, 13 Dec 2024 09:16:09 +0000 Subject: [PATCH] Process deploy param ref only when non-empty (#5730) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PROT-935 --- ## PR-Codex overview This PR focuses on enhancing the handling of `implementationConstructorParams` and `initializeParams` by adding null checks to ensure that they are defined before processing. This improves the robustness of the code. ### Detailed summary - Changed `processedImplParams` and `processedInitializeParams` from constants to `undefined` initially. - Added checks to confirm that `implementationConstructorParams` and `initializeParams` are defined before processing. - Retained the logic for processing parameters using `processRefDeployments`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../extensions/prebuilts/deploy-published.ts | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts b/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts index fbdb48aefbd..ce0e0f662ff 100644 --- a/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts +++ b/packages/thirdweb/src/extensions/prebuilts/deploy-published.ts @@ -150,28 +150,35 @@ export async function deployContractfromDeployMetadata( salt, } = options; - const processedImplParams: Record = {}; - for (const key in implementationConstructorParams) { - processedImplParams[key] = await processRefDeployments({ - client, - account, - chain, - paramValue: implementationConstructorParams[key] as - | string - | ImplementationConstructorParam, - }); + let processedImplParams: Record | undefined; + let processedInitializeParams: Record | undefined; + + if (implementationConstructorParams) { + processedImplParams = {}; + for (const key in implementationConstructorParams) { + processedImplParams[key] = await processRefDeployments({ + client, + account, + chain, + paramValue: implementationConstructorParams[key] as + | string + | ImplementationConstructorParam, + }); + } } - const processedInitializeParams: Record = {}; - for (const key in initializeParams) { - processedInitializeParams[key] = await processRefDeployments({ - client, - account, - chain, - paramValue: initializeParams[key] as - | string - | ImplementationConstructorParam, - }); + if (initializeParams) { + processedInitializeParams = {}; + for (const key in initializeParams) { + processedInitializeParams[key] = await processRefDeployments({ + client, + account, + chain, + paramValue: initializeParams[key] as + | string + | ImplementationConstructorParam, + }); + } } switch (deployMetadata?.deployType) {