cosmic-interchain-cli
Version:
A command-line utility for Cosmic Wire's interchain messaging protocol
40 lines • 1.27 kB
JavaScript
import select from '@inquirer/select';
import { logGreen, logRed } from '../logger.js';
export async function runTokenSelectionStep(tokens, message = 'Select token') {
const choices = tokens.map((t) => ({
name: `${t.symbol} - ${t.addressOrDenom}`,
value: t.addressOrDenom,
}));
const routerAddress = (await select({
message,
choices,
pageSize: 20,
}));
return routerAddress;
}
export async function selectRegistryWarpRoute(registry, symbol) {
const matching = await registry.getWarpRoutes({
symbol,
});
const routes = Object.entries(matching);
let warpCoreConfig;
if (routes.length === 0) {
logRed(`No warp routes found for symbol ${symbol}`);
process.exit(0);
}
else if (routes.length === 1) {
warpCoreConfig = routes[0][1];
}
else {
logGreen(`Multiple warp routes found for symbol ${symbol}`);
const chosenRouteId = await select({
message: 'Select from matching warp routes',
choices: routes.map(([routeId, _]) => ({
value: routeId,
})),
});
warpCoreConfig = matching[chosenRouteId];
}
return warpCoreConfig;
}
//# sourceMappingURL=tokens.js.map