Skip to content

Commit a905072

Browse files
authored
Move common UI components into UI (#5287)
This moves various UI components I've seen into the CLI's UI folder. It moves select prompts and other things from utils into the UI if they are related to a UI component.
1 parent cf812ef commit a905072

File tree

24 files changed

+227
-244
lines changed

24 files changed

+227
-244
lines changed

ironfish-cli/src/commands/wallet/burn.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { Flags, ux } from '@oclif/core'
1414
import { IronfishCommand } from '../../command'
1515
import { IronFlag, RemoteFlags, ValueFlag } from '../../flags'
1616
import * as ui from '../../ui'
17-
import { selectAsset } from '../../utils/asset'
1817
import { promptCurrency } from '../../utils/currency'
1918
import { promptExpiration } from '../../utils/expiration'
2019
import { getExplorer } from '../../utils/explorer'
@@ -126,7 +125,7 @@ This will destroy tokens and decrease supply for a given asset.`
126125
let assetId = flags.assetId
127126

128127
if (assetId == null) {
129-
const asset = await selectAsset(client, account, {
128+
const asset = await ui.assetPrompt(client, account, {
130129
action: 'burn',
131130
showNativeAsset: false,
132131
showNonCreatorAsset: true,

ironfish-cli/src/commands/wallet/chainport/send.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import { Flags, ux } from '@oclif/core'
1717
import inquirer from 'inquirer'
1818
import { IronfishCommand } from '../../../command'
1919
import { HexFlag, IronFlag, RemoteFlags, ValueFlag } from '../../../flags'
20-
import { confirmOrQuit, inputPrompt } from '../../../ui'
21-
import { selectAsset } from '../../../utils'
20+
import * as ui from '../../../ui'
2221
import {
2322
ChainportBridgeTransaction,
2423
ChainportNetwork,
@@ -118,7 +117,7 @@ export class BridgeCommand extends IronfishCommand {
118117
assetData,
119118
)
120119

121-
await confirmOrQuit()
120+
await ui.confirmOrQuit()
122121

123122
const postTransaction = await client.wallet.postTransaction({
124123
transaction: RawTransactionSerde.serialize(rawTransaction).toString('hex'),
@@ -177,7 +176,7 @@ export class BridgeCommand extends IronfishCommand {
177176
}
178177

179178
if (!to) {
180-
to = await inputPrompt('Enter the public address of the recipient', true)
179+
to = await ui.inputPrompt('Enter the public address of the recipient', true)
181180
}
182181

183182
if (!isEthereumAddress(to)) {
@@ -191,7 +190,7 @@ export class BridgeCommand extends IronfishCommand {
191190
const tokens = await fetchChainportVerifiedTokens(networkId)
192191

193192
if (assetId == null) {
194-
const asset = await selectAsset(client, from, {
193+
const asset = await ui.assetPrompt(client, from, {
195194
action: 'send',
196195
showNativeAsset: true,
197196
showNonCreatorAsset: true,

ironfish-cli/src/commands/wallet/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Args, Flags, ux } from '@oclif/core'
1111
import { IronfishCommand } from '../../command'
1212
import { RemoteFlags } from '../../flags'
1313
import { inputPrompt } from '../../ui'
14-
import { importFile, importPipe, longPrompt } from '../../utils/input'
14+
import { importFile, importPipe, longPrompt } from '../../ui/longPrompt'
1515
import { Ledger } from '../../utils/ledger'
1616

1717
export class ImportCommand extends IronfishCommand {

ironfish-cli/src/commands/wallet/mint.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { Flags, ux } from '@oclif/core'
1818
import { IronfishCommand } from '../../command'
1919
import { IronFlag, RemoteFlags, ValueFlag } from '../../flags'
2020
import * as ui from '../../ui'
21-
import { selectAsset } from '../../utils/asset'
2221
import { promptCurrency } from '../../utils/currency'
2322
import { promptExpiration } from '../../utils/expiration'
2423
import { getExplorer } from '../../utils/explorer'
@@ -170,7 +169,7 @@ This will create tokens and increase supply for a given asset.`
170169
const newAsset = new Asset(accountPublicKey, name, metadata)
171170
assetId = newAsset.id().toString('hex')
172171
} else if (!assetId) {
173-
const asset = await selectAsset(client, account, {
172+
const asset = await ui.assetPrompt(client, account, {
174173
action: 'mint',
175174
showNativeAsset: false,
176175
showNonCreatorAsset: false,

ironfish-cli/src/commands/wallet/multisig/commitment/aggregate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { Flags } from '@oclif/core'
66
import { IronfishCommand } from '../../../../command'
77
import { RemoteFlags } from '../../../../flags'
8-
import { longPrompt } from '../../../../utils/input'
8+
import * as ui from '../../../../ui'
99
import { MultisigTransactionJson } from '../../../../utils/multisig'
1010

1111
export class CreateSigningPackage extends IronfishCommand {
@@ -41,14 +41,14 @@ export class CreateSigningPackage extends IronfishCommand {
4141

4242
let unsignedTransaction = options.unsignedTransaction
4343
if (!unsignedTransaction) {
44-
unsignedTransaction = await longPrompt('Enter the unsigned transaction', {
44+
unsignedTransaction = await ui.longPrompt('Enter the unsigned transaction', {
4545
required: true,
4646
})
4747
}
4848

4949
let commitments = options.commitment
5050
if (!commitments) {
51-
const input = await longPrompt('Enter the signing commitments, separated by commas', {
51+
const input = await ui.longPrompt('Enter the signing commitments, separated by commas', {
5252
required: true,
5353
})
5454
commitments = input.split(',')

ironfish-cli/src/commands/wallet/multisig/commitment/create.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { UnsignedTransaction } from '@ironfish/sdk'
55
import { Flags } from '@oclif/core'
66
import { IronfishCommand } from '../../../../command'
77
import { RemoteFlags } from '../../../../flags'
8-
import { confirmOrQuit } from '../../../../ui'
9-
import { longPrompt } from '../../../../utils/input'
8+
import * as ui from '../../../../ui'
109
import { MultisigTransactionJson } from '../../../../utils/multisig'
1110
import { renderUnsignedTransactionDetails } from '../../../../utils/transaction'
1211

@@ -48,7 +47,7 @@ export class CreateSigningCommitmentCommand extends IronfishCommand {
4847

4948
let identities = options.identity
5049
if (!identities || identities.length < 2) {
51-
const input = await longPrompt(
50+
const input = await ui.longPrompt(
5251
'Enter the identities of all participants who will sign the transaction, separated by commas',
5352
{
5453
required: true,
@@ -64,7 +63,7 @@ export class CreateSigningCommitmentCommand extends IronfishCommand {
6463

6564
let unsignedTransactionInput = options.unsignedTransaction
6665
if (!unsignedTransactionInput) {
67-
unsignedTransactionInput = await longPrompt('Enter the unsigned transaction', {
66+
unsignedTransactionInput = await ui.longPrompt('Enter the unsigned transaction', {
6867
required: true,
6968
})
7069
}
@@ -81,7 +80,7 @@ export class CreateSigningCommitmentCommand extends IronfishCommand {
8180
this.logger,
8281
)
8382

84-
await confirmOrQuit('Confirm signing commitment creation', flags.confirm)
83+
await ui.confirmOrQuit('Confirm signing commitment creation', flags.confirm)
8584

8685
const response = await client.wallet.multisig.createSigningCommitment({
8786
account: flags.account,

ironfish-cli/src/commands/wallet/multisig/dealer/create.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { AccountImport } from '@ironfish/sdk/src/wallet/exporter'
66
import { Flags, ux } from '@oclif/core'
77
import { IronfishCommand } from '../../../../command'
88
import { RemoteFlags } from '../../../../flags'
9-
import { inputPrompt } from '../../../../ui'
10-
import { longPrompt } from '../../../../utils/input'
9+
import * as ui from '../../../../ui'
1110

1211
export class MultisigCreateDealer extends IronfishCommand {
1312
static description = `Create a set of multisig accounts from participant identities`
@@ -39,7 +38,7 @@ export class MultisigCreateDealer extends IronfishCommand {
3938

4039
let identities = flags.identity
4140
if (!identities || identities.length < 2) {
42-
const input = await longPrompt(
41+
const input = await ui.longPrompt(
4342
'Enter the identities of all participants, separated by commas',
4443
{
4544
required: true,
@@ -55,7 +54,7 @@ export class MultisigCreateDealer extends IronfishCommand {
5554

5655
let minSigners = flags.minSigners
5756
if (!minSigners) {
58-
const input = await inputPrompt('Enter the number of minimum signers', true)
57+
const input = await ui.inputPrompt('Enter the number of minimum signers', true)
5958
minSigners = parseInt(input)
6059
if (isNaN(minSigners) || minSigners < 2) {
6160
this.error('Minimum number of signers must be at least 2')
@@ -130,7 +129,7 @@ export class MultisigCreateDealer extends IronfishCommand {
130129

131130
let name = inputName
132131
do {
133-
name = name ?? (await inputPrompt('Enter a name for the coordinator', true))
132+
name = name ?? (await ui.inputPrompt('Enter a name for the coordinator', true))
134133

135134
if (accountNames.has(name)) {
136135
this.log(`Account with name ${name} already exists`)

ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import { Flags } from '@oclif/core'
55
import { IronfishCommand } from '../../../../command'
66
import { RemoteFlags } from '../../../../flags'
7-
import { inputPrompt } from '../../../../ui'
8-
import { longPrompt } from '../../../../utils/input'
9-
import { selectSecret } from '../../../../utils/multisig'
7+
import * as ui from '../../../../ui'
108

119
export class DkgRound1Command extends IronfishCommand {
1210
static description = 'Perform round1 of the DKG protocol for multisig account creation'
@@ -37,12 +35,12 @@ export class DkgRound1Command extends IronfishCommand {
3735

3836
let participantName = flags.participantName
3937
if (!participantName) {
40-
participantName = await selectSecret(client)
38+
participantName = await ui.multisigSecretPrompt(client)
4139
}
4240

4341
let identities = flags.identity
4442
if (!identities || identities.length < 2) {
45-
const input = await longPrompt(
43+
const input = await ui.longPrompt(
4644
'Enter the identities of all participants, separated by commas',
4745
{
4846
required: true,
@@ -58,7 +56,7 @@ export class DkgRound1Command extends IronfishCommand {
5856

5957
let minSigners = flags.minSigners
6058
if (!minSigners) {
61-
const input = await inputPrompt('Enter the number of minimum signers', true)
59+
const input = await ui.inputPrompt('Enter the number of minimum signers', true)
6260
minSigners = parseInt(input)
6361
if (isNaN(minSigners) || minSigners < 2) {
6462
this.error('Minimum number of signers must be at least 2')

ironfish-cli/src/commands/wallet/multisig/dkg/round2.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import { Flags } from '@oclif/core'
55
import { IronfishCommand } from '../../../../command'
66
import { RemoteFlags } from '../../../../flags'
7-
import { inputPrompt } from '../../../../ui'
8-
import { longPrompt } from '../../../../utils/input'
9-
import { selectSecret } from '../../../../utils/multisig'
7+
import * as ui from '../../../../ui'
108

119
export class DkgRound2Command extends IronfishCommand {
1210
static description = 'Perform round2 of the DKG protocol for multisig account creation'
@@ -37,20 +35,20 @@ export class DkgRound2Command extends IronfishCommand {
3735

3836
let participantName = flags.participantName
3937
if (!participantName) {
40-
participantName = await selectSecret(client)
38+
participantName = await ui.multisigSecretPrompt(client)
4139
}
4240

4341
let round1SecretPackage = flags.round1SecretPackage
4442
if (!round1SecretPackage) {
45-
round1SecretPackage = await inputPrompt(
43+
round1SecretPackage = await ui.inputPrompt(
4644
`Enter the round 1 secret package for participant ${participantName}`,
4745
true,
4846
)
4947
}
5048

5149
let round1PublicPackages = flags.round1PublicPackages
5250
if (!round1PublicPackages || round1PublicPackages.length < 2) {
53-
const input = await longPrompt(
51+
const input = await ui.longPrompt(
5452
'Enter round 1 public packages, separated by commas, one for each participant',
5553
{ required: true },
5654
)

ironfish-cli/src/commands/wallet/multisig/dkg/round3.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import { Flags } from '@oclif/core'
55
import { IronfishCommand } from '../../../../command'
66
import { RemoteFlags } from '../../../../flags'
7-
import { inputPrompt } from '../../../../ui'
8-
import { longPrompt } from '../../../../utils/input'
9-
import { selectSecret } from '../../../../utils/multisig'
7+
import * as ui from '../../../../ui'
108

119
export class DkgRound3Command extends IronfishCommand {
1210
static description = 'Perform round3 of the DKG protocol for multisig account creation'
@@ -47,20 +45,20 @@ export class DkgRound3Command extends IronfishCommand {
4745

4846
let participantName = flags.participantName
4947
if (!participantName) {
50-
participantName = await selectSecret(client)
48+
participantName = await ui.multisigSecretPrompt(client)
5149
}
5250

5351
let round2SecretPackage = flags.round2SecretPackage
5452
if (!round2SecretPackage) {
55-
round2SecretPackage = await inputPrompt(
53+
round2SecretPackage = await ui.inputPrompt(
5654
`Enter the round 2 encrypted secret package for participant ${participantName}`,
5755
true,
5856
)
5957
}
6058

6159
let round1PublicPackages = flags.round1PublicPackages
6260
if (!round1PublicPackages || round1PublicPackages.length < 2) {
63-
const input = await longPrompt(
61+
const input = await ui.longPrompt(
6462
'Enter round 1 public packages, separated by commas, one for each participant',
6563
{
6664
required: true,
@@ -78,7 +76,7 @@ export class DkgRound3Command extends IronfishCommand {
7876

7977
let round2PublicPackages = flags.round2PublicPackages
8078
if (!round2PublicPackages) {
81-
const input = await longPrompt(
79+
const input = await ui.longPrompt(
8280
'Enter round 2 public packages, separated by commas, one for each participant',
8381
{
8482
required: true,

0 commit comments

Comments
 (0)