Skip to content

Commit

Permalink
refactor: reorder warp route config retrieval and symbol matching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ljankovic-txfusion committed Feb 10, 2025
1 parent 7c7f2d6 commit b70335d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
10 changes: 5 additions & 5 deletions typescript/cli/src/read/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ export async function runWarpRouteRead({
let addresses: ChainMap<string>;
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,
Expand All @@ -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);
Expand Down
38 changes: 20 additions & 18 deletions typescript/cli/src/utils/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand All @@ -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');
Expand Down

0 comments on commit b70335d

Please sign in to comment.