From d49fc2628d647abec960ea684b667a08c6426810 Mon Sep 17 00:00:00 2001 From: spsjvc Date: Wed, 9 Oct 2024 18:23:03 +0200 Subject: [PATCH] refactor --- src/utils/getRollupCreatorAddress.ts | 15 +++++++-------- src/utils/getTokenBridgeCreatorAddress.ts | 15 +++++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/utils/getRollupCreatorAddress.ts b/src/utils/getRollupCreatorAddress.ts index 950ee64f..97edac91 100644 --- a/src/utils/getRollupCreatorAddress.ts +++ b/src/utils/getRollupCreatorAddress.ts @@ -9,17 +9,16 @@ export function getRollupCreatorAddress( const { chainId: parentChainId, isCustom: parentChainIsCustom } = validateParentChain(client); if (parentChainIsCustom) { - const customParentChainRollupCreator = client.chain?.contracts?.rollupCreator as - | ChainContract - | undefined; + const contract = client.chain?.contracts?.rollupCreator as ChainContract | undefined; + const address = contract?.address; - // check if it's a custom parent chain with the factory address provided - - if (!customParentChainRollupCreator?.address) { - throw new Error('invalid rollup creator address provided'); + if (typeof address === 'undefined') { + throw new Error( + `Address for RollupCreator is missing on custom parent chain with id ${parentChainId}`, + ); } - return customParentChainRollupCreator?.address; + return address; } return rollupCreatorAddress[parentChainId]; diff --git a/src/utils/getTokenBridgeCreatorAddress.ts b/src/utils/getTokenBridgeCreatorAddress.ts index 33e5409a..aa7c9485 100644 --- a/src/utils/getTokenBridgeCreatorAddress.ts +++ b/src/utils/getTokenBridgeCreatorAddress.ts @@ -9,17 +9,16 @@ export function getTokenBridgeCreatorAddress( const { chainId: parentChainId, isCustom: parentChainIsCustom } = validateParentChain(client); if (parentChainIsCustom) { - const customParentChainTokenBridgeCreator = client.chain?.contracts?.tokenBridgeCreator as - | ChainContract - | undefined; + const contract = client.chain?.contracts?.tokenBridgeCreator as ChainContract | undefined; + const address = contract?.address; - // check if it's a custom parent chain with the factory address provided - - if (!customParentChainTokenBridgeCreator?.address) { - throw new Error('invalid token bridge creator address provided'); + if (typeof address === 'undefined') { + throw new Error( + `Address for TokenBridgeCreator is missing on custom parent chain with id ${parentChainId}`, + ); } - return customParentChainTokenBridgeCreator?.address; + return address; } return tokenBridgeCreatorAddress[parentChainId];