Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: better chain selection for single chain #4824

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yellow-icons-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': minor
---

Update single chain selection to be searchable instead of a simple select
1 change: 1 addition & 0 deletions typescript/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@inquirer/core": "9.0.10",
"@inquirer/figures": "1.0.5",
"@inquirer/prompts": "^3.0.0",
"@inquirer/search": "^3.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not for this PR but could you create a separate issue to investigate and bump up the inquirer packages across the board to more recent versions?

i ask because prompts/figures don't look upto date, and v3 of search seems to be wanting v10+ of core (we only specify v9 here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do sir! thanks for pointing it out

"ansi-escapes": "^7.0.0",
"asn1.js": "^5.4.1",
"bignumber.js": "^9.1.1",
Expand Down
2 changes: 1 addition & 1 deletion typescript/cli/src/config/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ async function getOwnerAndBeneficiary(
async function selectIgpChains(context: CommandContext) {
const localChain = await runSingleChainSelectionStep(
context.chainMetadata,
'Select local chain for IGP hook',
'Select local chain for IGP hook:',
);
const isTestnet = context.chainMetadata[localChain].isTestnet;
const remoteChains = await runMultiChainSelectionStep({
Expand Down
2 changes: 1 addition & 1 deletion typescript/cli/src/deploy/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function runKurtosisAgentDeploy({
if (!originChain) {
originChain = await runSingleChainSelectionStep(
context.chainMetadata,
'Select the origin chain',
'Select the origin chain:',
);
}
if (!relayChains) {
Expand Down
4 changes: 2 additions & 2 deletions typescript/cli/src/send/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export async function sendTestMessage({
if (!origin) {
origin = await runSingleChainSelectionStep(
chainMetadata,
'Select the origin chain',
'Select the origin chain:',
);
}

if (!destination) {
destination = await runSingleChainSelectionStep(
chainMetadata,
'Select the destination chain',
'Select the destination chain:',
);
}

Expand Down
4 changes: 2 additions & 2 deletions typescript/cli/src/send/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export async function sendTestTransfer({
if (!origin) {
origin = await runSingleChainSelectionStep(
chainMetadata,
'Select the origin chain',
'Select the origin chain:',
);
}

if (!destination) {
destination = await runSingleChainSelectionStep(
chainMetadata,
'Select the destination chain',
'Select the destination chain:',
);
}

Expand Down
2 changes: 1 addition & 1 deletion typescript/cli/src/status/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function checkMessageStatus({
if (!origin) {
origin = await runSingleChainSelectionStep(
context.chainMetadata,
'Select the origin chain',
'Select the origin chain:',
);
}

Expand Down
20 changes: 17 additions & 3 deletions typescript/cli/src/utils/chains.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Separator, confirm } from '@inquirer/prompts';
import search from '@inquirer/search';
import select from '@inquirer/select';
import chalk from 'chalk';

Expand All @@ -23,9 +24,20 @@ export async function runSingleChainSelectionStep(
chainMetadata,
networkType,
);
const chain = (await select({

const options = [networkTypeSeparator, ...choices];
const chain = (await search({
message,
choices: [networkTypeSeparator, ...choices],
source: (searchTerm) => {
if (!searchTerm) {
return options;
}

return options.filter(
(value) =>
Separator.isSeparator(value) || value.value.includes(searchTerm),
);
},
pageSize: calculatePageSize(2),
})) as string;
handleNewChain([chain]);
Expand Down Expand Up @@ -142,7 +154,9 @@ function getChainChoices(
networkType: 'mainnet' | 'testnet',
) {
const chainsToChoices = (chains: ChainMetadata[]) =>
chains.map((c) => ({ name: c.name, value: c.name }));
chains
.map((c) => ({ name: c.name, value: c.name }))
.sort((a, b) => a.name.localeCompare(b.name));

const chains = Object.values(chainMetadata);
const filteredChains = chains.filter((c) =>
Expand Down
55 changes: 55 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7829,6 +7829,7 @@ __metadata:
"@inquirer/core": "npm:9.0.10"
"@inquirer/figures": "npm:1.0.5"
"@inquirer/prompts": "npm:^3.0.0"
"@inquirer/search": "npm:^3.0.1"
"@types/chai-as-promised": "npm:^8"
"@types/mocha": "npm:^10.0.1"
"@types/node": "npm:^18.14.5"
Expand Down Expand Up @@ -8232,6 +8233,23 @@ __metadata:
languageName: node
linkType: hard

"@inquirer/core@npm:^10.0.1":
version: 10.0.1
resolution: "@inquirer/core@npm:10.0.1"
dependencies:
"@inquirer/figures": "npm:^1.0.7"
"@inquirer/type": "npm:^3.0.0"
ansi-escapes: "npm:^4.3.2"
cli-width: "npm:^4.1.0"
mute-stream: "npm:^2.0.0"
signal-exit: "npm:^4.1.0"
strip-ansi: "npm:^6.0.1"
wrap-ansi: "npm:^6.2.0"
yoctocolors-cjs: "npm:^2.1.2"
checksum: 368f78110e3b9f1370a45047a24b5cc4ef41fe2b7f2d82080de15d9bfb7ee3ff90494e0c138d1cca1b480c2cfb21914da8e9706b09620ea2e314860f98938393
languageName: node
linkType: hard

"@inquirer/core@npm:^3.0.0":
version: 3.0.0
resolution: "@inquirer/core@npm:3.0.0"
Expand Down Expand Up @@ -8307,6 +8325,13 @@ __metadata:
languageName: node
linkType: hard

"@inquirer/figures@npm:^1.0.7":
version: 1.0.7
resolution: "@inquirer/figures@npm:1.0.7"
checksum: ce896860de9d822a7c2a212667bcfd0f04cf2ce86d9a2411cc9c077bb59cd61732cb5f72ac66e88d52912466eec433f005bf8a25efa658f41e1a32f3977080bd
languageName: node
linkType: hard

"@inquirer/input@npm:^1.2.5":
version: 1.2.5
resolution: "@inquirer/input@npm:1.2.5"
Expand Down Expand Up @@ -8429,6 +8454,20 @@ __metadata:
languageName: node
linkType: hard

"@inquirer/search@npm:^3.0.1":
version: 3.0.1
resolution: "@inquirer/search@npm:3.0.1"
dependencies:
"@inquirer/core": "npm:^10.0.1"
"@inquirer/figures": "npm:^1.0.7"
"@inquirer/type": "npm:^3.0.0"
yoctocolors-cjs: "npm:^2.1.2"
peerDependencies:
"@types/node": ">=18"
checksum: bdea5b2659ccd91b9c91ee355d32d92061127b5f871837c91e709e8b8dfbd531b3dac312d4d0fe7454594ff6d9fbda4194edce6e52ba6bb4b91a65850e0948bb
languageName: node
linkType: hard

"@inquirer/select@npm:^1.2.5":
version: 1.2.5
resolution: "@inquirer/select@npm:1.2.5"
Expand Down Expand Up @@ -8471,6 +8510,15 @@ __metadata:
languageName: node
linkType: hard

"@inquirer/type@npm:^3.0.0":
version: 3.0.0
resolution: "@inquirer/type@npm:3.0.0"
peerDependencies:
"@types/node": ">=18"
checksum: fd4c265f0ed03e8da7ae2972c4e6b81932f535d9dd1e039e9e52b027cb8b72ae3c3309a3383ba513a8d3ae626de7dd3634387775cbdcbd100155ecbcaa65a657
languageName: node
linkType: hard

"@isaacs/cliui@npm:^8.0.2":
version: 8.0.2
resolution: "@isaacs/cliui@npm:8.0.2"
Expand Down Expand Up @@ -25003,6 +25051,13 @@ __metadata:
languageName: node
linkType: hard

"mute-stream@npm:^2.0.0":
version: 2.0.0
resolution: "mute-stream@npm:2.0.0"
checksum: d2e4fd2f5aa342b89b98134a8d899d8ef9b0a6d69274c4af9df46faa2d97aeb1f2ce83d867880d6de63643c52386579b99139801e24e7526c3b9b0a6d1e18d6c
languageName: node
linkType: hard

"mz@npm:^2.7.0":
version: 2.7.0
resolution: "mz@npm:2.7.0"
Expand Down