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

Move common UI components into UI #5287

Merged
merged 1 commit into from
Aug 15, 2024
Merged
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
3 changes: 1 addition & 2 deletions ironfish-cli/src/commands/wallet/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { Flags, ux } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { IronFlag, RemoteFlags, ValueFlag } from '../../flags'
import * as ui from '../../ui'
import { selectAsset } from '../../utils/asset'
import { promptCurrency } from '../../utils/currency'
import { promptExpiration } from '../../utils/expiration'
import { getExplorer } from '../../utils/explorer'
Expand Down Expand Up @@ -126,7 +125,7 @@ This will destroy tokens and decrease supply for a given asset.`
let assetId = flags.assetId

if (assetId == null) {
const asset = await selectAsset(client, account, {
const asset = await ui.assetPrompt(client, account, {
action: 'burn',
showNativeAsset: false,
showNonCreatorAsset: true,
Expand Down
9 changes: 4 additions & 5 deletions ironfish-cli/src/commands/wallet/chainport/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { Flags, ux } from '@oclif/core'
import inquirer from 'inquirer'
import { IronfishCommand } from '../../../command'
import { HexFlag, IronFlag, RemoteFlags, ValueFlag } from '../../../flags'
import { confirmOrQuit, inputPrompt } from '../../../ui'
import { selectAsset } from '../../../utils'
import * as ui from '../../../ui'
import {
ChainportBridgeTransaction,
ChainportNetwork,
Expand Down Expand Up @@ -118,7 +117,7 @@ export class BridgeCommand extends IronfishCommand {
assetData,
)

await confirmOrQuit()
await ui.confirmOrQuit()

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

if (!to) {
to = await inputPrompt('Enter the public address of the recipient', true)
to = await ui.inputPrompt('Enter the public address of the recipient', true)
}

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

if (assetId == null) {
const asset = await selectAsset(client, from, {
const asset = await ui.assetPrompt(client, from, {
action: 'send',
showNativeAsset: true,
showNonCreatorAsset: true,
Expand Down
2 changes: 1 addition & 1 deletion ironfish-cli/src/commands/wallet/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Args, Flags, ux } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { RemoteFlags } from '../../flags'
import { inputPrompt } from '../../ui'
import { importFile, importPipe, longPrompt } from '../../utils/input'
import { importFile, importPipe, longPrompt } from '../../ui/longPrompt'
import { Ledger } from '../../utils/ledger'

export class ImportCommand extends IronfishCommand {
Expand Down
3 changes: 1 addition & 2 deletions ironfish-cli/src/commands/wallet/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { Flags, ux } from '@oclif/core'
import { IronfishCommand } from '../../command'
import { IronFlag, RemoteFlags, ValueFlag } from '../../flags'
import * as ui from '../../ui'
import { selectAsset } from '../../utils/asset'
import { promptCurrency } from '../../utils/currency'
import { promptExpiration } from '../../utils/expiration'
import { getExplorer } from '../../utils/explorer'
Expand Down Expand Up @@ -170,7 +169,7 @@ This will create tokens and increase supply for a given asset.`
const newAsset = new Asset(accountPublicKey, name, metadata)
assetId = newAsset.id().toString('hex')
} else if (!assetId) {
const asset = await selectAsset(client, account, {
const asset = await ui.assetPrompt(client, account, {
action: 'mint',
showNativeAsset: false,
showNonCreatorAsset: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import { longPrompt } from '../../../../utils/input'
import * as ui from '../../../../ui'
import { MultisigTransactionJson } from '../../../../utils/multisig'

export class CreateSigningPackage extends IronfishCommand {
Expand Down Expand Up @@ -41,14 +41,14 @@ export class CreateSigningPackage extends IronfishCommand {

let unsignedTransaction = options.unsignedTransaction
if (!unsignedTransaction) {
unsignedTransaction = await longPrompt('Enter the unsigned transaction', {
unsignedTransaction = await ui.longPrompt('Enter the unsigned transaction', {
required: true,
})
}

let commitments = options.commitment
if (!commitments) {
const input = await longPrompt('Enter the signing commitments, separated by commas', {
const input = await ui.longPrompt('Enter the signing commitments, separated by commas', {
required: true,
})
commitments = input.split(',')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { UnsignedTransaction } from '@ironfish/sdk'
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import { confirmOrQuit } from '../../../../ui'
import { longPrompt } from '../../../../utils/input'
import * as ui from '../../../../ui'
import { MultisigTransactionJson } from '../../../../utils/multisig'
import { renderUnsignedTransactionDetails } from '../../../../utils/transaction'

Expand Down Expand Up @@ -48,7 +47,7 @@ export class CreateSigningCommitmentCommand extends IronfishCommand {

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

let unsignedTransactionInput = options.unsignedTransaction
if (!unsignedTransactionInput) {
unsignedTransactionInput = await longPrompt('Enter the unsigned transaction', {
unsignedTransactionInput = await ui.longPrompt('Enter the unsigned transaction', {
required: true,
})
}
Expand All @@ -81,7 +80,7 @@ export class CreateSigningCommitmentCommand extends IronfishCommand {
this.logger,
)

await confirmOrQuit('Confirm signing commitment creation', flags.confirm)
await ui.confirmOrQuit('Confirm signing commitment creation', flags.confirm)

const response = await client.wallet.multisig.createSigningCommitment({
account: flags.account,
Expand Down
9 changes: 4 additions & 5 deletions ironfish-cli/src/commands/wallet/multisig/dealer/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { AccountImport } from '@ironfish/sdk/src/wallet/exporter'
import { Flags, ux } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import { inputPrompt } from '../../../../ui'
import { longPrompt } from '../../../../utils/input'
import * as ui from '../../../../ui'

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

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

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

let name = inputName
do {
name = name ?? (await inputPrompt('Enter a name for the coordinator', true))
name = name ?? (await ui.inputPrompt('Enter a name for the coordinator', true))

if (accountNames.has(name)) {
this.log(`Account with name ${name} already exists`)
Expand Down
10 changes: 4 additions & 6 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import { inputPrompt } from '../../../../ui'
import { longPrompt } from '../../../../utils/input'
import { selectSecret } from '../../../../utils/multisig'
import * as ui from '../../../../ui'

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

let participantName = flags.participantName
if (!participantName) {
participantName = await selectSecret(client)
participantName = await ui.multisigSecretPrompt(client)
}

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

let minSigners = flags.minSigners
if (!minSigners) {
const input = await inputPrompt('Enter the number of minimum signers', true)
const input = await ui.inputPrompt('Enter the number of minimum signers', true)
minSigners = parseInt(input)
if (isNaN(minSigners) || minSigners < 2) {
this.error('Minimum number of signers must be at least 2')
Expand Down
10 changes: 4 additions & 6 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import { inputPrompt } from '../../../../ui'
import { longPrompt } from '../../../../utils/input'
import { selectSecret } from '../../../../utils/multisig'
import * as ui from '../../../../ui'

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

let participantName = flags.participantName
if (!participantName) {
participantName = await selectSecret(client)
participantName = await ui.multisigSecretPrompt(client)
}

let round1SecretPackage = flags.round1SecretPackage
if (!round1SecretPackage) {
round1SecretPackage = await inputPrompt(
round1SecretPackage = await ui.inputPrompt(
`Enter the round 1 secret package for participant ${participantName}`,
true,
)
}

let round1PublicPackages = flags.round1PublicPackages
if (!round1PublicPackages || round1PublicPackages.length < 2) {
const input = await longPrompt(
const input = await ui.longPrompt(
'Enter round 1 public packages, separated by commas, one for each participant',
{ required: true },
)
Expand Down
12 changes: 5 additions & 7 deletions ironfish-cli/src/commands/wallet/multisig/dkg/round3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import { inputPrompt } from '../../../../ui'
import { longPrompt } from '../../../../utils/input'
import { selectSecret } from '../../../../utils/multisig'
import * as ui from '../../../../ui'

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

let participantName = flags.participantName
if (!participantName) {
participantName = await selectSecret(client)
participantName = await ui.multisigSecretPrompt(client)
}

let round2SecretPackage = flags.round2SecretPackage
if (!round2SecretPackage) {
round2SecretPackage = await inputPrompt(
round2SecretPackage = await ui.inputPrompt(
`Enter the round 2 encrypted secret package for participant ${participantName}`,
true,
)
}

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

let round2PublicPackages = flags.round2PublicPackages
if (!round2PublicPackages) {
const input = await longPrompt(
const input = await ui.longPrompt(
'Enter round 2 public packages, separated by commas, one for each participant',
{
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CurrencyUtils, Transaction } from '@ironfish/sdk'
import { Flags, ux } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import { longPrompt } from '../../../../utils/input'
import * as ui from '../../../../ui'
import { MultisigTransactionJson } from '../../../../utils/multisig'
import { watchTransaction } from '../../../../utils/transaction'

Expand Down Expand Up @@ -50,12 +50,12 @@ export class MultisigSign extends IronfishCommand {

let signingPackage = options.signingPackage
if (!signingPackage) {
signingPackage = await longPrompt('Enter the signing package', { required: true })
signingPackage = await ui.longPrompt('Enter the signing package', { required: true })
}

let signatureShares = options.signatureShare
if (!signatureShares) {
const input = await longPrompt('Enter the signature shares, separated by commas', {
const input = await ui.longPrompt('Enter the signature shares, separated by commas', {
required: true,
})
signatureShares = input.split(',')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { UnsignedTransaction } from '@ironfish/sdk'
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../../command'
import { RemoteFlags } from '../../../../flags'
import { confirmOrQuit } from '../../../../ui'
import { longPrompt } from '../../../../utils/input'
import * as ui from '../../../../ui'
import { MultisigTransactionJson } from '../../../../utils/multisig'
import { renderUnsignedTransactionDetails } from '../../../../utils/transaction'

Expand Down Expand Up @@ -43,7 +42,7 @@ export class CreateSignatureShareCommand extends IronfishCommand {

let signingPackageString = options.signingPackage
if (!signingPackageString) {
signingPackageString = await longPrompt('Enter the signing package')
signingPackageString = await ui.longPrompt('Enter the signing package')
}

const client = await this.connectRpc()
Expand All @@ -63,7 +62,7 @@ export class CreateSignatureShareCommand extends IronfishCommand {
)

if (!flags.confirm) {
await confirmOrQuit('Confirm new signature share creation')
await ui.confirmOrQuit('Confirm new signature share creation')
}

const signatureShareResponse = await client.wallet.multisig.createSignatureShare({
Expand Down
Loading