From b70335d168a760154b4908a87d28e70069d9c458 Mon Sep 17 00:00:00 2001 From: ljankovic-txfusion Date: Mon, 10 Feb 2025 14:12:03 +0100 Subject: [PATCH] refactor: reorder warp route config retrieval and symbol matching logic --- typescript/cli/src/read/warp.ts | 10 ++++----- typescript/cli/src/utils/warp.ts | 38 +++++++++++++++++--------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/typescript/cli/src/read/warp.ts b/typescript/cli/src/read/warp.ts index 46314cf681..ea50e94aff 100644 --- a/typescript/cli/src/read/warp.ts +++ b/typescript/cli/src/read/warp.ts @@ -36,11 +36,7 @@ export async function runWarpRouteRead({ let addresses: ChainMap; let warpCoreConfig = context.warpCoreConfig; - if (warpCoreConfig) { - addresses = Object.fromEntries( - warpCoreConfig.tokens.map((t) => [t.chainName, t.addressOrDenom!]), - ); - } else if (symbol || warp) { + if (symbol || warp) { warpCoreConfig = await getWarpCoreConfigOrExit({ context, warp, @@ -51,6 +47,10 @@ export async function runWarpRouteRead({ ); } else if (chain && address) { addresses = { [chain]: address }; + } else if (warpCoreConfig) { + addresses = Object.fromEntries( + warpCoreConfig.tokens.map((t) => [t.chainName, t.addressOrDenom!]), + ); } else { logRed(`Please specify either a symbol, chain and address or warp file`); process.exit(1); diff --git a/typescript/cli/src/utils/warp.ts b/typescript/cli/src/utils/warp.ts index 59d1a3598e..cb64d4e124 100644 --- a/typescript/cli/src/utils/warp.ts +++ b/typescript/cli/src/utils/warp.ts @@ -66,11 +66,23 @@ export async function getWarpConfigs({ warpDeployConfig: WarpRouteDeployConfig; warpCoreConfig: WarpCoreConfig; }> { - if (warpRouteId) { - const configs = await getWarpConfigFromRegistry(warpRouteId, context); + if (symbol) { + const warpCoreConfig = await selectRegistryWarpRoute( + context.registry, + symbol, + ); + + const routeIds = await getWarpRouteIds(context); + const matchingId = routeIds.find((id) => + id.toUpperCase().includes(symbol.toUpperCase()), + ); + if (!matchingId) { + throw new Error(`No matching warp route ID found for symbol ${symbol}`); + } + const configs = await getWarpConfigFromRegistry(matchingId, context); return { warpDeployConfig: configs.deployConfig as WarpRouteDeployConfig, - warpCoreConfig: configs.coreConfig, + warpCoreConfig, }; } @@ -85,26 +97,16 @@ export async function getWarpConfigs({ return { warpDeployConfig, warpCoreConfig }; } - if (symbol) { - const warpCoreConfig = await selectRegistryWarpRoute( - context.registry, - symbol, - ); - - const routeIds = await getWarpRouteIds(context); - const matchingId = routeIds.find((id) => - id.toUpperCase().includes(symbol.toUpperCase()), - ); - if (!matchingId) { - throw new Error(`No matching warp route ID found for symbol ${symbol}`); - } - const configs = await getWarpConfigFromRegistry(matchingId, context); + if (warpRouteId) { + const configs = await getWarpConfigFromRegistry(warpRouteId, context); return { warpDeployConfig: configs.deployConfig as WarpRouteDeployConfig, - warpCoreConfig, + warpCoreConfig: configs.coreConfig, }; } + // No inputs provided, prompt user to select from all routes + const routeIds = await getWarpRouteIds(context); if (routeIds.length === 0) { throw new Error('No valid warp routes found in registry');