Skip to content

Commit

Permalink
Require 2 chains from multi-select
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy committed Nov 22, 2023
1 parent b5840a6 commit 22a00e9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions typescript/cli/src/utils/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
testnetChainsMetadata,
} from '@hyperlane-xyz/sdk';

import { log, logBlue, logTip } from '../../logger.js';
import { log, logBlue, logRed, logTip } from '../../logger.js';

// A special value marker to indicate user selected
// a new chain in the list
Expand All @@ -33,16 +33,18 @@ export async function runMultiChainSelectionStep(
customChains: ChainMap<ChainMetadata>,
message = 'Select chains',
) {
logTip('Use SPACE key to select chains, then press ENTER');
const choices = getChainChoices(customChains);
const chains = (await checkbox({
message,
choices,
pageSize: 20,
})) as string[];
handleNewChain(chains);
if (!chains?.length) throw new Error('No chains selected');
return chains;
while (true) {
logTip('Use SPACE key to select chains, then press ENTER');
const chains = (await checkbox({
message,
choices,
pageSize: 20,
})) as string[];
handleNewChain(chains);
if (chains?.length >= 2) return chains;
else logRed('Please select at least 2 chains');
}
}

function getChainChoices(customChains: ChainMap<ChainMetadata>) {
Expand Down

0 comments on commit 22a00e9

Please sign in to comment.